diff --git a/fastanime/cli/commands/anilist/utils.py b/fastanime/cli/commands/anilist/utils.py deleted file mode 100644 index 1bc414c..0000000 --- a/fastanime/cli/commands/anilist/utils.py +++ /dev/null @@ -1,25 +0,0 @@ -from ....libs.anilist.anilist_data_schema import ( - AnilistBaseMediaDataSchema, - AnilistDataSchema, -) -from ...utils.fzf import fzf - - -def get_search_result( - anilist_data: AnilistDataSchema, -) -> AnilistBaseMediaDataSchema | None: - choices = [] - data = anilist_data["data"]["Page"]["media"] - for choice in data: - choices.append(choice["title"]["romaji"]) - _selected_anime = fzf(choices) - if not _selected_anime: - return None - - def _get_result(x): - return x["title"]["romaji"] == _selected_anime - - selected_anime = list(filter(_get_result, data)) - if not selected_anime: - return None - return selected_anime[0] diff --git a/fastanime/cli/commands/search.py b/fastanime/cli/commands/search.py index 1ccac30..fb1cdfb 100644 --- a/fastanime/cli/commands/search.py +++ b/fastanime/cli/commands/search.py @@ -1,10 +1,49 @@ import click +from ...cli.config import Config +from ...libs.anime_provider.allanime.api import anime_provider +from ...libs.anime_provider.types import Anime +from ...libs.fzf import fzf +from ..utils.mpv import mpv -@click.command() + +@click.command( + help="This subcommand directly interacts with the provider to enable basic streaming and perhaps automation if required", + short_help="Directly stream anime with provider", +) +@click.argument("anime_title", required=True, type=str) @click.pass_obj def search( - config, - anime_title, + config: Config, + anime_title: str, ): - pass + search_results = anime_provider.search_for_anime( + anime_title, config.translation_type + ) + search_results = search_results["results"] + search_results_ = { + search_result["title"]: search_result for search_result in search_results + } + + search_result = fzf.run( + list(search_results_.keys()), "Please Select title: ", "FastAnime" + ) + + anime: Anime = anime_provider.get_anime(search_results_[search_result]["id"]) + + def stream_anime(): + episodes = anime["availableEpisodesDetail"][config.translation_type] + episode = fzf.run(episodes, "Select an episode: ", header="Episodes") + streams = anime_provider.get_episode_streams( + anime, episode, config.translation_type + ) + if not streams: + print("Failed to get streams") + return + links = [link["link"] for server in streams for link in server["links"]] + link = fzf.run(links, "Select stream", "Streams") + + mpv(link, search_result) + stream_anime() + + stream_anime()