put everything in main(), zero mypy issues
This commit is contained in:
parent
a6409c9c35
commit
7334f67e45
1 changed files with 178 additions and 170 deletions
10
bcao.py
10
bcao.py
|
@ -34,6 +34,7 @@ from PIL import Image
|
|||
fully_supported: List[str] = ["ogg", "flac", "mp3", "m4a", "wav"]
|
||||
MutagenFile = Union[MP3, FLAC, OggVorbis, mutagen.FileType]
|
||||
MutagenTags = Union[mutagen.id3.ID3Tags, mutagen.mp4.Tags, mutagen.oggvorbis.OggVCommentDict]
|
||||
args: argparse.Namespace
|
||||
|
||||
class SongInfo:
|
||||
tag_lookup: Dict[str, Dict[str, str]] = {
|
||||
|
@ -61,6 +62,7 @@ class SongInfo:
|
|||
if fallbacks is None:
|
||||
die("Couldn't determine fallback tags!")
|
||||
return # needed for mypy
|
||||
|
||||
# set default values for the tags, in case the file is missing any (or all!) of them
|
||||
self.tags: Dict[str, str] = {
|
||||
"track": fallbacks.group("track"),
|
||||
|
@ -210,6 +212,8 @@ def sanitise(in_str: str) -> str:
|
|||
return re.sub(r"[?\\/:|*\"<>]", "_", in_str)
|
||||
return in_str
|
||||
|
||||
|
||||
def main():
|
||||
# noinspection PyTypeChecker
|
||||
parser = argparse.ArgumentParser(usage='%(prog)s zip [options]',
|
||||
formatter_class=argparse.RawTextHelpFormatter,
|
||||
|
@ -230,6 +234,7 @@ parser.add_argument('-u', '--unsanitised', dest='sanitise', action='store_false'
|
|||
parser.add_argument('-t', '--threshold', dest='threshold', nargs=1, default=300,
|
||||
help="Maximum acceptable file size for cover art, in kilobytes.\nDefault: %(default)s")
|
||||
|
||||
global args
|
||||
args = parser.parse_args()
|
||||
# convert args.threshold to bytes
|
||||
args.threshold *= 1024
|
||||
|
@ -266,7 +271,7 @@ if song_format not in fully_supported:
|
|||
|
||||
if cover is None:
|
||||
die("Unable to find cover image!")
|
||||
# return # needed for mypy
|
||||
return # needed for mypy
|
||||
|
||||
if args.process_cover != 'n':
|
||||
log("Resizing album art to embed in songs...")
|
||||
|
@ -410,3 +415,6 @@ shutil.move(str(Path(tmp, cover)), str(Path(destination, cover)))
|
|||
|
||||
tmp_dir.cleanup()
|
||||
log("Done!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue