2018-03-25 16:17:41 +02:00
|
|
|
import shutil
|
|
|
|
|
|
|
|
import mutagen
|
|
|
|
|
|
|
|
from . import abstract
|
|
|
|
|
2018-04-04 23:21:48 +02:00
|
|
|
|
2018-03-25 16:17:41 +02:00
|
|
|
class MutagenParser(abstract.AbstractParser):
|
|
|
|
def get_meta(self):
|
|
|
|
f = mutagen.File(self.filename)
|
|
|
|
if f.tags:
|
2018-05-16 22:36:59 +02:00
|
|
|
return {k:', '.join(v) for k, v in f.tags.items()}
|
2018-03-25 16:17:41 +02:00
|
|
|
return {}
|
|
|
|
|
|
|
|
def remove_all(self):
|
|
|
|
shutil.copy(self.filename, self.output_filename)
|
|
|
|
f = mutagen.File(self.output_filename)
|
|
|
|
f.delete()
|
|
|
|
f.save()
|
|
|
|
return True
|
|
|
|
|
2018-04-04 23:21:48 +02:00
|
|
|
|
2018-03-25 16:17:41 +02:00
|
|
|
class MP3Parser(MutagenParser):
|
|
|
|
mimetypes = {'audio/mpeg', }
|
|
|
|
|
|
|
|
def get_meta(self):
|
|
|
|
metadata = {}
|
2018-04-04 21:59:46 +02:00
|
|
|
meta = mutagen.File(self.filename).tags
|
2018-03-25 16:31:21 +02:00
|
|
|
for key in meta:
|
2018-04-04 21:59:46 +02:00
|
|
|
metadata[key.rstrip(' \t\r\n\0')] = ', '.join(map(str, meta[key].text))
|
2018-03-25 16:17:41 +02:00
|
|
|
return metadata
|
|
|
|
|
2018-04-04 23:21:48 +02:00
|
|
|
|
2018-03-25 16:17:41 +02:00
|
|
|
class OGGParser(MutagenParser):
|
|
|
|
mimetypes = {'audio/ogg', }
|
2018-03-25 16:20:45 +02:00
|
|
|
|
2018-04-04 23:21:48 +02:00
|
|
|
|
2018-03-25 16:20:45 +02:00
|
|
|
class FLACParser(MutagenParser):
|
2018-06-12 21:27:44 +02:00
|
|
|
mimetypes = {'audio/flac', 'audio/x-flac' }
|