diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Lyrics.py | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/plugins/Lyrics.py b/plugins/Lyrics.py index e0d3936..97c3c71 100644 --- a/plugins/Lyrics.py +++ b/plugins/Lyrics.py @@ -2,6 +2,7 @@ from PyQt4 import QtGui,QtCore import re import os +import os.path from thread import start_new_thread from traceback import print_exc import webbrowser @@ -33,7 +34,7 @@ LYRICS_SITES_DEFAULT='azlyrics.com <br><br>.*?<br><br>(.*?)<br><br>\n'\ 'lyricstime.com phone-left.gif.*?<p>(.*?)</p>\n'\ 'lyricsfire.com class="lyric">.*?Song.*?<br>(.*?)</pre>\n'\ 'lyricsfreak.com <div.*?id="content".*?>(.*?)</div>\n' -LYRICS_DIR_DEFAULT='/rabbit' +LYRICS_DOWNLOADTO_DEFAULT='~/.lyrics/$artist/$artist - $title.txt' class wgLyrics(QtGui.QWidget): " contains the lyrics" @@ -44,6 +45,7 @@ class wgLyrics(QtGui.QWidget): btnSave=None btnSearch=None editMode=False + lyFormat=None p=None # plugin def __init__(self, p, parent=None): QtGui.QWidget.__init__(self, parent) @@ -111,6 +113,7 @@ class wgLyrics(QtGui.QWidget): if self.editMode: self.setMode(False) + self.lyFormat=format.compile(self.p.getSetting('downloadto')) song=monty.getCurrentSong() try: song._data['file'] @@ -130,13 +133,9 @@ class wgLyrics(QtGui.QWidget): self.txtView.insertHtml(event.html) def getLyricsFilePath(self, song): - save_dir=self.p.getSetting('dir') - fInfo=QtCore.QFileInfo(save_dir) - if fInfo.isDir(): - fName="%s - %s.txt"%(song.getArtist(), song.getTitle()) - fName=fName.replace("/", "_") - return toAscii('%s/%s'%(save_dir,fName)) - return None + params={'music_dir': mpdSettings.get('music_directory')} + path=self.lyFormat(format.params(song, params)) + return toAscii(os.path.expanduser(path)) _mutex=QtCore.QMutex() _fetchCnt=0 @@ -187,12 +186,18 @@ class wgLyrics(QtGui.QWidget): if lyFName: # we can't save if the path isn't correct try: + self.p.extended("Saving to %s"%(lyFName)) + try: + # fails when dir exists + os.makedirs(os.path.dirname(os.path.expanduser(lyFName))) + except Exception, e: + pass file=open(lyFName, 'w') file.write(self.curLyrics) file.close() - except: + except Exception, e: # probably a wrong path! - pass + self.p.normal("Failed to write lyrics %s"%(str(e))) else: self.curLyrics="" txt="No lyrics found :'(" @@ -249,7 +254,7 @@ class pluginLyrics(Plugin): return [ ['engine', 'Search engine', 'The URL that is used to search. $artist, $title and $album are replaced in the URL.', QtGui.QLineEdit(self.getSetting('engine'))], ['sites', 'Sites & regexes', 'This field contains all sites, together with the regex needed to fetch the lyrics.\nEvery line must look like this: $domain $regex-start(.*?)$regex-end\n$domain is the domain of the lyrics website, $regex-start is the regex indicating the start of the lyrics, $regex-end indicates the end. E.g. foolyrics.org <lyrics>(.*?)</lyrics>', sites], - ['dir', 'Lyrics directory', 'Directory where lyrics should be stored and retrieved.', QtGui.QLineEdit(self.getSetting('dir'))], + ['downloadto', 'Target', 'Specifies where to save lyrics fetched from internet to.\nPossible tags: music_dir, file, artist, title, album', QtGui.QLineEdit(self.getSetting('downloadto'))], ] def afterSaveSettings(self): self.o.refresh() |