Skip to content

Commit e5a966d

Browse files
ontomultani
authored andcommitted
Sonata automatically fetches lyrics in a new thread.
Before, the lyric plugin had to do it by itself, which means *each* lyric plugins had to do it by themselves. Now, the plugin code is launched into a new thread, not matter what.
1 parent b3871a5 commit e5a966d

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

sonata/info.py

+24-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
from __future__ import with_statement
23

34
import sys
@@ -7,12 +8,12 @@
78

89
import gtk
910
import pango
10-
import gobject
1111

1212
import ui
1313
import misc
1414
import mpdhelper as mpdh
1515
import consts
16+
import threading
1617
from pluginsystem import pluginsystem
1718

1819

@@ -386,18 +387,28 @@ def get_lyrics_start(self, search_artist, search_title, filename_artist,
386387
lyrics = lyrics[len(header):]
387388
self._show_lyrics(filename_artist, filename_title, lyrics=lyrics)
388389
else:
389-
# Fetch lyrics from lyricwiki.org etc.
390-
lyrics_fetchers = pluginsystem.get('lyrics_fetching')
391-
callback = lambda * args: self.get_lyrics_response(
392-
filename_artist, filename_title, song_dir, *args)
393-
if lyrics_fetchers:
394-
msg = _("Fetching lyrics...")
395-
for _plugin, cb in lyrics_fetchers:
396-
cb(callback, search_artist, search_title)
397-
else:
398-
msg = _("No lyrics plug-in enabled.")
399-
self._show_lyrics(filename_artist, filename_title,
400-
lyrics=msg)
390+
# Fetch lyrics from plugins.
391+
thread = threading.Thread(target=self.fetch_lyrics_from_plugins,
392+
args=(search_artist, search_title,
393+
song_dir))
394+
thread.start()
395+
396+
def fetch_lyrics_from_plugins(self, search_artist, search_title, song_dir):
397+
lyrics_fetchers = pluginsystem.get('lyrics_fetching')
398+
if lyrics_fetchers:
399+
self._show_lyrics(search_artist, search_title,
400+
lyrics=_("Fetching lyrics..."))
401+
for plugin, get_lyrics in lyrics_fetchers:
402+
lyrics = get_lyrics(search_artist, search_title)
403+
if lyrics:
404+
self.get_lyrics_response(search_artist, search_title,
405+
song_dir, lyrics=lyrics)
406+
return
407+
msg = _("Lyrics not found.")
408+
else:
409+
msg = _("No lyrics plug-in enabled.")
410+
411+
self._show_lyrics(search_artist, search_title, lyrics=msg)
401412

402413
def get_lyrics_response(self, artist_then, title_then, song_dir,
403414
lyrics=None, error=None):

0 commit comments

Comments
 (0)