1from mutagen.flac
import FLAC
2from mutagen.mp3
import MP3
3from mutagen.mp4
import MP4
4from mutagen.oggvorbis
import OggVorbis
5from mutagen.apev2
import APEv2
8LANGUAGE = ADDON.getLocalizedString
20 lyrics = Lyrics(settings=lyricssettings)
24 lry = lyrics.song.embed
27 if (getlrc
and match)
or ((
not getlrc)
and (
not match)):
28 if lyrics.song.source:
29 lyrics.source = lyrics.song.source
32 filename = song.filepath
33 ext = os.path.splitext(filename)[1].lower()
34 sup_ext = [
'.mp3',
'.flac',
'.ogg',
'.ape',
'.m4a']
60Get lyrics embed with Lyrics3/Lyrics3V2 format
61See: http://id3.org/Lyrics3
62 http://id3.org/Lyrics3v2
64def getLyrics3(bfile, getlrc):
65 bfile.seek(-128-9, os.SEEK_END)
67 if (buf != b
'LYRICS200' and buf != b
'LYRICSEND'):
68 bfile.seek(-9, os.SEEK_END)
70 if (buf == b
'LYRICSEND'):
71 ''' Find Lyrics3v1 '''
72 bfile.seek(-5100-9-11, os.SEEK_CUR)
73 buf = bfile.read(5100+11)
74 start = buf.find(b
'LYRICSBEGIN')
76 enc = chardet.detect(data)
77 content = data.decode(enc[
'encoding'])
78 if (getlrc
and isLRC(content))
or (
not getlrc
and not isLRC(content)):
80 elif (buf == b
'LYRICS200'):
81 ''' Find Lyrics3v2 '''
82 bfile.seek(-9-6, os.SEEK_CUR)
83 size = int(bfile.read(6))
84 bfile.seek(-size-6, os.SEEK_CUR)
86 if(buf == b
'LYRICSBEGIN'):
87 buf = bfile.read(size-11)
91 length = int(buf[3:8])
92 data = buf[8:8+length]
93 enc = chardet.detect(data)
94 content = data.decode(enc[
'encoding'])
96 if (getlrc
and isLRC(content))
or (
not getlrc
and not isLRC(content)):
101 mins =
'0%s' % int(ms/1000/60)
102 sec =
'0%s' % int((ms/1000)%60)
103 msec =
'0%s' % int((ms%1000)/10)
104 timestamp =
'[%s:%s.%s]' % (mins[-2:],sec[-2:],msec[-2:])
108Get USLT/SYLT/TXXX lyrics embed with ID3v2 format
109See: http://id3.org/id3v2.3.0
115 for tag,value
in data.items():
116 if getlrc
and tag.startswith(
'SYLT'):
117 for line
in data[tag].text:
118 txt = line[0].strip()
120 lyr +=
'%s%s\r\n' % (stamp, txt)
121 elif not getlrc
and tag.startswith(
'USLT'):
124 elif tag.startswith(
'TXXX'):
125 if getlrc
and tag.upper().endswith(
'SYNCEDLYRICS'):
126 lyr = data[tag].text[0]
127 elif not getlrc
and tag.upper().endswith(
'LYRICS'):
128 lyr = data[tag].text[0]
138 lyr = tags[
'lyrics'][0]
140 if (getlrc
and match)
or ((
not getlrc)
and (
not match)):
149 lyr = tags[
'©lyr'][0]
151 if (getlrc
and match)
or ((
not getlrc)
and (
not match)):
158 tags = OggVorbis(bfile)
160 lyr = tags[
'lyrics'][0]
162 if (getlrc
and match)
or ((
not getlrc)
and (
not match)):
171 lyr = tags[
'lyrics'][0]
173 if (getlrc
and match)
or ((
not getlrc)
and (
not match)):
179 match = re.compile(
'\[(\d+):(\d\d)(\.\d+|)\]').search(lyr)
bytearray readBytes(self, int numBytes=0)
def getID3Lyrics(bfile, getlrc)
def getFlacLyrics(bfile, getlrc)
def getMP4Lyrics(bfile, getlrc)
def getOGGLyrics(bfile, getlrc)
def getAPELyrics(bfile, getlrc)
def getLyrics3(bfile, getlrc)
def getEmbedLyrics(song, getlrc, lyricssettings)