Merge lp:~vuhieple/rhythmbox/plugin-lyrics into lp:rhythmbox

Proposed by Le Vu Hiep
Status: Needs review
Proposed branch: lp:~vuhieple/rhythmbox/plugin-lyrics
Merge into: lp:rhythmbox
Diff against target: 222 lines (+187/-8)
3 files modified
plugins/lyrics/LyricsSites.py (+9/-8)
plugins/lyrics/MaxiParser.py (+82/-0)
plugins/lyrics/ZingParser.py (+96/-0)
To merge this branch: bzr merge lp:~vuhieple/rhythmbox/plugin-lyrics
Reviewer Review Type Date Requested Status
Jonathan Matthew Disapprove
Review via email: mp+92809@code.launchpad.net

Description of the change

I added two working parsers for the lyrics plugin and edited the LyricsSites.py to include those ones.

To post a comment you must log in.
Revision history for this message
Jonathan Matthew (jmatthew) wrote :

Thanks, but I don't accept patches this way. Please open a bug in GNOME bugzilla and attach a patch there.

Also, it appears you've based your changes to LyricsSites.py on an old version of the file. Please make sure you base your changes on the current code.

review: Disapprove

Unmerged revisions

7879. By Le Vu Hiep

Some new parsers for rhythmbox fetching Vietnamese and English lyrics)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/lyrics/LyricsSites.py'
--- plugins/lyrics/LyricsSites.py 2011-12-19 09:41:45 +0000
+++ plugins/lyrics/LyricsSites.py 2012-02-13 17:49:28 +0000
@@ -25,21 +25,22 @@
25# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.25# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2626
2727
28from LyrcParser import LyrcParser
28from AstrawebParser import AstrawebParser29from AstrawebParser import AstrawebParser
30from LeoslyricsParser import LeoslyricsParser
29from WinampcnParser import WinampcnParser31from WinampcnParser import WinampcnParser
30from TerraParser import TerraParser32from TerraParser import TerraParser
31from DarkLyricsParser import DarkLyricsParser33from ZingParser import ZingParser
3234from MaxiParser import MaxiParser
33from gi.repository import RB
34
35import gettext
36gettext.install('rhythmbox', RB.locale_dir())
3735
38lyrics_sites = [36lyrics_sites = [
37 { 'id': 'lyrc.com.ar', 'class': LyrcParser, 'name': _("Lyrc (lyrc.com.ar)") },
39 { 'id': 'astraweb.com', 'class': AstrawebParser, 'name': _("Astraweb (www.astraweb.com)") },38 { 'id': 'astraweb.com', 'class': AstrawebParser, 'name': _("Astraweb (www.astraweb.com)") },
39 { 'id': 'leoslyrics.com', 'class': LeoslyricsParser, 'name': _("Leo's Lyrics (www.leoslyrics.com)") },
40 { 'id': 'winampcn.com', 'class': WinampcnParser, 'name': _("WinampCN (www.winampcn.com)") },40 { 'id': 'winampcn.com', 'class': WinampcnParser, 'name': _("WinampCN (www.winampcn.com)") },
41 { 'id': 'terra.com.br', 'class': TerraParser, 'name': _("TerraBrasil (terra.com.br)") },41 { 'id': 'terra.com.br', 'class': TerraParser, 'name': _("TerraBrasil (terra.com.br)") },
42 { 'id': 'darklyrics.com', 'class': DarkLyricsParser, 'name': _("Dark Lyrics (darklyrics.com)") }42 { 'id': 'mp3.zing.vn', 'class': ZingParser, 'name': _("ZingVietNam (mp3.zing.vn)") },
4343 { 'id': 'maxilyrics.com', 'class': MaxiParser, 'name': _("MaxiLyrics (MaxiLyrics)") }
44
44]45]
4546
4647
=== added file 'plugins/lyrics/MaxiParser.py'
--- plugins/lyrics/MaxiParser.py 1970-01-01 00:00:00 +0000
+++ plugins/lyrics/MaxiParser.py 2012-02-13 17:49:28 +0000
@@ -0,0 +1,82 @@
1# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
2#
3# Copyright (C) 2012 Le Vu Hiep
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2, or (at your option)
8# any later version.
9#
10# The Rhythmbox authors hereby grant permission for non-GPL compatible
11# GStreamer plugins to be used and distributed together with GStreamer
12# and Rhythmbox. This permission is above and beyond the permissions granted
13# by the GPL license by which Rhythmbox is covered. If you modify this code
14# you may extend this exception to your version of the code, but you are not
15# obligated to do so. If you do not wish to do so, delete this exception
16# statement from your version.
17#
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22# GNU General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program; if not, write to the Free Software
26# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27
28import urllib2
29import rb
30import re
31import sys
32import urllib
33import HTMLParser
34
35class MaxiParser (object):
36 def __init__(self, artist, title):
37 self.artist = artist
38 self.title = title
39
40 def search(self, callback, *data):
41 artist = urllib.quote(self.artist)
42 title = urllib.quote(self.title)
43 title = re.sub('(\-|\.wav|\.mp3|\.mid\.wma)','',title)
44
45 if re.search('[uU]nknown',artist):
46 join = urllib.quote('-')
47 content = '%s' % (title)
48
49 else:
50 join = urllib.quote('-')
51 content = '%s%s%s' % (title, join, artist)
52
53 path ='https://www.google.com/search?sclient=psy-ab&hl=vi&safe=off&source=hp&q='+content+'+site:maxilyrics.com&pbx=1&oq='+content+'+site:maxilyrics.com&aq=f&aqi=&aql=&gs_sm=e&gs_upl=3203972l3209682l9l3209897l17l17l0l0l0l0l190l1691l14.3l17l0&fp=1&biw=1280&bih=640&cad=b&btnI=1&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&tch=1&ech=1&psi=9e8vT5_5OcOaiAfk47i7Dg.1328541646416.3'
54 req_headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0','Cookie': 'Hello Google','Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Accept-Language': 'en-us,en;q=0.5','Accept-Encoding': 'gzip,deflate','Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7','Connection': 'keep-alive','Referer': 'http://www.google.com/search?sourceid=chrome&ie=UTF-8&q='+content}
55 req = urllib2.Request(path, headers=req_headers)
56 response = urllib2.urlopen(req)
57 lyrURL = response.info().getheader('Location')
58 self.got_lyrics(lyrURL, callback, *data)
59# self.parse_lyrics(lyrURL)
60
61 def got_lyrics(self, url, callback, *data):
62 if url is None:
63 callback(None, *data)
64 return
65 if url is not None:
66 callback(self.parse_lyrics(url), *data)
67 else:
68 callback(None, *data)
69
70 def parse_lyrics(self, uRL):
71# print "Final URL: ===> " + uRL
72 lyrics = urllib.urlopen(uRL).read()
73 lyrics = re.split('<div class=\"contentdiv_leftbox_data\">', lyrics)[1]
74 lyrics = re.split('</div>', lyrics)[0]
75 lyrics = re.sub('<[Bb][Rr] />', '\n', lyrics)
76 lyrics = re.sub('^\\s{1,}','',lyrics)
77
78 unen = HTMLParser.HTMLParser()
79 lyrics = unen.unescape(lyrics)
80 lyrics += "\n\nGet from MaxiLyrics"
81# print lyrics
82 return lyrics
083
=== added file 'plugins/lyrics/ZingParser.py'
--- plugins/lyrics/ZingParser.py 1970-01-01 00:00:00 +0000
+++ plugins/lyrics/ZingParser.py 2012-02-13 17:49:28 +0000
@@ -0,0 +1,96 @@
1# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
2#
3# Copyright (C) 2011 Le Vu Hiep
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2, or (at your option)
8# any later version.
9#
10# The Rhythmbox authors hereby grant permission for non-GPL compatible
11# GStreamer plugins to be used and distributed together with GStreamer
12# and Rhythmbox. This permission is above and beyond the permissions granted
13# by the GPL license by which Rhythmbox is covered. If you modify this code
14# you may extend this exception to your version of the code, but you are not
15# obligated to do so. If you do not wish to do so, delete this exception
16# statement from your version.
17#
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22# GNU General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program; if not, write to the Free Software
26# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27
28import urllib
29import rb
30import re
31import sys
32import unicodedata
33
34
35class ZingParser (object):
36 def __init__(self, artist, title):
37 self.artist = artist
38 self.title = title
39
40 def search(self, callback, *data):
41 path = 'http://mp3.zing.vn/tim-kiem/bai-hat.html'
42 artist = urllib.quote(self.artist)
43 title = urllib.quote(self.title)
44 title = re.sub('(\-|\.wav|\.mp3|\.mid\.wma)','',title)
45
46 if re.search('[uU]nknown',artist):
47 content = '%s' % (title)
48
49 else:
50 join = urllib.quote('-')
51 content = '%s%s%s' % (title, join, artist)
52
53 wurl = '?q='+content+'&filter=4&search_type=bai-hat'
54 print "search URL: " + path + wurl
55
56 loader = rb.Loader()
57 loader.get_url (path + wurl, self.got_lyrics, callback, *data)
58
59 def got_lyrics(self, result, callback, *data):
60
61 if result is None:
62 callback (None, *data)
63 return
64 if result is not None:
65 result = result.decode('iso-8859-1').encode('UTF-8')
66
67 if re.search('<strong>0</strong>', result):
68 print "======NO SONG FOUND===="
69 callback (None, *data)
70
71 elif re.search('<div class="first-search-song">', result):
72 print "=======FOUND========="
73 callback(self.parse_lyrics(result), *data)
74 else:
75 callback (None, *data)
76 else:
77 callback (None, *data)
78
79 def parse_lyrics(self, source):
80
81
82 source = re.split('\<div\ class\=\"first-search-song\"\>',source)[1]
83 source = re.split('href\=\"',source)[1]
84 source = re.split('\"\>',source)[0]
85 mylink = 'http://mp3.zing.vn' + source
86 print "search URL: " + mylink
87 lyrics = urllib.urlopen(mylink).read()
88
89 lyrics = re.split('</span></span>', lyrics)[1]
90 lyrics = re.split('</p>', lyrics)[0]
91 lyrics = re.sub('<[Bb][Rr] />', '', lyrics)
92 lyrics = re.sub('^\\s{1,}','',lyrics)
93 lyrics += "\n\nGet from Zing"
94# print lyrics
95
96 return lyrics

Subscribers

People subscribed via source and target branches

to all changes: