mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-12 15:50:01 -08:00
feat(cli): switch to using AnimeProvider obj
This commit is contained in:
@@ -3,6 +3,7 @@ import signal
|
||||
import click
|
||||
|
||||
from .. import __version__
|
||||
from ..libs.anime_provider import anime_sources
|
||||
from ..libs.anime_provider.allanime.constants import SERVERS_AVAILABLE
|
||||
from ..Utility.data import anilist_sort_normalizer
|
||||
from .commands.anilist import anilist
|
||||
@@ -40,6 +41,12 @@ signal.signal(signal.SIGINT, handle_exit)
|
||||
short_help="Stream Anime",
|
||||
)
|
||||
@click.version_option(__version__, "--version")
|
||||
@click.option(
|
||||
"-p",
|
||||
"--provider",
|
||||
type=click.Choice(list(anime_sources.keys()), case_sensitive=False),
|
||||
help="Provider of your choice",
|
||||
)
|
||||
@click.option(
|
||||
"-s",
|
||||
"--server",
|
||||
@@ -96,6 +103,7 @@ signal.signal(signal.SIGINT, handle_exit)
|
||||
@click.pass_context
|
||||
def run_cli(
|
||||
ctx: click.Context,
|
||||
provider,
|
||||
server,
|
||||
format,
|
||||
continue_,
|
||||
@@ -111,6 +119,9 @@ def run_cli(
|
||||
no_preview,
|
||||
):
|
||||
ctx.obj = Config()
|
||||
if provider:
|
||||
ctx.obj.provider = provider
|
||||
ctx.obj.load_config()
|
||||
if server:
|
||||
ctx.obj.server = server
|
||||
if format:
|
||||
|
||||
@@ -2,7 +2,6 @@ import click
|
||||
from rich import print
|
||||
from thefuzz import fuzz
|
||||
|
||||
from ...libs.anime_provider.allanime.api import anime_provider
|
||||
from ...libs.anime_provider.types import Anime
|
||||
from ...libs.fzf import fzf
|
||||
from ...Utility.downloader.downloader import downloader
|
||||
@@ -26,11 +25,17 @@ from ..utils.utils import clear
|
||||
)
|
||||
@click.pass_obj
|
||||
def download(config: Config, anime_title, episode_range):
|
||||
anime_provider = config.anime_provider
|
||||
translation_type = config.translation_type
|
||||
download_dir = config.downloads_dir
|
||||
search_results = anime_provider.search_for_anime(
|
||||
anime_title, translation_type=translation_type
|
||||
)
|
||||
if not search_results:
|
||||
print("Search results failed")
|
||||
input("Enter to retry")
|
||||
download(config, anime_title, episode_range)
|
||||
return
|
||||
search_results = search_results["results"]
|
||||
search_results_ = {
|
||||
search_result["title"]: search_result for search_result in search_results
|
||||
|
||||
@@ -3,7 +3,6 @@ from rich import print
|
||||
from thefuzz import fuzz
|
||||
|
||||
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
|
||||
@@ -23,9 +22,15 @@ from ..utils.utils import clear
|
||||
@click.argument("anime_title", required=True, type=str)
|
||||
@click.pass_obj
|
||||
def search(config: Config, anime_title: str, episode_range: str):
|
||||
anime_provider = config.anime_provider
|
||||
search_results = anime_provider.search_for_anime(
|
||||
anime_title, config.translation_type
|
||||
)
|
||||
if not search_results:
|
||||
print("Search results not found")
|
||||
input("Enter to retry")
|
||||
search(config, anime_title, episode_range)
|
||||
return
|
||||
search_results = search_results["results"]
|
||||
if not search_results:
|
||||
print("Anime not found :cry:")
|
||||
|
||||
@@ -4,6 +4,7 @@ from configparser import ConfigParser
|
||||
from rich import print
|
||||
|
||||
from .. import USER_CONFIG_PATH, USER_VIDEOS_DIR
|
||||
from ..AnimeProvider import AnimeProvider
|
||||
from ..Utility.user_data_helper import user_data_helper
|
||||
|
||||
|
||||
@@ -29,6 +30,7 @@ class Config(object):
|
||||
"use_fzf": "False",
|
||||
"preview": "False",
|
||||
"format": "best[height<=1080]/bestvideo[height<=1080]+bestaudio/best",
|
||||
"provider": "allanime",
|
||||
}
|
||||
)
|
||||
self.configparser.add_section("stream")
|
||||
@@ -41,6 +43,7 @@ class Config(object):
|
||||
|
||||
# --- set defaults ---
|
||||
self.downloads_dir = self.get_downloads_dir()
|
||||
self.provider = self.get_provider()
|
||||
self.use_fzf = self.get_use_fzf()
|
||||
self.preview = self.get_preview()
|
||||
self.translation_type = self.get_translation_type()
|
||||
@@ -57,6 +60,8 @@ class Config(object):
|
||||
self.watch_history: dict = user_data_helper.user_data.get("watch_history", {})
|
||||
self.anime_list: list = user_data_helper.user_data.get("animelist", [])
|
||||
|
||||
self.anime_provider = AnimeProvider(self.provider)
|
||||
|
||||
def update_watch_history(self, anime_id: int, episode: str | None):
|
||||
self.watch_history.update({str(anime_id): episode})
|
||||
user_data_helper.update_watch_history(self.watch_history)
|
||||
@@ -74,6 +79,9 @@ class Config(object):
|
||||
print("Succesfully added :smile:")
|
||||
input("Enter to continue...")
|
||||
|
||||
def get_provider(self):
|
||||
return self.configparser.get("general", "provider")
|
||||
|
||||
def get_downloads_dir(self):
|
||||
return self.configparser.get("general", "downloads_dir")
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ from rich.prompt import Prompt
|
||||
from ... import USER_CONFIG_PATH
|
||||
from ...libs.anilist.anilist import AniList
|
||||
from ...libs.anilist.anilist_data_schema import AnilistBaseMediaDataSchema
|
||||
from ...libs.anime_provider.allanime.api import anime_provider
|
||||
from ...libs.anime_provider.types import Anime, SearchResult, Server
|
||||
from ...libs.fzf import fzf
|
||||
from ...Utility.data import anime_normalizer
|
||||
@@ -152,6 +151,7 @@ def fetch_streams(config: Config, anilist_config: QueryDict):
|
||||
anime_id: int = anilist_config.anime_id
|
||||
anime: Anime = anilist_config.anime
|
||||
translation_type = config.translation_type
|
||||
anime_provider = config.anime_provider
|
||||
|
||||
# get streams for episode from provider
|
||||
episode_streams = anime_provider.get_episode_streams(
|
||||
@@ -266,6 +266,7 @@ def fetch_episode(config: Config, anilist_config: QueryDict):
|
||||
|
||||
def fetch_anime_episode(config, anilist_config: QueryDict):
|
||||
selected_anime: SearchResult = anilist_config._anime
|
||||
anime_provider = config.anime_provider
|
||||
anilist_config.anime = anime_provider.get_anime(selected_anime["id"])
|
||||
if not anilist_config.anime:
|
||||
|
||||
@@ -287,6 +288,7 @@ def provide_anime(config: Config, anilist_config: QueryDict):
|
||||
selected_anime_title = anilist_config.selected_anime_title
|
||||
|
||||
anime_data: AnilistBaseMediaDataSchema = anilist_config.selected_anime_anilist
|
||||
anime_provider = config.anime_provider
|
||||
|
||||
# search and get the requested title from provider
|
||||
search_results = anime_provider.search_for_anime(
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
from .allanime.api import AllAnimeAPI
|
||||
|
||||
anime_sources = {"allanime": AllAnimeAPI}
|
||||
|
||||
|
||||
class Anime_Provider:
|
||||
def search_for_anime(self):
|
||||
pass
|
||||
|
||||
def get_anime(self):
|
||||
pass
|
||||
|
||||
def get_episode_streams(self):
|
||||
pass
|
||||
|
||||
@@ -217,10 +217,8 @@ class AllAnimeAPI:
|
||||
return []
|
||||
|
||||
|
||||
anime_provider = AllAnimeAPI()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
anime_provider = AllAnimeAPI()
|
||||
# lets see if it works :)
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
Reference in New Issue
Block a user