diff options
| author | jvoisin | 2018-05-18 23:52:40 +0200 |
|---|---|---|
| committer | jvoisin | 2018-05-18 23:52:40 +0200 |
| commit | 38fae60b8beaf9c7b37c65325d2d285e62b6cb85 (patch) | |
| tree | e6bd4f699d6190dfada7618ebd04455eb7de9660 /libmat2/audio.py | |
| parent | 57d5cd04284276c49899034a9ad321b680624d8f (diff) | |
Rename some files to simplify packaging
- the `src` folder is now `libmat2`
- the `main.py` script is now `mat2.py`
Diffstat (limited to 'libmat2/audio.py')
| -rw-r--r-- | libmat2/audio.py | 39 |
1 files changed, 39 insertions, 0 deletions
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 @@ | |||
| 1 | import shutil | ||
| 2 | |||
| 3 | import mutagen | ||
| 4 | |||
| 5 | from . import abstract | ||
| 6 | |||
| 7 | |||
| 8 | class MutagenParser(abstract.AbstractParser): | ||
| 9 | def get_meta(self): | ||
| 10 | f = mutagen.File(self.filename) | ||
| 11 | if f.tags: | ||
| 12 | return {k:', '.join(v) for k, v in f.tags.items()} | ||
| 13 | return {} | ||
| 14 | |||
| 15 | def remove_all(self): | ||
| 16 | shutil.copy(self.filename, self.output_filename) | ||
| 17 | f = mutagen.File(self.output_filename) | ||
| 18 | f.delete() | ||
| 19 | f.save() | ||
| 20 | return True | ||
| 21 | |||
| 22 | |||
| 23 | class MP3Parser(MutagenParser): | ||
| 24 | mimetypes = {'audio/mpeg', } | ||
| 25 | |||
| 26 | def get_meta(self): | ||
| 27 | metadata = {} | ||
| 28 | meta = mutagen.File(self.filename).tags | ||
| 29 | for key in meta: | ||
| 30 | metadata[key.rstrip(' \t\r\n\0')] = ', '.join(map(str, meta[key].text)) | ||
| 31 | return metadata | ||
| 32 | |||
| 33 | |||
| 34 | class OGGParser(MutagenParser): | ||
| 35 | mimetypes = {'audio/ogg', } | ||
| 36 | |||
| 37 | |||
| 38 | class FLACParser(MutagenParser): | ||
| 39 | mimetypes = {'audio/flac', } | ||
