feat: add yt-dlp format option

This commit is contained in:
Benex254
2024-08-05 09:47:03 +03:00
parent 2d8b966a1a
commit 1474df04e7
5 changed files with 22 additions and 3 deletions

View File

@@ -49,7 +49,7 @@ class YtDLPDownloader:
self._thread.start()
# Function to download the file
def _download_file(self, url: str, download_dir, title, silent):
def _download_file(self, url: str, download_dir, title, silent, vid_format="best"):
anime_title = sanitize_filename(title[0])
episode_title = sanitize_filename(title[1])
ydl_opts = {
@@ -59,6 +59,7 @@ class YtDLPDownloader:
], # Progress hook
"silent": silent,
"verbose": False,
"format": vid_format,
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:

View File

@@ -46,6 +46,12 @@ signal.signal(signal.SIGINT, handle_exit)
type=click.Choice(SERVERS_AVAILABLE, case_sensitive=False),
help="Server of choice",
)
@click.option(
"-f",
"--format",
type=str,
help="yt-dlp format to use",
)
@click.option(
"-c/-no-c",
"--continue/--no-continue",
@@ -91,6 +97,7 @@ signal.signal(signal.SIGINT, handle_exit)
def run_cli(
ctx: click.Context,
server,
format,
continue_,
translation_type,
quality,
@@ -106,6 +113,8 @@ def run_cli(
ctx.obj = Config()
if server:
ctx.obj.server = server
if format:
ctx.obj.format = format
if ctx.get_parameter_source("continue_") == click.core.ParameterSource.COMMANDLINE:
ctx.obj.continue_from_history = continue_
if quality:

View File

@@ -80,7 +80,11 @@ def download(config: Config, anime_title, episode_range):
]
link = max(links, key=lambda x: x[0])[1]
downloader._download_file(
link, download_dir, (anime["title"], streams[0]["episode_title"]), True
link,
download_dir,
(anime["title"], streams[0]["episode_title"]),
True,
config.format,
)
except Exception as e:
print(e)

View File

@@ -28,6 +28,7 @@ class Config(object):
"preferred_language": "english",
"use_fzf": "False",
"preview": "False",
"format": "bestvideo[height<=1080]+bestaudio/best",
}
)
self.configparser.add_section("stream")
@@ -49,6 +50,7 @@ class Config(object):
self.auto_select = self.get_auto_select()
self.quality = self.get_quality()
self.server = self.get_server()
self.format = self.get_format()
self.preferred_language = self.get_preferred_language()
# ---- setup user data ------
@@ -105,6 +107,9 @@ class Config(object):
def get_server(self):
return self.configparser.get("stream", "server")
def get_format(self):
return self.configparser.get("stream", "format")
def update_config(self, section: str, key: str, value: str):
self.configparser.set(section, key, value)
with open(USER_CONFIG_PATH, "w") as config:

View File

@@ -384,7 +384,7 @@ 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)
mpv(trailer_url, selected_anime_title, f"--ytdl-format={config.format}")
anilist_options(config, anilist_config)
else:
print("no trailer available :confused:")