From 33c518ed4c90e1913e78ee85d210996404fc8b4e Mon Sep 17 00:00:00 2001 From: Benex254 Date: Fri, 23 Aug 2024 17:18:36 +0300 Subject: [PATCH] chore: cleanup codebase --- fastanime/Utility/data.py | 2 +- fastanime/cli/__init__.py | 3 + fastanime/cli/commands/anilist/completed.py | 2 +- fastanime/cli/commands/anilist/dropped.py | 2 +- fastanime/cli/commands/anilist/favourites.py | 2 +- fastanime/cli/commands/anilist/paused.py | 2 +- fastanime/cli/commands/anilist/planning.py | 2 +- fastanime/cli/commands/anilist/popular.py | 2 +- .../cli/commands/anilist/random_anime.py | 2 +- fastanime/cli/commands/anilist/recent.py | 2 +- fastanime/cli/commands/anilist/rewatching.py | 2 +- fastanime/cli/commands/anilist/scores.py | 2 +- fastanime/cli/commands/anilist/search.py | 109 +++++++++--------- fastanime/cli/commands/anilist/trending.py | 2 +- fastanime/cli/commands/anilist/upcoming.py | 2 +- fastanime/cli/commands/anilist/watching.py | 2 +- .../cli/interfaces/anilist_interfaces.py | 22 ++-- fastanime/cli/utils/player.py | 2 - fastanime/cli/utils/tools.py | 2 +- 19 files changed, 86 insertions(+), 80 deletions(-) diff --git a/fastanime/Utility/data.py b/fastanime/Utility/data.py index 1ba07bd..693f49f 100644 --- a/fastanime/Utility/data.py +++ b/fastanime/Utility/data.py @@ -11,7 +11,7 @@ anime_normalizer_raw = { 'Hazurewaku no "Joutai Ijou Skill" de Saikyou ni Natta Ore ga Subete wo Juurin suru made': "Hazure Waku no [Joutai Ijou Skill] de Saikyou ni Natta Ore ga Subete wo Juurin Suru made", }, "aniwatch": {"My Star": "Oshi no Ko"}, - "animepahe": {}, + "animepahe": {"Azumanga Daiou The Animation": "Azumanga Daioh"}, } diff --git a/fastanime/cli/__init__.py b/fastanime/cli/__init__.py index 360bc79..42e0884 100644 --- a/fastanime/cli/__init__.py +++ b/fastanime/cli/__init__.py @@ -223,7 +223,10 @@ def run_cli( if sync_play: ctx.obj.sync_play = sync_play if provider: + import os + ctx.obj.provider = provider + os.environ["CURRENT_FASTANIME_PROVIDER"] = provider if server: ctx.obj.server = server if format: diff --git a/fastanime/cli/commands/anilist/completed.py b/fastanime/cli/commands/anilist/completed.py index 85df8ee..67b2c13 100644 --- a/fastanime/cli/commands/anilist/completed.py +++ b/fastanime/cli/commands/anilist/completed.py @@ -42,5 +42,5 @@ def completed(config: "Config", dump_json): from ...interfaces import anilist_interfaces fastanime_runtime_state = FastAnimeRuntimeState() - fastanime_runtime_state.current_anilist_data = anime_list[1] + fastanime_runtime_state.anilist_results_data = anime_list[1] anilist_interfaces.anilist_results_menu(config, fastanime_runtime_state) diff --git a/fastanime/cli/commands/anilist/dropped.py b/fastanime/cli/commands/anilist/dropped.py index da32cb7..812f324 100644 --- a/fastanime/cli/commands/anilist/dropped.py +++ b/fastanime/cli/commands/anilist/dropped.py @@ -42,5 +42,5 @@ def dropped(config: "Config", dump_json): from ...utils.tools import FastAnimeRuntimeState fastanime_runtime_state = FastAnimeRuntimeState() - fastanime_runtime_state.current_anilist_data = anime_list[1] + fastanime_runtime_state.anilist_results_data = anime_list[1] anilist_interfaces.anilist_results_menu(config, fastanime_runtime_state) diff --git a/fastanime/cli/commands/anilist/favourites.py b/fastanime/cli/commands/anilist/favourites.py index e893b6e..61ac291 100644 --- a/fastanime/cli/commands/anilist/favourites.py +++ b/fastanime/cli/commands/anilist/favourites.py @@ -26,7 +26,7 @@ def favourites(config, dump_json): from ...utils.tools import FastAnimeRuntimeState fastanime_runtime_state = FastAnimeRuntimeState() - fastanime_runtime_state.current_anilist_data = anime_data[1] + fastanime_runtime_state.anilist_results_data = anime_data[1] anilist_results_menu(config, fastanime_runtime_state) else: from sys import exit diff --git a/fastanime/cli/commands/anilist/paused.py b/fastanime/cli/commands/anilist/paused.py index 6637ef6..a5fdcad 100644 --- a/fastanime/cli/commands/anilist/paused.py +++ b/fastanime/cli/commands/anilist/paused.py @@ -42,5 +42,5 @@ def paused(config: "Config", dump_json): from ...utils.tools import FastAnimeRuntimeState anilist_config = FastAnimeRuntimeState() - anilist_config.data = anime_list[1] + anilist_config.anilist_results_data = anime_list[1] anilist_interfaces.anilist_results_menu(config, anilist_config) diff --git a/fastanime/cli/commands/anilist/planning.py b/fastanime/cli/commands/anilist/planning.py index 71beb33..85a6f2c 100644 --- a/fastanime/cli/commands/anilist/planning.py +++ b/fastanime/cli/commands/anilist/planning.py @@ -42,5 +42,5 @@ def planning(config: "Config", dump_json): from ...utils.tools import FastAnimeRuntimeState fastanime_runtime_state = FastAnimeRuntimeState() - fastanime_runtime_state.current_anilist_data = anime_list[1] + fastanime_runtime_state.anilist_results_data = anime_list[1] anilist_interfaces.anilist_results_menu(config, fastanime_runtime_state) diff --git a/fastanime/cli/commands/anilist/popular.py b/fastanime/cli/commands/anilist/popular.py index e8ce5de..6ea4993 100644 --- a/fastanime/cli/commands/anilist/popular.py +++ b/fastanime/cli/commands/anilist/popular.py @@ -25,7 +25,7 @@ def popular(config, dump_json): from ...utils.tools import FastAnimeRuntimeState fastanime_runtime_state = FastAnimeRuntimeState() - fastanime_runtime_state.current_anilist_data = anime_data[1] + fastanime_runtime_state.anilist_results_data = anime_data[1] anilist_results_menu(config, fastanime_runtime_state) else: from sys import exit diff --git a/fastanime/cli/commands/anilist/random_anime.py b/fastanime/cli/commands/anilist/random_anime.py index 5d44232..5fdd47f 100644 --- a/fastanime/cli/commands/anilist/random_anime.py +++ b/fastanime/cli/commands/anilist/random_anime.py @@ -33,7 +33,7 @@ def random_anime(config, dump_json): from ...utils.tools import FastAnimeRuntimeState fastanime_runtime_state = FastAnimeRuntimeState() - fastanime_runtime_state.current_anilist_data = anime_data[1] + fastanime_runtime_state.anilist_results_data = anime_data[1] anilist_results_menu(config, fastanime_runtime_state) else: exit(1) diff --git a/fastanime/cli/commands/anilist/recent.py b/fastanime/cli/commands/anilist/recent.py index 6153856..efbb3bd 100644 --- a/fastanime/cli/commands/anilist/recent.py +++ b/fastanime/cli/commands/anilist/recent.py @@ -26,7 +26,7 @@ def recent(config, dump_json): from ...utils.tools import FastAnimeRuntimeState fastanime_runtime_state = FastAnimeRuntimeState() - fastanime_runtime_state.current_anilist_data = anime_data[1] + fastanime_runtime_state.anilist_results_data = anime_data[1] anilist_results_menu(config, fastanime_runtime_state) else: from sys import exit diff --git a/fastanime/cli/commands/anilist/rewatching.py b/fastanime/cli/commands/anilist/rewatching.py index 8a865b7..9330b10 100644 --- a/fastanime/cli/commands/anilist/rewatching.py +++ b/fastanime/cli/commands/anilist/rewatching.py @@ -42,5 +42,5 @@ def rewatching(config: "Config", dump_json): from ...utils.tools import FastAnimeRuntimeState fastanime_runtime_state = FastAnimeRuntimeState() - fastanime_runtime_state.current_anilist_data = anime_list[1] + fastanime_runtime_state.anilist_results_data = anime_list[1] anilist_interfaces.anilist_results_menu(config, fastanime_runtime_state) diff --git a/fastanime/cli/commands/anilist/scores.py b/fastanime/cli/commands/anilist/scores.py index 43551f8..664413c 100644 --- a/fastanime/cli/commands/anilist/scores.py +++ b/fastanime/cli/commands/anilist/scores.py @@ -25,7 +25,7 @@ def scores(config, dump_json): from ...utils.tools import FastAnimeRuntimeState fastanime_runtime_state = FastAnimeRuntimeState() - fastanime_runtime_state.data = anime_data[1] + fastanime_runtime_state.anilist_results_data = anime_data[1] anilist_results_menu(config, fastanime_runtime_state) else: from sys import exit diff --git a/fastanime/cli/commands/anilist/search.py b/fastanime/cli/commands/anilist/search.py index 4f35f56..ece7718 100644 --- a/fastanime/cli/commands/anilist/search.py +++ b/fastanime/cli/commands/anilist/search.py @@ -4,7 +4,7 @@ from ...completion_functions import anime_titles_shell_complete tags_available = { "Cast": ["Polyamorous"], - "Cast / Main Cast": [ + "Cast Main Cast": [ "Anti-Hero", "Elderly Protagonist", "Ensemble Cast", @@ -18,7 +18,7 @@ tags_available = { "Primarily Male Cast", "Primarily Teen Cast", ], - "Cast / Traits": [ + "Cast Traits": [ "Age Regression", "Agender", "Aliens", @@ -94,7 +94,7 @@ tags_available = { ], "Demographic": ["Josei", "Kids", "Seinen", "Shoujo", "Shounen"], "Setting": ["Matriarchy"], - "Setting / Scene": [ + "Setting Scene": [ "Bar", "Boarding School", "Circus", @@ -117,7 +117,7 @@ tags_available = { "Urban", "Work", ], - "Setting / Time": [ + "Setting Time": [ "Achronological Order", "Anachronism", "Ancient China", @@ -125,7 +125,7 @@ tags_available = { "Historical", "Time Skip", ], - "Setting / Universe": [ + "Setting Universe": [ "Afterlife", "Alternate Universe", "Augmented Reality", @@ -152,7 +152,7 @@ tags_available = { "Rotoscoping", "Stop Motion", ], - "Theme / Action": [ + "Theme Action": [ "Archery", "Battle Royale", "Espionage", @@ -162,7 +162,7 @@ tags_available = { "Spearplay", "Swordplay", ], - "Theme / Arts": [ + "Theme Arts": [ "Acting", "Calligraphy", "Classic Literature", @@ -174,7 +174,7 @@ tags_available = { "Rakugo", "Writing", ], - "Theme / Arts-Music": [ + "Theme Arts-Music": [ "Band", "Classical Music", "Dancing", @@ -184,8 +184,8 @@ tags_available = { "Musical Theater", "Rock Music", ], - "Theme / Comedy": ["Parody", "Satire", "Slapstick", "Surreal Comedy"], - "Theme / Drama": [ + "Theme Comedy": ["Parody", "Satire", "Slapstick", "Surreal Comedy"], + "Theme Drama": [ "Bullying", "Class Struggle", "Coming of Age", @@ -198,7 +198,7 @@ tags_available = { "Suicide", "Tragedy", ], - "Theme / Fantasy": [ + "Theme Fantasy": [ "Alchemy", "Body Swapping", "Cultivation", @@ -216,8 +216,8 @@ tags_available = { "Wuxia", "Youkai", ], - "Theme / Game": ["Board Game", "E-Sports", "Video Games"], - "Theme / Game-Card & Board Game": [ + "Theme Game": ["Board Game", "E-Sports", "Video Games"], + "Theme Game-Card & Board Game": [ "Card Battle", "Go", "Karuta", @@ -225,7 +225,7 @@ tags_available = { "Poker", "Shogi", ], - "Theme / Game-Sport": [ + "Theme Game-Sport": [ "Acrobatics", "Airsoft", "American Football", @@ -258,7 +258,7 @@ tags_available = { "Volleyball", "Wrestling", ], - "Theme / Other": [ + "Theme Other": [ "Adoption", "Animals", "Astronomy", @@ -308,7 +308,7 @@ tags_available = { "Travel", "War", ], - "Theme / Other-Organisations": [ + "Theme Other-Organisations": [ "Assassins", "Criminal Organization", "Cult", @@ -320,7 +320,7 @@ tags_available = { "Triads", "Yakuza", ], - "Theme / Other-Vehicle": [ + "Theme Other-Vehicle": [ "Aviation", "Cars", "Mopeds", @@ -329,7 +329,7 @@ tags_available = { "Tanks", "Trains", ], - "Theme / Romance": [ + "Theme Romance": [ "Age Gap", "Bisexual", "Boys' Love", @@ -343,15 +343,15 @@ tags_available = { "Unrequited Love", "Yuri", ], - "Theme / Sci Fi": [ + "Theme Sci Fi": [ "Cyberpunk", "Space Opera", "Time Loop", "Time Manipulation", "Tokusatsu", ], - "Theme / Sci Fi-Mecha": ["Real Robot", "Super Robot"], - "Theme / Slice of Life": [ + "Theme Sci Fi-Mecha": ["Real Robot", "Super Robot"], + "Theme Slice of Life": [ "Agriculture", "Cute Boys Doing Cute Things", "Cute Girls Doing Cute Things", @@ -386,6 +386,7 @@ for tag_category, tags_in_category in tags_available.items(): "--status", "-S", help="The media status of the anime", + multiple=True, type=click.Choice( ["FINISHED", "RELEASING", "NOT_YET_RELEASED", "CANCELLED", "HIATUS"] ), @@ -486,38 +487,38 @@ for tag_category, tags_in_category in tags_available.items(): "-y", type=click.Choice( [ - "2024", - "2023", - "2022", - "2021", - "2020", - "2019", - "2018", - "2017", - "2016", - "2015", - "2014", - "2013", - "2012", - "2011", - "2010", - "2009", - "2008", - "2007", - "2006", - "2005", - "2004", - "2000", - "1990", - "1980", - "1970", - "1960", - "1950", - "1940", - "1930", - "1920", - "1910", "1900", + "1910", + "1920", + "1930", + "1940", + "1950", + "1960", + "1970", + "1980", + "1990", + "2000", + "2004", + "2005", + "2006", + "2007", + "2008", + "2009", + "2010", + "2011", + "2012", + "2013", + "2014", + "2015", + "2016", + "2017", + "2018", + "2019", + "2020", + "2021", + "2022", + "2023", + "2024", ] ), help="the year the media was released", @@ -531,7 +532,7 @@ def search( success, search_results = AniList.search( query=title, sort=sort, - status=status, + status_in=list(status), genre_in=list(genres), season=season, tag_in=list(tags), @@ -548,7 +549,7 @@ def search( from ...utils.tools import FastAnimeRuntimeState fastanime_runtime_state = FastAnimeRuntimeState() - fastanime_runtime_state.current_anilist_data = search_results + fastanime_runtime_state.anilist_results_data = search_results anilist_results_menu(config, fastanime_runtime_state) else: from sys import exit diff --git a/fastanime/cli/commands/anilist/trending.py b/fastanime/cli/commands/anilist/trending.py index 3130e1a..7aa2831 100644 --- a/fastanime/cli/commands/anilist/trending.py +++ b/fastanime/cli/commands/anilist/trending.py @@ -26,7 +26,7 @@ def trending(config, dump_json): from ...utils.tools import FastAnimeRuntimeState fastanime_runtime_state = FastAnimeRuntimeState() - fastanime_runtime_state.current_anilist_data = data + fastanime_runtime_state.anilist_results_data = data anilist_results_menu(config, fastanime_runtime_state) else: from sys import exit diff --git a/fastanime/cli/commands/anilist/upcoming.py b/fastanime/cli/commands/anilist/upcoming.py index 8ad62f6..263b064 100644 --- a/fastanime/cli/commands/anilist/upcoming.py +++ b/fastanime/cli/commands/anilist/upcoming.py @@ -25,7 +25,7 @@ def upcoming(config, dump_json): from ...utils.tools import FastAnimeRuntimeState fastanime_runtime_state = FastAnimeRuntimeState() - fastanime_runtime_state.current_anilist_data = data + fastanime_runtime_state.anilist_results_data = data anilist_results_menu(config, fastanime_runtime_state) else: from sys import exit diff --git a/fastanime/cli/commands/anilist/watching.py b/fastanime/cli/commands/anilist/watching.py index 5f03c10..677f9cc 100644 --- a/fastanime/cli/commands/anilist/watching.py +++ b/fastanime/cli/commands/anilist/watching.py @@ -42,5 +42,5 @@ def watching(config: "Config", dump_json): from ...utils.tools import FastAnimeRuntimeState fastanime_runtime_state = FastAnimeRuntimeState() - fastanime_runtime_state.current_anilist_data = anime_list[1] + fastanime_runtime_state.anilist_results_data = anime_list[1] anilist_interfaces.anilist_results_menu(config, fastanime_runtime_state) diff --git a/fastanime/cli/interfaces/anilist_interfaces.py b/fastanime/cli/interfaces/anilist_interfaces.py index 86ae824..7a098df 100644 --- a/fastanime/cli/interfaces/anilist_interfaces.py +++ b/fastanime/cli/interfaces/anilist_interfaces.py @@ -221,7 +221,7 @@ def media_player_controls( "Are you sure you wish to continue to the next episode, your progress for the current episodes will be erased?", default=True, ): - media_player_controls(config, fastanime_runtime_state) + media_actions_menu(config, fastanime_runtime_state) return # all checks have passed lets go to the next episode @@ -386,7 +386,7 @@ def provider_anime_episode_servers_menu( else: if not Rofi.confirm("Sth went wrong!!Enter to continue..."): exit(1) - provider_anime_episode_servers_menu(config, fastanime_runtime_state) + media_actions_menu(config, fastanime_runtime_state) return if config.server == "top": @@ -640,7 +640,9 @@ def provider_anime_episodes_menu( ) # prompt for episode number - total_episodes = provider_anime["availableEpisodesDetail"][translation_type] + total_episodes = sorted( + provider_anime["availableEpisodesDetail"][translation_type], key=float + ) current_episode_number = "" # auto select episode if continue from history otherwise prompt episode number @@ -731,7 +733,9 @@ def provider_anime_episodes_menu( provider_anime_episode_servers_menu(config, fastanime_runtime_state) -def fetch_anime_episode(config, fastanime_runtime_state: "FastAnimeRuntimeState"): +def fetch_anime_episode( + config: "Config", fastanime_runtime_state: "FastAnimeRuntimeState" +): selected_anime: "SearchResult" = ( fastanime_runtime_state.provider_anime_search_result ) @@ -739,7 +743,7 @@ def fetch_anime_episode(config, fastanime_runtime_state: "FastAnimeRuntimeState" with Progress() as progress: progress.add_task("Fetching Anime Info...", total=None) provider_anime = anime_provider.get_anime( - selected_anime["id"], fastanime_runtime_state.selected_anime_anilist + selected_anime["id"], ) if not provider_anime: print( @@ -750,7 +754,7 @@ def fetch_anime_episode(config, fastanime_runtime_state: "FastAnimeRuntimeState" else: if not Rofi.confirm("Sth went wrong!!Enter to continue..."): exit(1) - return fetch_anime_episode(config, fastanime_runtime_state) + return media_actions_menu(config, fastanime_runtime_state) fastanime_runtime_state.provider_anime = provider_anime provider_anime_episodes_menu(config, fastanime_runtime_state) @@ -795,7 +799,7 @@ def anime_provider_search_results_menu( else: if not Rofi.confirm("Sth went wrong!!Enter to continue..."): exit(1) - return anime_provider_search_results_menu(config, fastanime_runtime_state) + return media_actions_menu(config, fastanime_runtime_state) provider_search_results = { anime["title"]: anime for anime in provider_search_results["results"] @@ -1277,7 +1281,7 @@ def anilist_results_menu( config: [TODO:description] fastanime_runtime_state: [TODO:description] """ - search_results = fastanime_runtime_state.current_anilist_data["data"]["Page"][ + search_results = fastanime_runtime_state.anilist_results_data["data"]["Page"][ "media" ] @@ -1558,7 +1562,7 @@ def fastanime_main_menu( # anilist data is a (bool,data) # the bool indicated success if anilist_data[0]: - fastanime_runtime_state.current_anilist_data = anilist_data[1] + fastanime_runtime_state.anilist_results_data = anilist_data[1] anilist_results_menu(config, fastanime_runtime_state) else: diff --git a/fastanime/cli/utils/player.py b/fastanime/cli/utils/player.py index 853d8d0..3bb0fe8 100644 --- a/fastanime/cli/utils/player.py +++ b/fastanime/cli/utils/player.py @@ -111,7 +111,6 @@ class MpvPlayer(object): provider_anime, current_episode_number, translation_type, - fastanime_runtime_state.selected_anime_anilist, ) if not episode_streams: self.mpv_player.show_text("No streams were found") @@ -271,7 +270,6 @@ class MpvPlayer(object): mpv_player.show_text("Changing translation type...") anime = anime_provider.get_anime( fastanime_runtime_state.provider_anime_search_result["id"], - fastanime_runtime_state.selected_anime_anilist, ) if not anime: mpv_player.show_text("Failed to update translation type") diff --git a/fastanime/cli/utils/tools.py b/fastanime/cli/utils/tools.py index dcf01ac..11cd7e6 100644 --- a/fastanime/cli/utils/tools.py +++ b/fastanime/cli/utils/tools.py @@ -24,7 +24,7 @@ class FastAnimeRuntimeState(object): selected_anime_id_anilist: int selected_anime_title_anilist: str # current_anilist_data: "AnilistDataSchema | AnilistMediaList" - current_anilist_data: "Any" + anilist_results_data: "Any" def exit_app(exit_code=0, *args):