Skip to content

Instantly share code, notes, and snippets.

@indrekj
Created June 30, 2009 15:00
Show Gist options
  • Save indrekj/138205 to your computer and use it in GitHub Desktop.
Save indrekj/138205 to your computer and use it in GitHub Desktop.
diff --git a/plugins/lyrics/lyrics-prefs.ui b/plugins/lyrics/lyrics-prefs.ui
index 374e8b4..baedd2d 100644
--- a/plugins/lyrics/lyrics-prefs.ui
+++ b/plugins/lyrics/lyrics-prefs.ui
@@ -103,6 +103,21 @@
<property name="position">4</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="engine6">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label">Sasslantis (lap.ttu.ee/~muhw)</property>
+ <property name="use_underline">True</property>
+ <property name="response_id">0</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">5</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/plugins/lyrics/lyrics/LyricsConfigureDialog.py b/plugins/lyrics/lyrics/LyricsConfigureDialog.py
index aab0a3e..a82268e 100644
--- a/plugins/lyrics/lyrics/LyricsConfigureDialog.py
+++ b/plugins/lyrics/lyrics/LyricsConfigureDialog.py
@@ -46,6 +46,7 @@ class LyricsConfigureDialog (object):
self.toggle3 = builder.get_object("engine3")
self.toggle4 = builder.get_object("engine4")
self.toggle5 = builder.get_object("engine5")
+ self.toggle6 = builder.get_object("engine6")
self.choose_button = builder.get_object("choose_button")
self.path_display = builder.get_object("path_display")
@@ -62,6 +63,8 @@ class LyricsConfigureDialog (object):
self.toggle3.set_active('leoslyrics.com' in engines)
self.toggle4.set_active('lyricwiki.org' in engines)
self.toggle5.set_active('winampcn.com' in engines)
+ self.toggle6.set_active('lap.ttu.ee/~muhw' in engines)
+
def dialog_response(self, dialog, response):
if response == gtk.RESPONSE_OK:
@@ -85,6 +88,8 @@ class LyricsConfigureDialog (object):
engines.append('lyricwiki.org')
if self.toggle5.get_active():
engines.append('winampcn.com')
+ if self.toggle6.get_active():
+ engines.append('lap.ttu.ee/~muhw')
if len(self.path_display.get_text()) is not 0:
self.folder = self.path_display.get_text()
diff --git a/plugins/lyrics/lyrics/LyricsParse.py b/plugins/lyrics/lyrics/LyricsParse.py
index b321ffe..eb74be3 100644
--- a/plugins/lyrics/lyrics/LyricsParse.py
+++ b/plugins/lyrics/lyrics/LyricsParse.py
@@ -36,6 +36,7 @@ from AstrawebParser import AstrawebParser
from LeoslyricsParser import LeoslyricsParser
from LyricWikiParser import LyricWikiParser
from WinampcnParser import WinampcnParser
+from SasslantisParser import SasslantisParser
engines_map = {
@@ -43,7 +44,8 @@ engines_map = {
'astraweb.com': AstrawebParser,
'leoslyrics.com': LeoslyricsParser,
'lyricwiki.org': LyricWikiParser,
- 'winampcn.com': WinampcnParser
+ 'winampcn.com': WinampcnParser,
+ 'lap.ttu.ee/~muhw': SasslantisParser
}
diff --git a/plugins/lyrics/lyrics/Makefile.am b/plugins/lyrics/lyrics/Makefile.am
index 87bf6f4..c61ae74 100644
--- a/plugins/lyrics/lyrics/Makefile.am
+++ b/plugins/lyrics/lyrics/Makefile.am
@@ -9,4 +9,5 @@ plugin_PYTHON = \
AstrawebParser.py \
LeoslyricsParser.py \
LyricWikiParser.py \
- WinampcnParser.py
+ WinampcnParser.py \
+ SasslantisParser.py
diff --git a/plugins/lyrics/lyrics/SasslantisParser.py b/plugins/lyrics/lyrics/SasslantisParser.py
new file mode 100644
index 0000000..a3c261e
--- /dev/null
+++ b/plugins/lyrics/lyrics/SasslantisParser.py
@@ -0,0 +1,49 @@
+import urllib
+import re
+import rb
+
+class SasslantisParser (object):
+ def __init__(self, artist, title):
+ self.artist = artist
+ self.title = title
+
+ def search(self, callback, *data):
+ wartist = self.artist.decode('UTF-8').encode('ISO-8859-1')
+ wtitle = self.title.decode('UTF-8').encode('ISO-8859-1')
+
+ wurl = 'http://lap.ttu.ee/~muhw/lyrics.php?action=Search'
+
+ params = urllib.urlencode({'artist': wartist, 'title': wtitle, 'type': 'AND'})
+ f = urllib.urlopen(wurl, params)
+ self.got_results (f.read(), callback, *data)
+
+ def got_results (self, result, callback, *data):
+ if result is None:
+ callback (None, *data)
+ return
+
+ results = re.sub('\n', '', re.sub('\r', '', result))
+
+ if re.search('<a href=lyrics.php\?action=show&id=(.*?)>', results) is not None:
+ lyrics_id = re.split('<a href=lyrics.php\?action=show&id=(\d*?)\>(.*?)</a>', results)[1]
+ loader = rb.Loader()
+ loader.get_url('http://lap.ttu.ee/~muhw/lyrics.php?action=show&id=' + lyrics_id, self.parse_lyrics, callback, *data)
+ return
+ callback (None, *data)
+
+ def parse_lyrics(self, result, callback, *data):
+ if result is None:
+ callback (None, *data)
+ return
+
+ result = result.decode('ISO-8859-1').encode('UTF-8')
+ result = re.sub('\n', '', re.sub('\r', '', (re.sub('\t', '', result)))).strip()
+
+ artist_title = re.split('<td height=35 valign="bottom" class="lyricsHeader" colspan="2">(.*?)</td>', result)[1]
+
+ lyrics = re.split('<td colspan="2">(.*?)</td>', result)[1]
+ lyrics = artist_title + "\n" + lyrics
+ lyrics = re.sub('<[Bb][Rr][^>]*>', "\n", lyrics)
+ lyrics += "\n\nLyrics provided by Sasslantis (http://lap.ttu.ee/~muhw/)"
+
+ callback (lyrics, *data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment