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
1=== modified file 'plugins/lyrics/LyricsSites.py'
2--- plugins/lyrics/LyricsSites.py 2011-12-19 09:41:45 +0000
3+++ plugins/lyrics/LyricsSites.py 2012-02-13 17:49:28 +0000
4@@ -25,21 +25,22 @@
5 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6
7
8+from LyrcParser import LyrcParser
9 from AstrawebParser import AstrawebParser
10+from LeoslyricsParser import LeoslyricsParser
11 from WinampcnParser import WinampcnParser
12 from TerraParser import TerraParser
13-from DarkLyricsParser import DarkLyricsParser
14-
15-from gi.repository import RB
16-
17-import gettext
18-gettext.install('rhythmbox', RB.locale_dir())
19+from ZingParser import ZingParser
20+from MaxiParser import MaxiParser
21
22 lyrics_sites = [
23+ { 'id': 'lyrc.com.ar', 'class': LyrcParser, 'name': _("Lyrc (lyrc.com.ar)") },
24 { 'id': 'astraweb.com', 'class': AstrawebParser, 'name': _("Astraweb (www.astraweb.com)") },
25+ { 'id': 'leoslyrics.com', 'class': LeoslyricsParser, 'name': _("Leo's Lyrics (www.leoslyrics.com)") },
26 { 'id': 'winampcn.com', 'class': WinampcnParser, 'name': _("WinampCN (www.winampcn.com)") },
27 { 'id': 'terra.com.br', 'class': TerraParser, 'name': _("TerraBrasil (terra.com.br)") },
28- { 'id': 'darklyrics.com', 'class': DarkLyricsParser, 'name': _("Dark Lyrics (darklyrics.com)") }
29-
30+ { 'id': 'mp3.zing.vn', 'class': ZingParser, 'name': _("ZingVietNam (mp3.zing.vn)") },
31+ { 'id': 'maxilyrics.com', 'class': MaxiParser, 'name': _("MaxiLyrics (MaxiLyrics)") }
32+
33 ]
34
35
36=== added file 'plugins/lyrics/MaxiParser.py'
37--- plugins/lyrics/MaxiParser.py 1970-01-01 00:00:00 +0000
38+++ plugins/lyrics/MaxiParser.py 2012-02-13 17:49:28 +0000
39@@ -0,0 +1,82 @@
40+# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
41+#
42+# Copyright (C) 2012 Le Vu Hiep
43+#
44+# This program is free software; you can redistribute it and/or modify
45+# it under the terms of the GNU General Public License as published by
46+# the Free Software Foundation; either version 2, or (at your option)
47+# any later version.
48+#
49+# The Rhythmbox authors hereby grant permission for non-GPL compatible
50+# GStreamer plugins to be used and distributed together with GStreamer
51+# and Rhythmbox. This permission is above and beyond the permissions granted
52+# by the GPL license by which Rhythmbox is covered. If you modify this code
53+# you may extend this exception to your version of the code, but you are not
54+# obligated to do so. If you do not wish to do so, delete this exception
55+# statement from your version.
56+#
57+#
58+# This program is distributed in the hope that it will be useful,
59+# but WITHOUT ANY WARRANTY; without even the implied warranty of
60+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
61+# GNU General Public License for more details.
62+#
63+# You should have received a copy of the GNU General Public License
64+# along with this program; if not, write to the Free Software
65+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
66+
67+import urllib2
68+import rb
69+import re
70+import sys
71+import urllib
72+import HTMLParser
73+
74+class MaxiParser (object):
75+ def __init__(self, artist, title):
76+ self.artist = artist
77+ self.title = title
78+
79+ def search(self, callback, *data):
80+ artist = urllib.quote(self.artist)
81+ title = urllib.quote(self.title)
82+ title = re.sub('(\-|\.wav|\.mp3|\.mid\.wma)','',title)
83+
84+ if re.search('[uU]nknown',artist):
85+ join = urllib.quote('-')
86+ content = '%s' % (title)
87+
88+ else:
89+ join = urllib.quote('-')
90+ content = '%s%s%s' % (title, join, artist)
91+
92+ 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'
93+ 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}
94+ req = urllib2.Request(path, headers=req_headers)
95+ response = urllib2.urlopen(req)
96+ lyrURL = response.info().getheader('Location')
97+ self.got_lyrics(lyrURL, callback, *data)
98+# self.parse_lyrics(lyrURL)
99+
100+ def got_lyrics(self, url, callback, *data):
101+ if url is None:
102+ callback(None, *data)
103+ return
104+ if url is not None:
105+ callback(self.parse_lyrics(url), *data)
106+ else:
107+ callback(None, *data)
108+
109+ def parse_lyrics(self, uRL):
110+# print "Final URL: ===> " + uRL
111+ lyrics = urllib.urlopen(uRL).read()
112+ lyrics = re.split('<div class=\"contentdiv_leftbox_data\">', lyrics)[1]
113+ lyrics = re.split('</div>', lyrics)[0]
114+ lyrics = re.sub('<[Bb][Rr] />', '\n', lyrics)
115+ lyrics = re.sub('^\\s{1,}','',lyrics)
116+
117+ unen = HTMLParser.HTMLParser()
118+ lyrics = unen.unescape(lyrics)
119+ lyrics += "\n\nGet from MaxiLyrics"
120+# print lyrics
121+ return lyrics
122
123=== added file 'plugins/lyrics/ZingParser.py'
124--- plugins/lyrics/ZingParser.py 1970-01-01 00:00:00 +0000
125+++ plugins/lyrics/ZingParser.py 2012-02-13 17:49:28 +0000
126@@ -0,0 +1,96 @@
127+# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
128+#
129+# Copyright (C) 2011 Le Vu Hiep
130+#
131+# This program is free software; you can redistribute it and/or modify
132+# it under the terms of the GNU General Public License as published by
133+# the Free Software Foundation; either version 2, or (at your option)
134+# any later version.
135+#
136+# The Rhythmbox authors hereby grant permission for non-GPL compatible
137+# GStreamer plugins to be used and distributed together with GStreamer
138+# and Rhythmbox. This permission is above and beyond the permissions granted
139+# by the GPL license by which Rhythmbox is covered. If you modify this code
140+# you may extend this exception to your version of the code, but you are not
141+# obligated to do so. If you do not wish to do so, delete this exception
142+# statement from your version.
143+#
144+#
145+# This program is distributed in the hope that it will be useful,
146+# but WITHOUT ANY WARRANTY; without even the implied warranty of
147+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
148+# GNU General Public License for more details.
149+#
150+# You should have received a copy of the GNU General Public License
151+# along with this program; if not, write to the Free Software
152+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
153+
154+import urllib
155+import rb
156+import re
157+import sys
158+import unicodedata
159+
160+
161+class ZingParser (object):
162+ def __init__(self, artist, title):
163+ self.artist = artist
164+ self.title = title
165+
166+ def search(self, callback, *data):
167+ path = 'http://mp3.zing.vn/tim-kiem/bai-hat.html'
168+ artist = urllib.quote(self.artist)
169+ title = urllib.quote(self.title)
170+ title = re.sub('(\-|\.wav|\.mp3|\.mid\.wma)','',title)
171+
172+ if re.search('[uU]nknown',artist):
173+ content = '%s' % (title)
174+
175+ else:
176+ join = urllib.quote('-')
177+ content = '%s%s%s' % (title, join, artist)
178+
179+ wurl = '?q='+content+'&filter=4&search_type=bai-hat'
180+ print "search URL: " + path + wurl
181+
182+ loader = rb.Loader()
183+ loader.get_url (path + wurl, self.got_lyrics, callback, *data)
184+
185+ def got_lyrics(self, result, callback, *data):
186+
187+ if result is None:
188+ callback (None, *data)
189+ return
190+ if result is not None:
191+ result = result.decode('iso-8859-1').encode('UTF-8')
192+
193+ if re.search('<strong>0</strong>', result):
194+ print "======NO SONG FOUND===="
195+ callback (None, *data)
196+
197+ elif re.search('<div class="first-search-song">', result):
198+ print "=======FOUND========="
199+ callback(self.parse_lyrics(result), *data)
200+ else:
201+ callback (None, *data)
202+ else:
203+ callback (None, *data)
204+
205+ def parse_lyrics(self, source):
206+
207+
208+ source = re.split('\<div\ class\=\"first-search-song\"\>',source)[1]
209+ source = re.split('href\=\"',source)[1]
210+ source = re.split('\"\>',source)[0]
211+ mylink = 'http://mp3.zing.vn' + source
212+ print "search URL: " + mylink
213+ lyrics = urllib.urlopen(mylink).read()
214+
215+ lyrics = re.split('</span></span>', lyrics)[1]
216+ lyrics = re.split('</p>', lyrics)[0]
217+ lyrics = re.sub('<[Bb][Rr] />', '', lyrics)
218+ lyrics = re.sub('^\\s{1,}','',lyrics)
219+ lyrics += "\n\nGet from Zing"
220+# print lyrics
221+
222+ return lyrics

Subscribers

People subscribed via source and target branches

to all changes: