(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..2ea38d6 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,41 @@ 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 +                       #ogg/vorbis unsynchronized lyrics
36 +                       if exists and value.startswith("LYRICS"):
37 +                               text = value.replace("LYRICS=", "")
38 +                               return text
39 +                       #ogg/vorbis synchronized lyrics
40 +                       elif exists and value.startswith("SYNCLYRICS"):
41 +                               text = value.replace("SYNCLYRICS=", "")
42 +                               return text
43           
44         def search_lyrics(self, callback, cache_only=False):
45                 self.callback = callback
46 -               
47 +
48 +               text = self.lyric_from_tag()
49 +               if text is not None:
50 +                       self.callback(text)
51 +                       return
52 +
53                 status = self.verify_lyric()
54                 
55                 if status: