|
a/src/filters/rclaudio |
|
b/src/filters/rclaudio |
|
... |
|
... |
162 |
'\xa9ope' : 'ORIGINALARTIST',
|
162 |
'\xa9ope' : 'ORIGINALARTIST',
|
163 |
'\xa9too' : 'ENCODEDBY',
|
163 |
'\xa9too' : 'ENCODEDBY',
|
164 |
'\xa9wrt' : 'COMPOSER',
|
164 |
'\xa9wrt' : 'COMPOSER',
|
165 |
}
|
165 |
}
|
166 |
|
166 |
|
|
|
167 |
def tobytes(s):
|
|
|
168 |
if type(s) == type(b''):
|
|
|
169 |
return s
|
|
|
170 |
if type(s) != type(u''):
|
|
|
171 |
s = str(s)
|
|
|
172 |
return s.encode('utf-8', errors='replace')
|
|
|
173 |
|
167 |
# mp3: album, title, artist, genre, date, tracknumber
|
174 |
# mp3: album, title, artist, genre, date, tracknumber
|
168 |
# flac: album, title, artist, genre, xxx, tracknumber
|
175 |
# flac: album, title, artist, genre, xxx, tracknumber
|
169 |
# oggvorbis:album, title, artist, genre, date, tracknumber
|
176 |
# oggvorbis:album, title, artist, genre, date, tracknumber
|
170 |
class AudioTagExtractor:
|
177 |
class AudioTagExtractor:
|
171 |
def __init__(self, em):
|
178 |
def __init__(self, em):
|
|
... |
|
... |
274 |
except:
|
281 |
except:
|
275 |
#self.em.rclog("using default bits_per_sample")
|
282 |
#self.em.rclog("using default bits_per_sample")
|
276 |
minf['bits_per_sample'] = 16
|
283 |
minf['bits_per_sample'] = 16
|
277 |
|
284 |
|
278 |
for tag,val in minf.items():
|
285 |
for tag,val in minf.items():
|
279 |
val = str(val)
|
|
|
280 |
if type(val) == type(u''):
|
|
|
281 |
val = val.encode('utf-8', errors='replace')
|
|
|
282 |
minf[tag] = val
|
286 |
minf[tag] = tobytes(val)
|
283 |
|
287 |
|
284 |
####################
|
288 |
####################
|
285 |
# Metadata tags. The names vary depending on the file type. We
|
289 |
# Metadata tags. The names vary depending on the file type. We
|
286 |
# just have a big translation dictionary for all
|
290 |
# just have a big translation dictionary for all
|
287 |
for tag,val in mutf.items():
|
291 |
for tag,val in mutf.items():
|
288 |
#self.em.rclog("Original tag: <%s>, val <%s>" % (tag, val))
|
|
|
289 |
if tag.upper() in tagdict:
|
292 |
if tag.upper() in tagdict:
|
290 |
tag = tag.upper()
|
293 |
tag = tag.upper()
|
291 |
if tag in tagdict:
|
294 |
if tag in tagdict:
|
|
|
295 |
#self.em.rclog("Original tag: <%s>, type0 %s val <%s>" %
|
|
|
296 |
# (tag, type(val), val))
|
|
|
297 |
# Some file types return lists of value (e.g. FLAC)
|
|
|
298 |
try:
|
|
|
299 |
val = " ".join(val)
|
|
|
300 |
#self.em.rclog("Joined tag: <%s>, type0 %s val <%s>" %
|
|
|
301 |
# (tag, type(val), val))
|
|
|
302 |
except:
|
|
|
303 |
pass
|
292 |
ntag = tagdict[tag].lower()
|
304 |
ntag = tagdict[tag].lower()
|
293 |
#self.em.rclog("New tag: %s" % ntag)
|
305 |
#self.em.rclog("New tag: %s" % ntag)
|
294 |
try:
|
306 |
try:
|
295 |
if type(val) == type(u''):
|
|
|
296 |
val = val.encode('utf-8', errors='replace')
|
|
|
297 |
elif type(val) != type(b''):
|
|
|
298 |
val = str(val)
|
|
|
299 |
if type(val) == type(u''):
|
|
|
300 |
val = val.encode('utf-8', errors='replace')
|
|
|
301 |
minf[ntag] = val
|
307 |
minf[ntag] = tobytes(val)
|
302 |
#self.em.rclog("Tag %s -> %s" % (ntag, val0))
|
308 |
#self.em.rclog("Tag %s -> %s" % (ntag, val))
|
303 |
except Exception as err:
|
309 |
except Exception as err:
|
304 |
self.em.rclog("Error while extracting tag: %s"%err)
|
310 |
self.em.rclog("Error while extracting tag: %s"%err)
|
305 |
else:
|
311 |
else:
|
306 |
#self.em.rclog("Unprocessed tag: %s, value %s"%(tag,val))
|
312 |
#self.em.rclog("Unprocessed tag: %s, value %s"%(tag,val))
|
307 |
pass
|
313 |
pass
|
|
... |
|
... |
338 |
|
344 |
|
339 |
# Check for embedded image. We just set a flag.
|
345 |
# Check for embedded image. We just set a flag.
|
340 |
embdimg = self._embeddedImageFormat(mutf)
|
346 |
embdimg = self._embeddedImageFormat(mutf)
|
341 |
if embdimg:
|
347 |
if embdimg:
|
342 |
#self.em.rclog("Embedded image format: %s" % embdimg)
|
348 |
#self.em.rclog("Embedded image format: %s" % embdimg)
|
343 |
if type(embdimg) == type(u''):
|
349 |
embdimg = tobytes(embdimg)
|
344 |
minf["embdimg"] = embdimg.encode('ascii', errors='replace')
|
|
|
345 |
else:
|
|
|
346 |
minf["embdimg"] = embdimg
|
|
|
347 |
|
350 |
|
348 |
self.em.setmimetype("text/plain")
|
351 |
self.em.setmimetype("text/plain")
|
349 |
self.em.setfield("charset", 'utf-8')
|
352 |
self.em.setfield("charset", 'utf-8')
|
350 |
|
353 |
|
351 |
for tag,val in minf.items():
|
354 |
for tag,val in minf.items():
|
|
... |
|
... |
354 |
# Compat with old version
|
357 |
# Compat with old version
|
355 |
if tag == 'artist':
|
358 |
if tag == 'artist':
|
356 |
self.em.setfield('author', val)
|
359 |
self.em.setfield('author', val)
|
357 |
|
360 |
|
358 |
try:
|
361 |
try:
|
359 |
docdata = mutf.pprint().encode('utf-8', errors='replace')
|
362 |
docdata = tobytes(mutf.pprint())
|
360 |
except Exception as err:
|
363 |
except Exception as err:
|
361 |
self.em.rclog("Doc pprint error: %s" % err)
|
364 |
self.em.rclog("Doc pprint error: %s" % err)
|
362 |
|
365 |
|
363 |
ok = True
|
366 |
ok = True
|
364 |
return (ok, docdata, "", rclexecm.RclExecM.eofnext)
|
367 |
return (ok, docdata, "", rclexecm.RclExecM.eofnext)
|