From 6887c3ef89cb052a36a93851f1b8956aafb1426b Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sun, 17 Dec 2023 00:59:54 +0100 Subject: [PATCH] Format using black --- akibabot/main.py | 30 +++++++++++++++++++++++------- akibabot/xmpp.py | 9 ++++++--- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/akibabot/main.py b/akibabot/main.py index 8ed6d51..7dd2a5b 100644 --- a/akibabot/main.py +++ b/akibabot/main.py @@ -12,6 +12,7 @@ import akibapass_downloader.episode from akibabot.xmpp import send_notification + @dataclass class Show: # List of episode numbers that are locally available. @@ -26,23 +27,29 @@ class Show: # The base URL of the show. url: str + def build_show_dir_name(name: str, year: int) -> str: """Build the Jellyfin-compatible directory name of the show.""" return f"{name} ({year})" -def get_episode_numbers(show_name: str, show_year: int, storage_path: Path) -> list[int]: + +def get_episode_numbers( + show_name: str, show_year: int, storage_path: Path +) -> list[int]: """Computes the episode numbers that are locally available. @show_name: The name of the show @show_year: The release year of the show. - @storage_path: Path to where the show directories are. + @storage_path: Path to where the show directories are. """ episodes_path = storage_path / build_show_dir_name(show_name, show_year) if not episodes_path.exists(): return [] return [ - int(item.split(".")[0].split(" ")[1]) for item in os.listdir(episodes_path) if (episodes_path / item).is_file() + int(item.split(".")[0].split(" ")[1]) + for item in os.listdir(episodes_path) + if (episodes_path / item).is_file() ] @@ -114,20 +121,29 @@ def main(): logging.debug("Processing %s", show.name) episodes_path = storage_path / build_show_dir_name(show.name, show.year) if not episodes_path.exists(): - logging.info("Episodes directory of %s does not exist. Creating...", show.name) + logging.info( + "Episodes directory of %s does not exist. Creating...", show.name + ) episodes_path.mkdir(parents=True) episodes_remote = akibapass_downloader.episode.list_episodes( show.url, ) - episodes_to_download = set([episode.episode_nr for episode in episodes_remote]) - set(show.local_episodes) + episodes_to_download = set( + [episode.episode_nr for episode in episodes_remote] + ) - set(show.local_episodes) for episode in episodes_remote: if episode.episode_nr in episodes_to_download: logging.info(f"Downloading {episode.name} ({episode.episode_nr})...") - downloads = episode.get_downloads(cookies=cookies, filter_quality=akibapass_downloader.episode.Quality.UHD_1440P) + downloads = episode.get_downloads( + cookies=cookies, + filter_quality=akibapass_downloader.episode.Quality.UHD_1440P, + ) if not downloads: - logging.warning("Failed to find UHD quality for episode %d", episode.episode_nr) + logging.warning( + "Failed to find UHD quality for episode %d", episode.episode_nr + ) continue download = downloads[0] diff --git a/akibabot/xmpp.py b/akibabot/xmpp.py index d262c62..8e1700c 100644 --- a/akibabot/xmpp.py +++ b/akibabot/xmpp.py @@ -1,8 +1,12 @@ import aioxmpp -async def send_notification(jid: str, password: str, to: str, show_name: str, episode: int): + +async def send_notification( + jid: str, password: str, to: str, show_name: str, episode: int +): """Sends a notification of a new show download to @to using the account @jid:@password. - @show_name is the name of show. @episode is the number of the episode that was just downloaded.""" + @show_name is the name of show. @episode is the number of the episode that was just downloaded. + """ client = aioxmpp.PresenceManagedClient( aioxmpp.JID.fromstr(jid), aioxmpp.make_security_layer(password), @@ -18,4 +22,3 @@ async def send_notification(jid: str, password: str, to: str, show_name: str, ep show_name, ) await stream.send(msg) -