fix(anilist_interface): trailer not loading

This commit is contained in:
Benex254
2024-08-05 09:47:04 +03:00
parent c5f6d8389d
commit 02fee255ad
2 changed files with 15 additions and 8 deletions

View File

@@ -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),

View File

@@ -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