diff options
| author | jvoisin | 2018-03-31 15:46:17 +0200 |
|---|---|---|
| committer | jvoisin | 2018-03-31 15:46:17 +0200 |
| commit | f391c9603c36a8ec80942c23ac6ba39fca5df72a (patch) | |
| tree | 7fdc2053c01f103a675274ebd3e6abcffba4dfbe /src/audio.py | |
| parent | 088c3d013ce4515920dea5e0becb98b36afa9a31 (diff) | |
Change a bit the source code organisation
Diffstat (limited to 'src/audio.py')
| -rw-r--r-- | src/audio.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/audio.py b/src/audio.py new file mode 100644 index 0000000..4da298c --- /dev/null +++ b/src/audio.py | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | import subprocess | ||
| 2 | import shutil | ||
| 3 | import json | ||
| 4 | |||
| 5 | import mutagen | ||
| 6 | |||
| 7 | from . import abstract | ||
| 8 | |||
| 9 | class MutagenParser(abstract.AbstractParser): | ||
| 10 | def get_meta(self): | ||
| 11 | f = mutagen.File(self.filename) | ||
| 12 | if f.tags: | ||
| 13 | return f.tags | ||
| 14 | return {} | ||
| 15 | |||
| 16 | def remove_all(self): | ||
| 17 | shutil.copy(self.filename, self.output_filename) | ||
| 18 | f = mutagen.File(self.output_filename) | ||
| 19 | f.delete() | ||
| 20 | f.save() | ||
| 21 | return True | ||
| 22 | |||
| 23 | class MP3Parser(MutagenParser): | ||
| 24 | mimetypes = {'audio/mpeg', } | ||
| 25 | |||
| 26 | def get_meta(self): | ||
| 27 | meta = super().get_meta() | ||
| 28 | metadata = {} | ||
| 29 | for key in meta: | ||
| 30 | metadata[key] = meta[key].text | ||
| 31 | return metadata | ||
| 32 | |||
| 33 | class OGGParser(MutagenParser): | ||
| 34 | mimetypes = {'audio/ogg', } | ||
| 35 | |||
| 36 | class FLACParser(MutagenParser): | ||
| 37 | mimetypes = {'audio/flac', } | ||
