diff options
| author | jvoisin | 2018-03-25 16:17:41 +0200 |
|---|---|---|
| committer | jvoisin | 2018-03-25 16:17:41 +0200 |
| commit | 19a8fd97aa44e2f42a933f43cc9852d6303d7ca6 (patch) | |
| tree | 0b9535609a9c0c7c865fae7e717a6f7f19c8b4e3 /src | |
| parent | 4fa490d941cd0a1743963c4a8cfe89faeab6aded (diff) | |
Implement mp3 and ogg support
Diffstat (limited to 'src')
| -rw-r--r-- | src/parsers/audio.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/parsers/audio.py b/src/parsers/audio.py new file mode 100644 index 0000000..5c5c527 --- /dev/null +++ b/src/parsers/audio.py | |||
| @@ -0,0 +1,35 @@ | |||
| 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 | metadata = {} | ||
| 28 | f = mutagen.File(self.filename) | ||
| 29 | if f.tags: | ||
| 30 | for key in f.tags: | ||
| 31 | metadata[key] = f.tags[key].text | ||
| 32 | return metadata | ||
| 33 | |||
| 34 | class OGGParser(MutagenParser): | ||
| 35 | mimetypes = {'audio/ogg', } | ||
