From 1804ddf45739ff8c5f32ebec4e73989d84d2ffd9 Mon Sep 17 00:00:00 2001 From: Lynne Date: Mon, 26 Oct 2020 22:44:33 +1000 Subject: [PATCH] code cleanup --- bcao.py | 45 +++++++-------------------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/bcao.py b/bcao.py index de31b22..d6a5bbe 100755 --- a/bcao.py +++ b/bcao.py @@ -23,10 +23,12 @@ from typing import Optional, Union, List, Dict # Picture(), implying that they had imported mutagen.flac.Picture, and therefore i'm right and the computer is WRONG # https://mutagen.readthedocs.io/en/latest/api/flac.html#mutagen.Picture.data import mutagen +# noinspection PyProtectedMember from mutagen.flac import Picture, FLAC from mutagen.oggvorbis import OggVorbis from mutagen.mp3 import MP3 from mutagen.mp4 import MP4, MP4Cover +# noinspection PyProtectedMember from mutagen.id3 import APIC, PictureType from PIL import Image @@ -58,7 +60,11 @@ class SongInfo: self.format = path.splitext(file_name)[1][1:] self.fallback = False - fallbacks = re.match(r"^(?P.+) - (?P.+) - (?P\d{2,}) (?P.+)\.(?:ogg|flac|alac|aiff|wav|mp3|m4a)$", self.file_name) + fallbacks = re.match( + r"^(?P<artist>.+) - (?P<album>.+) - (?P<track>\d{2,}) (?P<title>.+)\.(?:ogg|flac|alac|aiff|wav|mp3|m4a)$", + self.file_name + ) + if fallbacks is None: die("Couldn't determine fallback tags!") return # needed for mypy @@ -151,43 +157,6 @@ def die(message: str, code: int = 1): print(message) sys.exit(code) -# def get_tag(mut_song: MutagenFile, tag: str, allow_list: bool = False, allow_sanitising: bool = True)\ -# -> Union[str, List[str]]: -# if isinstance(mut_song, MP3): -# tag = vorbis_to_id3[tag] -# tag_list = mut_song.tags.getall(tag) -# -# elif isinstance(mut_song, MP4): -# # every tag in the MP4 file (from what i can tell) is a list -# # this includes the track number tag, which is a list, containing a single tuple, containing two ints (track, total) -# # unless we account for this, tag_list will be set to [(1, 5)], and then converted to a string, resulting in -# # ['(1, 5)'], which (if not allow_list) will be returned as '(1, 5)', which is not exactly helpful. -# tag = vorbis_to_itunes[tag] -# if tag == 'trkn': -# # mut_song[tag] == [(1, 5)] -# # mut_song[tag][0] == (1, 5) -# tag_list = mut_song[tag][0] -# else: -# tag_list = mut_song[tag] -# -# else: -# if tag == "track": -# tag = "tracknumber" -# tag = tag.replace("_", "") -# tag_list = mut_song[tag] if isinstance(mut_song[tag], list) else [mut_song[tag]] -# -# # convert the list of strings/ID3 frames/ints/whatevers to strings -# tag_list = list(map(str, tag_list)) -# -# # sanitise everything -# if allow_sanitising: -# tag_list = [sanitise(tag) for tag in tag_list] -# -# if allow_list: -# return tag_list -# -# return tag_list[0] - def has_cover(mut_song: MutagenFile): if isinstance(mut_song, OggVorbis): return "metadata_block_picture" in mut_song and len(mut_song["metadata_block_picture"]) != 0