[Rhythmbox-devel] [PATCH] Adding support to azlyrics.com a lyric plugin.



I'm user and passionate for Rhythmbox also a music lover. 
I miss sometimes a good support in lyrics plugin. Terra plugin is failing
these days, and summed to that its database is not so good. 

With this patch I'm adding support to another site that provides lyrics
IMHO  better than terra and others.  Would appreciate a patch review or 
a deny review/feedback.

Thanks.

Signed-off-by: kirotawa <kirotawa gmail com>
---
 plugins/lyrics/AzLyricsParser.py |   76 ++++++++++++++++++++++++++++++++++++++
 plugins/lyrics/LyricsSites.py    |    4 +-
 2 files changed, 79 insertions(+), 1 deletion(-)
 create mode 100644 plugins/lyrics/AzLyricsParser.py

diff --git a/plugins/lyrics/AzLyricsParser.py b/plugins/lyrics/AzLyricsParser.py
new file mode 100644
index 0000000..583dcd4
--- /dev/null
+++ b/plugins/lyrics/AzLyricsParser.py
@@ -0,0 +1,76 @@
+# -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
+#
+# Copyright (C) 2014 Leonidas Da Silva Barbosa
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# The Rhythmbox authors hereby grant permission for non-GPL compatible
+# GStreamer plugins to be used and distributed together with GStreamer
+# and Rhythmbox. This permission is above and beyond the permissions granted
+# by the GPL license by which Rhythmbox is covered. If you modify this code
+# you may extend this exception to your version of the code, but you are not
+# obligated to do so. If you do not wish to do so, delete this exception
+# statement from your version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
+
+
+import rb
+import re
+
+
+class AzLyricsParser (object):
+    def __init__(self, artist, title):
+        self.artist = artist
+        self.title = title
+        self.base_url = 'http://www.azlyrics.com/'
+
+    def search(self, callback, *data):
+        letter = self.artist[0]+'/'
+        _base_url = self.base_url + letter
+        _artist = ('').join(self.artist.split())+'.html'
+        loader = rb.Loader()
+        print("searching for artist url: %s" % (_base_url+_artist))
+        loader.get_url (_base_url + _artist, self.get_lyric_url, callback, *data)
+
+    def get_lyric_url(self, artist_page, callback, *data):
+        if artist_page is None:
+            callback (None, *data)
+            return
+
+        result = artist_page.decode('utf-8')
+        if re.search('Welcome to the A-Z LYRICS UNIVERSE', result):
+            print("not found")
+            callback(None, *data)
+        elif re.search('<title>%s lyrics</title>' % self.artist.upper(), result):
+            if re.search(self.title.title(), result):
+                loader = rb.Loader()
+                _lyric = '/'+('').join(self.title.split())+'.html'
+                _base_url = self.base_url+'lyrics/'
+                _base_url = _base_url + ('').join(self.artist.split())
+                print("Getting lyric in: %s" % (_base_url+_lyric))
+                loader.get_url (_base_url + _lyric, self.get_lyric, callback, *data)
+
+    def get_lyric(self, lyric_page, callback, *data):
+        if lyric_page is None:
+            callback (None, *data)
+            return
+
+        lyric_page = lyric_page.decode('utf-8')
+        source = re.split('<!-- start of lyrics -->', lyric_page)
+        source = re.split('<!-- end of lyrics -->', source[1])
+        lyric = re.sub(r'<.*?>','',source[0])
+        head = "%s - %s\n\n" % (self.artist.title(), self.title.title())
+        result = head + str(lyric)
+        result += "\n\nLyric provide by AZLyrics"
+        callback (result, *data)
diff --git a/plugins/lyrics/LyricsSites.py b/plugins/lyrics/LyricsSites.py
index d680219..b9ce49f 100644
--- a/plugins/lyrics/LyricsSites.py
+++ b/plugins/lyrics/LyricsSites.py
@@ -31,6 +31,7 @@ from TerraParser import TerraParser
 from DarkLyricsParser import DarkLyricsParser
 from JlyricParser import JlyricParser
 from JetlyricsParser import JetlyricsParser
+from AzLyricsParser import AzLyricsParser
 
 from gi.repository import RB
 
@@ -43,6 +44,7 @@ lyrics_sites = [
        { 'id': 'terra.com.br',         'class': TerraParser,           'name': _("TerraBrasil 
(terra.com.br)")         },
        { 'id': 'darklyrics.com',       'class': DarkLyricsParser,      'name': _("Dark Lyrics 
(darklyrics.com)")       },
        { 'id': 'j-lyric.net',          'class': JlyricParser,          'name': _("Jlyric (j-lyric.net)")     
          },
-       { 'id': 'jetlyrics.com',        'class': JetlyricsParser,       'name': _("Jetlyrics 
(jetlyrics.com)")          }
+       { 'id': 'jetlyrics.com',        'class': JetlyricsParser,       'name': _("Jetlyrics 
(jetlyrics.com)")          },
+       { 'id': 'azlyrics.com',         'class': AzLyricsParser,        'name': _("AzLyrics (azlyrics.com)")  
          }
 ]
 
-- 
Leonidas S Barbosa



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]