diff options
| author | jvoisin | 2023-01-28 15:57:20 +0000 |
|---|---|---|
| committer | jvoisin | 2023-01-28 15:57:20 +0000 |
| commit | 39fb254e019c920516bb317d4b48a8de7cac850e (patch) | |
| tree | 5a5397fe318b8b73f6ebfdb9d1d6c0b64bbda0a3 /libmat2/audio.py | |
| parent | 1f73a16ef36d1a8e771a0b3695818d18e095486b (diff) | |
Fix the type annotations
Diffstat (limited to 'libmat2/audio.py')
| -rw-r--r-- | libmat2/audio.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/libmat2/audio.py b/libmat2/audio.py index 366d451..aa4afdb 100644 --- a/libmat2/audio.py +++ b/libmat2/audio.py | |||
| @@ -2,7 +2,7 @@ import mimetypes | |||
| 2 | import os | 2 | import os |
| 3 | import shutil | 3 | import shutil |
| 4 | import tempfile | 4 | import tempfile |
| 5 | from typing import Union | 5 | from typing import Union, Dict |
| 6 | 6 | ||
| 7 | import mutagen | 7 | import mutagen |
| 8 | 8 | ||
| @@ -18,10 +18,10 @@ class MutagenParser(abstract.AbstractParser): | |||
| 18 | except mutagen.MutagenError: | 18 | except mutagen.MutagenError: |
| 19 | raise ValueError | 19 | raise ValueError |
| 20 | 20 | ||
| 21 | def get_meta(self) -> dict[str, Union[str, dict]]: | 21 | def get_meta(self) -> Dict[str, Union[str, Dict]]: |
| 22 | f = mutagen.File(self.filename) | 22 | f = mutagen.File(self.filename) |
| 23 | if f.tags: | 23 | if f.tags: |
| 24 | return {k:', '.join(map(str, v)) for k, v in f.tags.items()} | 24 | return {k: ', '.join(map(str, v)) for k, v in f.tags.items()} |
| 25 | return {} | 25 | return {} |
| 26 | 26 | ||
| 27 | def remove_all(self) -> bool: | 27 | def remove_all(self) -> bool: |
| @@ -38,8 +38,8 @@ class MutagenParser(abstract.AbstractParser): | |||
| 38 | class MP3Parser(MutagenParser): | 38 | class MP3Parser(MutagenParser): |
| 39 | mimetypes = {'audio/mpeg', } | 39 | mimetypes = {'audio/mpeg', } |
| 40 | 40 | ||
| 41 | def get_meta(self) -> dict[str, Union[str, dict]]: | 41 | def get_meta(self) -> Dict[str, Union[str, Dict]]: |
| 42 | metadata = {} # type: dict[str, Union[str, dict]] | 42 | metadata = {} # type: Dict[str, Union[str, Dict]] |
| 43 | meta = mutagen.File(self.filename).tags | 43 | meta = mutagen.File(self.filename).tags |
| 44 | if not meta: | 44 | if not meta: |
| 45 | return metadata | 45 | return metadata |
| @@ -68,12 +68,12 @@ class FLACParser(MutagenParser): | |||
| 68 | f.save(deleteid3=True) | 68 | f.save(deleteid3=True) |
| 69 | return True | 69 | return True |
| 70 | 70 | ||
| 71 | def get_meta(self) -> dict[str, Union[str, dict]]: | 71 | def get_meta(self) -> Dict[str, Union[str, Dict]]: |
| 72 | meta = super().get_meta() | 72 | meta = super().get_meta() |
| 73 | for num, picture in enumerate(mutagen.File(self.filename).pictures): | 73 | for num, picture in enumerate(mutagen.File(self.filename).pictures): |
| 74 | name = picture.desc if picture.desc else 'Cover %d' % num | 74 | name = picture.desc if picture.desc else 'Cover %d' % num |
| 75 | extension = mimetypes.guess_extension(picture.mime) | 75 | extension = mimetypes.guess_extension(picture.mime) |
| 76 | if extension is None: # pragma: no cover | 76 | if extension is None: # pragma: no cover |
| 77 | meta[name] = 'harmful data' | 77 | meta[name] = 'harmful data' |
| 78 | continue | 78 | continue |
| 79 | 79 | ||
| @@ -98,6 +98,7 @@ class WAVParser(video.AbstractFFmpegParser): | |||
| 98 | 'MIMEType', 'NumChannels', 'SampleRate', 'SourceFile', | 98 | 'MIMEType', 'NumChannels', 'SampleRate', 'SourceFile', |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | |||
| 101 | class AIFFParser(video.AbstractFFmpegParser): | 102 | class AIFFParser(video.AbstractFFmpegParser): |
| 102 | mimetypes = {'audio/aiff', 'audio/x-aiff'} | 103 | mimetypes = {'audio/aiff', 'audio/x-aiff'} |
| 103 | meta_allowlist = {'AvgBytesPerSec', 'BitsPerSample', 'Directory', | 104 | meta_allowlist = {'AvgBytesPerSec', 'BitsPerSample', 'Directory', |
