From 02fee255ada298110a716807de46cb184ce74a1e Mon Sep 17 00:00:00 2001 From: Benex254 Date: Mon, 5 Aug 2024 09:47:04 +0300 Subject: [PATCH] fix(anilist_interface): trailer not loading --- fastanime/cli/interfaces/anilist_interfaces.py | 11 +++++++---- fastanime/cli/utils/mpv.py | 12 ++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fastanime/cli/interfaces/anilist_interfaces.py b/fastanime/cli/interfaces/anilist_interfaces.py index 92eec26..578db2f 100644 --- a/fastanime/cli/interfaces/anilist_interfaces.py +++ b/fastanime/cli/interfaces/anilist_interfaces.py @@ -149,8 +149,8 @@ def player_controls(config: Config, anilist_config: QueryDict): options = { "🔂 Replay": _replay, - "⏭ Next Episode": _next_episode, - "⏮ Previous Episode": _previous_episode, + "⏭ Next Episode": _next_episode, + "⏮ Previous Episode": _previous_episode, "🗃️ Episodes": _episodes, "📀 Change Quality": _change_quality, "🎧 Change Translation Type": _change_translation_type, @@ -419,7 +419,10 @@ def anilist_options(config, anilist_config: QueryDict): if trailer := selected_anime.get("trailer"): trailer_url = "https://youtube.com/watch?v=" + trailer["id"] print("[bold magenta]Watching Trailer of:[/]", selected_anime_title) - mpv(trailer_url, selected_anime_title, f"--ytdl-format={config.format}") + mpv( + trailer_url, + ytdl_format=config.format, + ) anilist_options(config, anilist_config) else: print("no trailer available :confused:") @@ -648,7 +651,7 @@ def anilist(config: Config, anilist_config: QueryDict): options = { "🔥 Trending": AniList.get_trending, "📺 Watching": lambda x="Watching": handle_animelist(x), - "⏸ Paused": lambda x="Paused": handle_animelist(x), + "⏸ Paused": lambda x="Paused": handle_animelist(x), "🚮 Dropped": lambda x="Dropped": handle_animelist(x), "📑 Planned": lambda x="Planned": handle_animelist(x), "✅ Completed": lambda x="Completed": handle_animelist(x), diff --git a/fastanime/cli/utils/mpv.py b/fastanime/cli/utils/mpv.py index 810ac01..7723b31 100644 --- a/fastanime/cli/utils/mpv.py +++ b/fastanime/cli/utils/mpv.py @@ -67,13 +67,11 @@ def stream_video(url, mpv_args): return last_time, total_time -def mpv(link: str, title: Optional[str] = "anime", start_time: str = "0", *custom_args): +def mpv(link: str, title: Optional[str] = "", start_time: str = "0", ytdl_format=""): # Determine if mpv is available MPV = shutil.which("mpv") # If title is None, set a default value - if title is None: - title = "anime" # Regex to check if the link is a YouTube URL youtube_regex = r"(https?://)?(www\.)?(youtube|youtu|youtube-nocookie)\.(com|be)/.+" @@ -116,7 +114,13 @@ def mpv(link: str, title: Optional[str] = "anime", start_time: str = "0", *custo return "0" else: # General mpv command with custom arguments - mpv_args = [*custom_args, f"--title={title}", f"--start={start_time}"] + mpv_args = [] + if start_time != "0": + mpv_args.append(f"--start={start_time}") + if title: + mpv_args.append(f"--title={title}") + if ytdl_format: + mpv_args.append(f"--ytdl-format={ytdl_format}") stop_time, total_time = stream_video(link, mpv_args) return stop_time, total_time