From 32685b66bd93370325993777a3d72edab6c31af0 Mon Sep 17 00:00:00 2001 From: "modula t. worm" Date: Wed, 20 May 2020 15:30:05 -0500 Subject: [PATCH] add --no_server option to just download one cover and exit --- bum/__main__.py | 8 +++++++- bum/song.py | 10 ++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bum/__main__.py b/bum/__main__.py index c6df72f..51c230d 100644 --- a/bum/__main__.py +++ b/bum/__main__.py @@ -43,6 +43,9 @@ def get_args(): help="Use a remote server instead of localhost.", default="localhost") + arg.add_argument("--no_server", action="store_true", + help="Don't run as a server; just download one cover and exit.") + arg.add_argument("--no_display", action="store_true", help="Only download album art, don't display.") @@ -70,10 +73,13 @@ def main(): client = song.init(args.port, args.server) while True: - song.get_art(args.cache_dir, args.size, args.default_cover, client) + got_cover = song.get_art(args.cache_dir, args.size, args.default_cover, client) if not args.no_display: display.launch(disp, args.cache_dir / "current.jpg") + if args.no_server: + exit(int(not got_cover)) + client.send_idle() if client.fetch_idle(["player"]): diff --git a/bum/song.py b/bum/song.py index 268fe42..789f2a9 100644 --- a/bum/song.py +++ b/bum/song.py @@ -30,10 +30,10 @@ def get_art(cache_dir, size, default_cover, client): print("album: Nothing currently playing.") if default_cover: shutil.copy(default_cover, cache_dir / "current.jpg") - return + return False util.bytes_to_file(util.default_album_art(), cache_dir / "current.jpg") - return + return False file_name = f"{song['artist']}_{song['album']}_{size}.jpg".replace("/", "") file_name = cache_dir / file_name @@ -41,6 +41,7 @@ def get_art(cache_dir, size, default_cover, client): if file_name.is_file(): shutil.copy(file_name, cache_dir / "current.jpg") print("album: Found cached art.") + return True else: print("album: Downloading album art...") @@ -56,3 +57,8 @@ def get_art(cache_dir, size, default_cover, client): util.bytes_to_file(album_art, cache_dir / "current.jpg") print(f"album: Swapped art to {song['artist']}, {song['album']}.") + + if album_art: + return True + else: + return False