From 4d9aa0ddbb4502fae18bc0772a6713ae0a061314 Mon Sep 17 00:00:00 2001 From: Phoenixthrush UwU Date: Fri, 19 Apr 2024 11:38:27 +0200 Subject: [PATCH] fix linting --- main.py | 57 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/main.py b/main.py index 57e46bb..d8b3fb3 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ """ -AniWorld Downloader is a command-line tool designed to download content from aniworld.to. -It offers various features, including fetching single episodes, downloading entire seasons, +AniWorld Downloader is a command-line tool designed to download content from aniworld.to. +It offers various features, including fetching single episodes, downloading entire seasons, organizing downloads into structured directories, and supporting multiple operating systems. """ @@ -20,7 +20,8 @@ from py7zr import SevenZipFile from yt_dlp import YoutubeDL, DownloadError -class Options: # pylint: disable=too-few-public-methods, too-many-arguments + +class Options: # pylint: disable=too-few-public-methods, too-many-arguments """ Handles system arguments for options. """ @@ -65,10 +66,11 @@ def from_args(cls): link_only=args.link_only ) -class ContentProvider: # pylint: disable=too-few-public-methods + +class ContentProvider: # pylint: disable=too-few-public-methods """ Represents a content provider for streaming anime episodes. - + This class encapsulates information about a content provider, including its name, language, and link. @@ -82,7 +84,8 @@ def __init__(self, provider, language, link): self.language = language self.link = f"https://aniworld.to{link}" -class Series: # pylint: disable=too-few-public-methods, too-many-arguments + +class Series: # pylint: disable=too-few-public-methods, too-many-arguments """ Represents a series of anime episodes. @@ -96,7 +99,8 @@ def __init__(self, episodes, series_name, filename, hls_link, episode_title): self.hls_link = hls_link self.episode_title = episode_title -def get_content_providers(url_with_episode): # pylint: disable=too-many-locals # :D + +def get_content_providers(url_with_episode): # pylint: disable=too-many-locals # :D """ Fetches content providers for a given URL with episodes. @@ -148,11 +152,11 @@ def get_content_providers(url_with_episode): # pylint: disable=too-many-locals # provider = ContentProvider(provider=hoster, language=language, link=redirect_link) providers_list.append(provider) series = Series( - series_name = series_title, - filename = None, - hls_link = None, - episodes = None, - episode_title = soup.find("span", class_="episodeGermanTitle").text + series_name=series_title, + filename=None, + hls_link=None, + episodes=None, + episode_title=soup.find("span", class_="episodeGermanTitle").text ) else: print("No watchEpisode link found within generateInlinePlayer div.") @@ -163,6 +167,7 @@ def get_content_providers(url_with_episode): # pylint: disable=too-many-locals # return providers_list, series + def get_stream_url(url, series): """ Retrieves the HLS stream URL and related information from the provided URL. @@ -203,6 +208,7 @@ def get_stream_url(url, series): return series + def play_hls_link(hls_link): """ Plays the HLS link using the MPV media player. @@ -242,6 +248,7 @@ def play_hls_link(hls_link): print("Could not determine OS.") shutdown() + def download_with_ytdlp(url, series): """ Downloads the video using youtube-dl. @@ -273,6 +280,7 @@ def download_with_ytdlp(url, series): except DownloadError as e: print("Could not download using yt-dlp:", e) + def calculate_checksum(file_path, checksum): """ Calculates the checksum of a file and compares it with the provided checksum. @@ -298,6 +306,7 @@ def calculate_checksum(file_path, checksum): return True + def extract_zip(archive_path, extract_path): """ Extracts a gzip-compressed tar archive or a 7z archive to a specified directory. @@ -322,7 +331,8 @@ def extract_zip(archive_path, extract_path): with SevenZipFile(archive_path, mode='r') as z: z.extractall(path=extract_path) -def get_mpv(download = True): + +def get_mpv(download=True): """ Downloads and extracts the MPV media player if it's not already downloaded. @@ -354,8 +364,9 @@ def get_mpv(download = True): if not path.exists("mpv/mpv.app"): try: makedirs("mpv", exist_ok=True) - urlretrieve("https://laboratory.stolendata.net/~djinn/mpv_osx/mpv-0.37.0.tar.gz" - ,"mpv/mpv-0.37.0.tar.gz") + urlretrieve("https://laboratory.stolendata.net/~djinn/" + "mpv_osx/mpv-0.37.0.tar.gz", + "mpv/mpv-0.37.0.tar.gz") except FileNotFoundError as e: print("Could not find the directory: ", e) except URLError as e: @@ -364,7 +375,8 @@ def get_mpv(download = True): # mpv-0.37.0.tar.gz # sha256:73a44595dc36b3aab6bd92e4426ede3478c5dd2d5cf8ca446b110ce520f12e47 if not calculate_checksum("mpv/mpv-0.37.0.tar.gz", - "73a44595dc36b3aab6bd92e4426ede3478c5dd2d5cf8ca446b110ce520f12e47"): + "73a44595dc36b3aab6bd92e4426ede3478c5dd2d5cf8ca" + "446b110ce520f12e47"): shutdown() extract_zip("mpv/mpv-0.37.0.tar.gz", "mpv/") elif os == "Windows": @@ -372,8 +384,8 @@ def get_mpv(download = True): try: makedirs("mpv", exist_ok=True) urlretrieve("https://sourceforge.net/projects/mpv-player-windows/" - "files/latest/download" - ,"mpv/mpv-x86_64-v3-latest-git.7z") + "files/latest/download", + "mpv/mpv-x86_64-v3-latest-git.7z") except FileNotFoundError as e: print("Could not find the directory: ", e) except URLError as e: @@ -383,6 +395,7 @@ def get_mpv(download = True): print("Could not determine OS.") shutdown() + def search_series(): """ Searches for a series based on user input, selects a series from the results, @@ -416,6 +429,7 @@ def search_series(): inner_episode_links, inner_html_content = list_episodes(selected_link) return inner_episode_links, inner_html_content + def parse_results(json_data): """ Parses the JSON data to extract series names and links. @@ -430,6 +444,7 @@ def parse_results(json_data): links = [entry['link'] for entry in json_data] return list(zip(names_with_years, links)) + def select_series(results): """ Selects a series from the search results. @@ -449,6 +464,7 @@ def select_series(results): return select_series_from_input(selection, results) return results[0][1] + def select_series_from_input(selection, results): """ Handles user input to select a series. @@ -469,6 +485,7 @@ def select_series_from_input(selection, results): print("Invalid input. Please enter a number.") return select_series(results) + def list_episodes(selected_link): """ Lists available episodes for the selected series. @@ -491,6 +508,7 @@ def list_episodes(selected_link): return get_episode_links(selected_link), inner_html_content + def get_last_episode(soup): """ Extracts the last episode number from the HTML content. @@ -507,6 +525,7 @@ def get_last_episode(soup): return max(map(int, findall(r'\d+', content))) return 0 + def get_episode_links(selected_link): """ Constructs episode links based on user input. @@ -540,6 +559,7 @@ def get_episode_links(selected_link): return episode_links + def select_language(languages): """ Allows the user to select a language from a list of available languages. @@ -568,6 +588,7 @@ def select_language(languages): else: print("Invalid input. Please enter a number.") + if __name__ == "__main__": options = Options.from_args()