From 5301413d16aced488cbc768c6c765afb21b90d06 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 28 Nov 2010 18:08:23 +0100 Subject: Stop saving lyrics in files. also write all lyrics read from files to sticker db. --- nephilim/plugins/Lyrics.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/nephilim/plugins/Lyrics.py b/nephilim/plugins/Lyrics.py index 7f5dd2a..35bb477 100644 --- a/nephilim/plugins/Lyrics.py +++ b/nephilim/plugins/Lyrics.py @@ -72,7 +72,7 @@ class LyricsWidget(QtGui.QWidget): self.layout().addWidget(self.__text_view, 1, 1) def __save_lyrics(self): - self.plugin.save_lyrics_file(self.__text_view.toPlainText()) + self.plugin.save_lyrics(self.__text_view.toPlainText()) def __toggle_editable(self, val): self.__text_view.setReadOnly(not val) @@ -136,7 +136,7 @@ class Lyrics(Plugin): i = self.__fetchers.index(self.sender()) if lyrics and i < self.__index: if int(self.settings.value(self.name + '/store')) and self.__lyrics_path: - self.save_lyrics_file(lyrics) + self.save_lyrics(lyrics) self.__index = i return self.o.set_lyrics(song, lyrics) elif self.__results >= len(self.__fetchers) and not self.o.lyrics_loaded: @@ -260,6 +260,7 @@ class Lyrics(Plugin): lyrics = file.read().decode('utf-8') file.close() if lyrics: + self.save_lyrics(lyrics) return self.o.set_lyrics(song, lyrics) except IOError, e: self.logger.info('Error reading lyrics file: %s.'%e) @@ -267,20 +268,11 @@ class Lyrics(Plugin): for fetcher in self.__fetchers: fetcher.fetch(song) - def save_lyrics_file(self, lyrics, path = None): - """Save lyrics (unicode string) to a file specified in path. - If path is None, then a default value is used.""" - self.logger.info('Saving lyrics...') - try: - if path: - file = open(path, 'w') - else: - file = open(self.__lyrics_path, 'w') - file.write(lyrics.encode('utf-8')) - file.close() - self.logger.info('Lyrics successfully saved.') - except IOError, e: - self.logger.error('Error writing lyrics: %s', e) + def save_lyrics(self, lyrics): + """ + Save lyrics (unicode string) to the sticker database + """ + self.logger.info('Saving lyrics.') self.mpclient.sticker_set(self.mpclient.cur_song['file'], 'lyrics', lyrics.replace('\n', '\\n')) def del_lyrics_file(self, song = None): -- cgit v1.2.3