(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..7333f2f 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,39 @@ 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 +               def fetags (list, tag):
34 +                       print("tag: %s" % tag)
35 +               tags.foreach(fetags)
36 +               for i in range(tags.get_tag_size("extended-comment")):
37 +                       (exists, value) = tags.get_string_index("extended-comment", i)
38 +                       if exists and value.startswith("LYRICS"):
39 +                               text = value.replace("LYRICS=", "")
40 +                               return text
41           
42         def search_lyrics(self, callback, cache_only=False):
43                 self.callback = callback
44 -               
45 +
46 +               text = self.lyric_from_tag()
47 +               if text is not None:
48 +                       self.callback(text)
49 +                       return
50 +
51                 status = self.verify_lyric()
52                 
53                 if status: