Skip to content

Commit

Permalink
Sonata automatically fetches lyrics in a new thread.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
onto authored and multani committed Nov 7, 2012
1 parent b3871a5 commit e5a966d
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions sonata/info.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

from __future__ import with_statement

import sys
Expand All @@ -7,12 +8,12 @@

import gtk
import pango
import gobject

import ui
import misc
import mpdhelper as mpdh
import consts
import threading
from pluginsystem import pluginsystem


Expand Down Expand Up @@ -386,18 +387,28 @@ def get_lyrics_start(self, search_artist, search_title, filename_artist,
lyrics = lyrics[len(header):]
self._show_lyrics(filename_artist, filename_title, lyrics=lyrics)
else:
# Fetch lyrics from lyricwiki.org etc.
lyrics_fetchers = pluginsystem.get('lyrics_fetching')
callback = lambda * args: self.get_lyrics_response(
filename_artist, filename_title, song_dir, *args)
if lyrics_fetchers:
msg = _("Fetching lyrics...")
for _plugin, cb in lyrics_fetchers:
cb(callback, search_artist, search_title)
else:
msg = _("No lyrics plug-in enabled.")
self._show_lyrics(filename_artist, filename_title,
lyrics=msg)
# Fetch lyrics from plugins.
thread = threading.Thread(target=self.fetch_lyrics_from_plugins,
args=(search_artist, search_title,
song_dir))
thread.start()

def fetch_lyrics_from_plugins(self, search_artist, search_title, song_dir):
lyrics_fetchers = pluginsystem.get('lyrics_fetching')
if lyrics_fetchers:
self._show_lyrics(search_artist, search_title,
lyrics=_("Fetching lyrics..."))
for plugin, get_lyrics in lyrics_fetchers:
lyrics = get_lyrics(search_artist, search_title)
if lyrics:
self.get_lyrics_response(search_artist, search_title,
song_dir, lyrics=lyrics)
return
msg = _("Lyrics not found.")
else:
msg = _("No lyrics plug-in enabled.")

self._show_lyrics(search_artist, search_title, lyrics=msg)

def get_lyrics_response(self, artist_then, title_then, song_dir,
lyrics=None, error=None):
Expand Down

0 comments on commit e5a966d

Please sign in to comment.