summaryrefslogtreecommitdiff
path: root/nephilim/plugins/Lyrics.py
diff options
context:
space:
mode:
Diffstat (limited to 'nephilim/plugins/Lyrics.py')
-rw-r--r--nephilim/plugins/Lyrics.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/nephilim/plugins/Lyrics.py b/nephilim/plugins/Lyrics.py
new file mode 100644
index 0000000..1983f2a
--- /dev/null
+++ b/nephilim/plugins/Lyrics.py
@@ -0,0 +1,74 @@
+from PyQt4 import QtGui,QtCore
+from PyQt4.QtCore import QVariant
+
+from thread import start_new_thread
+import logging
+
+from ..clPlugin import Plugin
+from .. import LyricWiki_client
+
+class wgLyrics(QtGui.QWidget):
+ " contains the lyrics"
+ txtView = None # text-object
+ p = None # plugin
+ def __init__(self, p, parent=None):
+ QtGui.QWidget.__init__(self, parent)
+ self.p = p
+ self.curLyrics = ''
+
+ self.txtView = QtGui.QTextEdit(self)
+ self.txtView.setReadOnly(True)
+
+ self.setLayout(QtGui.QVBoxLayout())
+ self.layout().setSpacing(0)
+ self.layout().setMargin(0)
+ self.layout().addWidget(self.txtView)
+
+ def set_lyrics(self, song, lyrics):
+ self.txtView.clear()
+ if song:
+ self.txtView.insertHtml('<b>%s</b>\n<br /><u>%s</u><br />'\
+ '<br />\n\n'%(song.getTitle(), song.getArtist()))
+ if lyrics:
+ self.txtView.insertPlainText(lyrics)
+
+class pluginLyrics(Plugin):
+ o = None
+ DEFAULTS = {'sites' : ['lyricwiki'], 'lyricdir' : '$musicdir/$songdir',
+ 'lyricname' : '.lyric_mpclient_$artist_$album_$song'}
+
+ def __init__(self, winMain):
+ Plugin.__init__(self, winMain, 'Lyrics')
+ self.addListener('onSongChange', self.refresh)
+ self.addListener('onReady', self.refresh)
+ def _load(self):
+ self.o = wgLyrics(self)
+ def _unload(self):
+ self.o = None
+ def getInfo(self):
+ return "Show (and fetch) the lyrics of the currently playing song."
+
+ def _getDockWidget(self):
+ return self._createDock(self.o)
+
+ def refresh(self, params = None):
+ lyrics = None
+ song = self.mpclient.getCurrentSong()
+ if not song:
+ self.o.set_lyrics(None, None)
+ return
+ for site in self.settings.value(self.getName() + '/sites').toStringList():
+ lyrics = eval('self.fetch_%s(song)'%site)
+ if lyrics:
+ self.o.set_lyrics(song, lyrics)
+ return
+
+ def fetch_lyricwiki(self, song):
+ soap = LyricWiki_client.LyricWikiBindingSOAP("http://lyricwiki.org/server.php")
+ req = LyricWiki_client.getSongRequest()
+ req.Artist = song.getArtist()
+ req.Song = song.getTitle()
+ result = soap.getSong(req)
+
+ return result.Return.Lyrics
+