From 38fae60b8beaf9c7b37c65325d2d285e62b6cb85 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Fri, 18 May 2018 23:52:40 +0200 Subject: Rename some files to simplify packaging - the `src` folder is now `libmat2` - the `main.py` script is now `mat2.py` --- libmat2/audio.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 libmat2/audio.py (limited to 'libmat2/audio.py') diff --git a/libmat2/audio.py b/libmat2/audio.py new file mode 100644 index 0000000..3a6aa79 --- /dev/null +++ b/libmat2/audio.py @@ -0,0 +1,39 @@ +import shutil + +import mutagen + +from . import abstract + + +class MutagenParser(abstract.AbstractParser): + def get_meta(self): + f = mutagen.File(self.filename) + if f.tags: + return {k:', '.join(v) for k, v in f.tags.items()} + return {} + + def remove_all(self): + shutil.copy(self.filename, self.output_filename) + f = mutagen.File(self.output_filename) + f.delete() + f.save() + return True + + +class MP3Parser(MutagenParser): + mimetypes = {'audio/mpeg', } + + def get_meta(self): + metadata = {} + meta = mutagen.File(self.filename).tags + for key in meta: + metadata[key.rstrip(' \t\r\n\0')] = ', '.join(map(str, meta[key].text)) + return metadata + + +class OGGParser(MutagenParser): + mimetypes = {'audio/ogg', } + + +class FLACParser(MutagenParser): + mimetypes = {'audio/flac', } -- cgit v1.3