diff options
| author | jvoisin | 2018-04-04 21:59:46 +0200 |
|---|---|---|
| committer | jvoisin | 2018-04-04 21:59:46 +0200 |
| commit | 4ee091d833b55932fec345cc7403ef3723ecbd2f (patch) | |
| tree | 988bd7f50cdf32e34ff4418246461032fee29af9 /src | |
| parent | 1ad817566de019521f565f4a7542f91b97c8a7a4 (diff) | |
Improve get_meta in various ways
- Normalize the case
- Strip \00, \r, space and \n
- Flatten metadata lists
- Add tests for audio files
Diffstat (limited to 'src')
| -rw-r--r-- | src/audio.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/audio.py b/src/audio.py index 4da298c..0f4b5c0 100644 --- a/src/audio.py +++ b/src/audio.py | |||
| @@ -10,7 +10,7 @@ class MutagenParser(abstract.AbstractParser): | |||
| 10 | def get_meta(self): | 10 | def get_meta(self): |
| 11 | f = mutagen.File(self.filename) | 11 | f = mutagen.File(self.filename) |
| 12 | if f.tags: | 12 | if f.tags: |
| 13 | return f.tags | 13 | return {k:', '.join(v) for k,v in f.tags.items()} |
| 14 | return {} | 14 | return {} |
| 15 | 15 | ||
| 16 | def remove_all(self): | 16 | def remove_all(self): |
| @@ -24,10 +24,10 @@ class MP3Parser(MutagenParser): | |||
| 24 | mimetypes = {'audio/mpeg', } | 24 | mimetypes = {'audio/mpeg', } |
| 25 | 25 | ||
| 26 | def get_meta(self): | 26 | def get_meta(self): |
| 27 | meta = super().get_meta() | ||
| 28 | metadata = {} | 27 | metadata = {} |
| 28 | meta = mutagen.File(self.filename).tags | ||
| 29 | for key in meta: | 29 | for key in meta: |
| 30 | metadata[key] = meta[key].text | 30 | metadata[key.rstrip(' \t\r\n\0')] = ', '.join(map(str, meta[key].text)) |
| 31 | return metadata | 31 | return metadata |
| 32 | 32 | ||
| 33 | class OGGParser(MutagenParser): | 33 | class OGGParser(MutagenParser): |
