(no commit message)
[paste/456.git] / 0-patch.diff
1 diff --git a/plugins/lyrics/lyrics.py b/plugins/lyrics/lyrics.py
2 index 13124b3..45b054a 100644
3 --- a/plugins/lyrics/lyrics.py
4 +++ b/plugins/lyrics/lyrics.py
5 @@ -32,6 +32,7 @@ import urllib.request
6  import rb
7  from gi.repository import Gtk, Gio, GObject, Peas
8  from gi.repository import RB
9 +from gi.repository import Gst, GstPbutils
10  
11  import LyricsParse
12  from LyricsConfigureDialog import LyricsConfigureDialog
13 @@ -142,10 +143,36 @@ class LyricGrabber(object):
14  
15         def verify_lyric(self):
16                 return os.path.exists(self.cache_path)
17 +
18 +
19 +       def lyric_from_tag(self):
20 +               """
21 +               Extract lyrics from the file meta data (tags)
22 +               Currently supported formats:
23 +               - ogg/vorbis files with "LYRICS" tag
24 +               """
25 +               location = self.entry.get_playback_uri()
26 +               print("discovering %s" % location)
27 +               self.discoverer = GstPbutils.Discoverer(timeout=Gst.SECOND*1)
28 +               info = self.discoverer.discover_uri(location)
29 +               tags = info.get_tags()
30 +               if tags is None:
31 +                       return
32 +
33 +               for i in range(tags.get_tag_size("extended-comment")):
34 +                       (exists, value) = tags.get_string_index("extended-comment", i)
35 +                       if exists and value.startswith("LYRICS"):
36 +                               text = value.replace("LYRICS=", "")
37 +                               return text
38           
39         def search_lyrics(self, callback, cache_only=False):
40                 self.callback = callback
41 -               
42 +
43 +               text = self.lyric_from_tag()
44 +               if text is not None:
45 +                       self.callback(text)
46 +                       return
47 +
48                 status = self.verify_lyric()
49                 
50                 if status: