rclaudio: more fixes: complicated because the different file type handlers (e.g. flac, mp3) return data in different types.
This commit is contained in:
parent
a012b831fa
commit
f0bedb2201
@ -164,6 +164,13 @@ tagdict = {
|
|||||||
'\xa9wrt' : 'COMPOSER',
|
'\xa9wrt' : 'COMPOSER',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def tobytes(s):
|
||||||
|
if type(s) == type(b''):
|
||||||
|
return s
|
||||||
|
if type(s) != type(u''):
|
||||||
|
s = str(s)
|
||||||
|
return s.encode('utf-8', errors='replace')
|
||||||
|
|
||||||
# mp3: album, title, artist, genre, date, tracknumber
|
# mp3: album, title, artist, genre, date, tracknumber
|
||||||
# flac: album, title, artist, genre, xxx, tracknumber
|
# flac: album, title, artist, genre, xxx, tracknumber
|
||||||
# oggvorbis:album, title, artist, genre, date, tracknumber
|
# oggvorbis:album, title, artist, genre, date, tracknumber
|
||||||
@ -276,30 +283,29 @@ class AudioTagExtractor:
|
|||||||
minf['bits_per_sample'] = 16
|
minf['bits_per_sample'] = 16
|
||||||
|
|
||||||
for tag,val in minf.items():
|
for tag,val in minf.items():
|
||||||
val = str(val)
|
minf[tag] = tobytes(val)
|
||||||
if type(val) == type(u''):
|
|
||||||
val = val.encode('utf-8', errors='replace')
|
|
||||||
minf[tag] = val
|
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# Metadata tags. The names vary depending on the file type. We
|
# Metadata tags. The names vary depending on the file type. We
|
||||||
# just have a big translation dictionary for all
|
# just have a big translation dictionary for all
|
||||||
for tag,val in mutf.items():
|
for tag,val in mutf.items():
|
||||||
#self.em.rclog("Original tag: <%s>, val <%s>" % (tag, val))
|
|
||||||
if tag.upper() in tagdict:
|
if tag.upper() in tagdict:
|
||||||
tag = tag.upper()
|
tag = tag.upper()
|
||||||
if tag in tagdict:
|
if tag in tagdict:
|
||||||
|
#self.em.rclog("Original tag: <%s>, type0 %s val <%s>" %
|
||||||
|
# (tag, type(val), val))
|
||||||
|
# Some file types return lists of value (e.g. FLAC)
|
||||||
|
try:
|
||||||
|
val = " ".join(val)
|
||||||
|
#self.em.rclog("Joined tag: <%s>, type0 %s val <%s>" %
|
||||||
|
# (tag, type(val), val))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
ntag = tagdict[tag].lower()
|
ntag = tagdict[tag].lower()
|
||||||
#self.em.rclog("New tag: %s" % ntag)
|
#self.em.rclog("New tag: %s" % ntag)
|
||||||
try:
|
try:
|
||||||
if type(val) == type(u''):
|
minf[ntag] = tobytes(val)
|
||||||
val = val.encode('utf-8', errors='replace')
|
#self.em.rclog("Tag %s -> %s" % (ntag, val))
|
||||||
elif type(val) != type(b''):
|
|
||||||
val = str(val)
|
|
||||||
if type(val) == type(u''):
|
|
||||||
val = val.encode('utf-8', errors='replace')
|
|
||||||
minf[ntag] = val
|
|
||||||
#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:
|
else:
|
||||||
@ -340,10 +346,7 @@ class AudioTagExtractor:
|
|||||||
embdimg = self._embeddedImageFormat(mutf)
|
embdimg = self._embeddedImageFormat(mutf)
|
||||||
if embdimg:
|
if embdimg:
|
||||||
#self.em.rclog("Embedded image format: %s" % embdimg)
|
#self.em.rclog("Embedded image format: %s" % embdimg)
|
||||||
if type(embdimg) == type(u''):
|
embdimg = tobytes(embdimg)
|
||||||
minf["embdimg"] = embdimg.encode('ascii', errors='replace')
|
|
||||||
else:
|
|
||||||
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')
|
||||||
@ -356,7 +359,7 @@ class AudioTagExtractor:
|
|||||||
self.em.setfield('author', val)
|
self.em.setfield('author', val)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
docdata = mutf.pprint().encode('utf-8', errors='replace')
|
docdata = tobytes(mutf.pprint())
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self.em.rclog("Doc pprint error: %s" % err)
|
self.em.rclog("Doc pprint error: %s" % err)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user