diff options
| author | jvoisin | 2018-10-11 19:52:47 +0200 |
|---|---|---|
| committer | jvoisin | 2018-10-11 19:52:47 +0200 |
| commit | b9dbd12ef91f4dfba8c1d0737ab52ff87ac515f1 (patch) | |
| tree | 89a3eccfc073233d0ba3973e0a46ef91e791aed4 /libmat2/audio.py | |
| parent | b2e153b69caac208fb1821e2f21436a2f0487188 (diff) | |
Implement recursive metadata for FLAC files
Since FLAC files can contain covers, it makes sense
to parse their metadata
Diffstat (limited to 'libmat2/audio.py')
| -rw-r--r-- | libmat2/audio.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/libmat2/audio.py b/libmat2/audio.py index f2a5e94..b67f766 100644 --- a/libmat2/audio.py +++ b/libmat2/audio.py | |||
| @@ -1,8 +1,11 @@ | |||
| 1 | import mimetypes | ||
| 2 | import os | ||
| 1 | import shutil | 3 | import shutil |
| 4 | import tempfile | ||
| 2 | 5 | ||
| 3 | import mutagen | 6 | import mutagen |
| 4 | 7 | ||
| 5 | from . import abstract | 8 | from . import abstract, parser_factory |
| 6 | 9 | ||
| 7 | 10 | ||
| 8 | class MutagenParser(abstract.AbstractParser): | 11 | class MutagenParser(abstract.AbstractParser): |
| @@ -55,6 +58,14 @@ class FLACParser(MutagenParser): | |||
| 55 | 58 | ||
| 56 | def get_meta(self): | 59 | def get_meta(self): |
| 57 | meta = super().get_meta() | 60 | meta = super().get_meta() |
| 58 | if mutagen.File(self.filename).pictures: | 61 | for num, picture in enumerate(mutagen.File(self.filename).pictures): |
| 59 | meta['Picture'] = 'Cover' | 62 | name = picture.desc if picture.desc else 'Cover %d' % num |
| 63 | _, fname = tempfile.mkstemp() | ||
| 64 | with open(fname, 'wb') as f: | ||
| 65 | f.write(picture.data) | ||
| 66 | extension = mimetypes.guess_extension(picture.mime) | ||
| 67 | shutil.move(fname, fname + extension) | ||
| 68 | p, _ = parser_factory.get_parser(fname+extension) | ||
| 69 | meta[name] = p.get_meta() if p else 'harmful data' | ||
| 70 | os.remove(fname + extension) | ||
| 60 | return meta | 71 | return meta |
