Permalink
Browse files

lyrics: ask the lyrics plugin to force the retrieval of new lyrics

Previously, this was done in the main module, which had to guess a bit how the
lyrics system was working: the lyrics file had to be deleted before fetching the
new lyrics, and the call to the function which located the lyrics file was
buggy.
This fixes the following error on fetching a song throught the "Search" button:

    Traceback (most recent call last):
      File ".../sonata/info.py", line 221, in on_link_click
        self.on_link_click_cb(linktype)
      File ".../sonata/main.py", line 3242, in on_link_click
        self.on_lyrics_search(None)
      File ".../sonata/main.py", line 2214, in on_lyrics_search
        consts.LYRICS_LOCATION_HOME)
      File ".../sonata/info.py", line 534, in target_lyrics_filename
        os.path.join(*file_map[lyrics_loc]))
      File "/usr/lib/python2.6/posixpath.py", line 65, in join
        if b.startswith('/'):
    AttributeError: 'NoneType' object has no attribute 'startswith'

Now, we let the lyrics system handle all of this, and we ask it to force the
fetching, even if a lyrics file already existed.
  • Loading branch information...
1 parent 7d3017c commit 389cacd97e166184e88aa73b6147b39c9169469a @multani committed Jan 25, 2011
Showing with 18 additions and 10 deletions.
  1. +10 −2 sonata/info.py
  2. +8 −8 sonata/main.py
View
@@ -341,7 +341,7 @@ def _check_for_local_lyrics(self, artist, title, song_dir):
return filename
def get_lyrics_start(self, search_artist, search_title, filename_artist,
- filename_title, song_dir):
+ filename_title, song_dir, force_fetch=False):
filename_artist = misc.strip_all_slashes(filename_artist)
filename_title = misc.strip_all_slashes(filename_title)
filename = self._check_for_local_lyrics(filename_artist,
@@ -357,11 +357,19 @@ def get_lyrics_start(self, search_artist, search_title, filename_artist,
lyrics = f.read()
except IOError:
pass
+
if lyrics == _("Lyrics not found"):
- misc.remove_file(filename)
+ force_fetch = True
+
+ if force_fetch:
+ # Remove all lyrics for this song
+ while filename is not None:
filename = self._check_for_local_lyrics(filename_artist,
filename_title,
song_dir)
+ if filename is not None:
+ misc.remove_file(filename)
+
if filename:
# Re-use lyrics from file:
try:
View
@@ -2208,15 +2208,15 @@ def on_lyrics_search(self, _event):
ui.show(dialog.vbox)
response = dialog.run()
if response == gtk.RESPONSE_ACCEPT:
- # Delete current lyrics:
- filename = self.info.target_lyrics_filename(artist, title, None,
- consts.LYRICS_LOCATION_HOME)
- misc.remove_file(filename)
# Search for new lyrics:
- self.info.get_lyrics_start(artist_entry.get_text(),
- title_entry.get_text(), artist, title,
- os.path.dirname(mpdh.get(self.songinfo,
- 'file')))
+ self.info.get_lyrics_start(
+ artist_entry.get_text(),
+ title_entry.get_text(),
+ artist,
+ title,
+ os.path.dirname(mpdh.get(self.songinfo, 'file')),
+ force_fetch=True)
+
dialog.destroy()
def mpd_shuffle(self, _action):

0 comments on commit 389cacd

Please sign in to comment.