Process a few non-standard tag names found in the wild + check for embedded images
This commit is contained in:
parent
ba350d685b
commit
d35c2a557a
@ -7,6 +7,7 @@ import os
|
|||||||
import rclexecm
|
import rclexecm
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
import mutagen
|
||||||
from mutagen import File
|
from mutagen import File
|
||||||
from mutagen.id3 import ID3TimeStamp
|
from mutagen.id3 import ID3TimeStamp
|
||||||
except:
|
except:
|
||||||
@ -63,6 +64,8 @@ tagdict = {
|
|||||||
'TPOS' : 'DISCNUMBER',
|
'TPOS' : 'DISCNUMBER',
|
||||||
'TPUB' : 'LABEL',
|
'TPUB' : 'LABEL',
|
||||||
'TXXX:ORCHESTRA' : 'ORCHESTRA',
|
'TXXX:ORCHESTRA' : 'ORCHESTRA',
|
||||||
|
'ORCHESTRA' : 'ORCHESTRA',
|
||||||
|
'ENSEMBLE' : 'ORCHESTRA',
|
||||||
'TRC' : 'ISRC',
|
'TRC' : 'ISRC',
|
||||||
'TRCK' : 'TRACKNUMBER',
|
'TRCK' : 'TRACKNUMBER',
|
||||||
'TRK' : 'TRACKNUMBER',
|
'TRK' : 'TRACKNUMBER',
|
||||||
@ -84,6 +87,7 @@ tagdict = {
|
|||||||
'TXT' : 'LYRICIST',
|
'TXT' : 'LYRICIST',
|
||||||
'TYE' : 'DATE',
|
'TYE' : 'DATE',
|
||||||
'TYER' : 'DATE',
|
'TYER' : 'DATE',
|
||||||
|
'YEAR' : 'DATE',
|
||||||
'ULT' : 'LYRICS',
|
'ULT' : 'LYRICS',
|
||||||
'USLT' : 'LYRICS',
|
'USLT' : 'LYRICS',
|
||||||
'aART' : 'ALBUMARTIST',
|
'aART' : 'ALBUMARTIST',
|
||||||
@ -111,6 +115,7 @@ tagdict = {
|
|||||||
'\xa9too' : 'ENCODEDBY',
|
'\xa9too' : 'ENCODEDBY',
|
||||||
'\xa9wrt' : 'COMPOSER',
|
'\xa9wrt' : 'COMPOSER',
|
||||||
'ALBUM' : 'ALBUM',
|
'ALBUM' : 'ALBUM',
|
||||||
|
'ALBUM ARTIST': 'ALBUMARTIST',
|
||||||
'ALBUMARTIST' : 'ALBUMARTIST',
|
'ALBUMARTIST' : 'ALBUMARTIST',
|
||||||
'ALBUMARTISTSORT' : 'ALBUMARTISTSORT',
|
'ALBUMARTISTSORT' : 'ALBUMARTISTSORT',
|
||||||
'ALBUMSORT' : 'ALBUMSORT',
|
'ALBUMSORT' : 'ALBUMSORT',
|
||||||
@ -140,9 +145,13 @@ tagdict = {
|
|||||||
'RELEASEDATE' : 'RELEASEDATE',
|
'RELEASEDATE' : 'RELEASEDATE',
|
||||||
'REMIXER' : 'REMIXER',
|
'REMIXER' : 'REMIXER',
|
||||||
'SUBTITLE' : 'SUBTITLE',
|
'SUBTITLE' : 'SUBTITLE',
|
||||||
|
'DISCTOTAL' : 'TOTALDISCS',
|
||||||
'TOTALDISCS' : 'TOTALDISCS',
|
'TOTALDISCS' : 'TOTALDISCS',
|
||||||
'TOTALTRACKS' : 'TOTALTRACKS',
|
'TOTALTRACKS' : 'TOTALTRACKS',
|
||||||
|
'TRACKTOTAL' : 'TOTALTRACKS',
|
||||||
'TRACKNUMBER' : 'TRACKNUMBER',
|
'TRACKNUMBER' : 'TRACKNUMBER',
|
||||||
|
'TRACKNUM' : 'TRACKNUMBER',
|
||||||
|
'TRACK' : 'TRACKNUMBER',
|
||||||
'TITLE' : 'TITLE',
|
'TITLE' : 'TITLE',
|
||||||
'TITLESORT' : 'TITLESORT',
|
'TITLESORT' : 'TITLESORT',
|
||||||
}
|
}
|
||||||
@ -162,6 +171,30 @@ class AudioTagExtractor:
|
|||||||
(prop, getattr( mutf.info, prop)))
|
(prop, getattr( mutf.info, prop)))
|
||||||
|
|
||||||
|
|
||||||
|
def _printableFilename(self):
|
||||||
|
return self.filename.decode('utf-8', errors='replace')
|
||||||
|
|
||||||
|
|
||||||
|
def _embeddedImageFormat(self, mutf):
|
||||||
|
#self.em.rclog("_embeddedImage: MIME: %s"%mutf.mime)
|
||||||
|
if 'audio/mp3' in mutf.mime:
|
||||||
|
for tagname in mutf.iterkeys():
|
||||||
|
if tagname.startswith('APIC:'):
|
||||||
|
#self.em.rclog("mp3 img: %s" % mutf[tagname].mime)
|
||||||
|
return 'jpg' if mutf[tagname].mime == 'image/jpeg' else 'png'
|
||||||
|
elif 'audio/x-flac' in mutf.mime:
|
||||||
|
if mutf.pictures:
|
||||||
|
return 'jpg' if mutf.pictures[0].mime == 'image/jpeg' else 'png'
|
||||||
|
elif 'audio/mp4' in mutf.mime:
|
||||||
|
if 'covr' in mutf.iterkeys():
|
||||||
|
format = mutf['covr'][0].imageformat
|
||||||
|
if format == mutagen.mp4.AtomDataType.JPEG:
|
||||||
|
return 'jpg'
|
||||||
|
else:
|
||||||
|
return 'png'
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
def extractone(self, params):
|
def extractone(self, params):
|
||||||
#self.em.rclog("extractone %s %s" % (params["filename:"],
|
#self.em.rclog("extractone %s %s" % (params["filename:"],
|
||||||
# params["mimetype:"]))
|
# params["mimetype:"]))
|
||||||
@ -172,6 +205,7 @@ class AudioTagExtractor:
|
|||||||
return (ok, docdata, "", rclexecm.RclExecM.eofnow)
|
return (ok, docdata, "", rclexecm.RclExecM.eofnow)
|
||||||
filename = params["filename:"]
|
filename = params["filename:"]
|
||||||
mimetype = params["mimetype:"]
|
mimetype = params["mimetype:"]
|
||||||
|
self.filename = filename
|
||||||
try:
|
try:
|
||||||
mutf = File(filename)
|
mutf = File(filename)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
@ -219,6 +253,8 @@ class AudioTagExtractor:
|
|||||||
# just have a big translation dictionary for all
|
# just have a big translation dictionary for all
|
||||||
for tag,val in mutf.iteritems():
|
for tag,val in mutf.iteritems():
|
||||||
#self.em.rclog("Original tag: <%s>, val <%s>" % (tag, val))
|
#self.em.rclog("Original tag: <%s>, val <%s>" % (tag, val))
|
||||||
|
if tag.upper() in tagdict:
|
||||||
|
tag = tag.upper()
|
||||||
if tag in tagdict:
|
if tag in tagdict:
|
||||||
ntag = tagdict[tag].lower()
|
ntag = tagdict[tag].lower()
|
||||||
#self.em.rclog("New tag: %s" % ntag)
|
#self.em.rclog("New tag: %s" % ntag)
|
||||||
@ -234,6 +270,9 @@ class AudioTagExtractor:
|
|||||||
#self.em.rclog("Tag %s -> %s" % (ntag, val0))
|
#self.em.rclog("Tag %s -> %s" % (ntag, val0))
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self.em.rclog("Error while extracting tag: %s"%err)
|
self.em.rclog("Error while extracting tag: %s"%err)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
#self.em.rclog("Unprocessed tag: %s, value %s"%(tag,val))
|
||||||
|
|
||||||
# TPA,TPOS,disc DISCNUMBER/TOTALDISCS
|
# TPA,TPOS,disc DISCNUMBER/TOTALDISCS
|
||||||
# TRCK,TRK,trkn TRACKNUMBER/TOTALTRACKS
|
# TRCK,TRK,trkn TRACKNUMBER/TOTALTRACKS
|
||||||
@ -254,8 +293,15 @@ class AudioTagExtractor:
|
|||||||
|
|
||||||
#self.em.rclog("minf after tags %s\n" % minf)
|
#self.em.rclog("minf after tags %s\n" % minf)
|
||||||
|
|
||||||
|
# Check for embedded image. We just set a flag.
|
||||||
|
embdimg = self._embeddedImageFormat(mutf)
|
||||||
|
if embdimg:
|
||||||
|
#self.em.rclog("Embedded image format: %s" % embdimg)
|
||||||
|
minf["embdimg"] = embdimg
|
||||||
|
|
||||||
self.em.setmimetype("text/plain")
|
self.em.setmimetype("text/plain")
|
||||||
self.em.setfield("charset", 'utf-8')
|
self.em.setfield("charset", 'utf-8')
|
||||||
|
|
||||||
for tag,val in minf.iteritems():
|
for tag,val in minf.iteritems():
|
||||||
#self.em.rclog("%s -> %s" % (tag, val))
|
#self.em.rclog("%s -> %s" % (tag, val))
|
||||||
self.em.setfield(tag, val)
|
self.em.setfield(tag, val)
|
||||||
@ -263,7 +309,6 @@ class AudioTagExtractor:
|
|||||||
if tag == 'artist':
|
if tag == 'artist':
|
||||||
self.em.setfield('author', val)
|
self.em.setfield('author', val)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
docdata = mutf.pprint().encode('utf-8', errors='replace')
|
docdata = mutf.pprint().encode('utf-8', errors='replace')
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
@ -272,14 +317,17 @@ class AudioTagExtractor:
|
|||||||
ok = True
|
ok = True
|
||||||
return (ok, docdata, "", rclexecm.RclExecM.eofnext)
|
return (ok, docdata, "", rclexecm.RclExecM.eofnext)
|
||||||
|
|
||||||
|
|
||||||
###### File type handler api, used by rclexecm ---------->
|
###### File type handler api, used by rclexecm ---------->
|
||||||
def openfile(self, params):
|
def openfile(self, params):
|
||||||
self.currentindex = 0
|
self.currentindex = 0
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def getipath(self, params):
|
def getipath(self, params):
|
||||||
return self.extractone(params)
|
return self.extractone(params)
|
||||||
|
|
||||||
|
|
||||||
def getnext(self, params):
|
def getnext(self, params):
|
||||||
if self.currentindex >= 1:
|
if self.currentindex >= 1:
|
||||||
return (False, "", "", rclexecm.RclExecM.eofnow)
|
return (False, "", "", rclexecm.RclExecM.eofnow)
|
||||||
@ -288,6 +336,7 @@ class AudioTagExtractor:
|
|||||||
self.currentindex += 1
|
self.currentindex += 1
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def makeObject():
|
def makeObject():
|
||||||
print("makeObject");
|
print("makeObject");
|
||||||
proto = rclexecm.RclExecM()
|
proto = rclexecm.RclExecM()
|
||||||
@ -295,6 +344,7 @@ def makeObject():
|
|||||||
extract = AudioTagExtractor(proto)
|
extract = AudioTagExtractor(proto)
|
||||||
return 17
|
return 17
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
proto = rclexecm.RclExecM()
|
proto = rclexecm.RclExecM()
|
||||||
extract = AudioTagExtractor(proto)
|
extract = AudioTagExtractor(proto)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user