From 4f7da0b12521a32da710b5e5fcc3e3207c658fe1 Mon Sep 17 00:00:00 2001 From: arabcoders Date: Sat, 28 Jun 2025 19:12:29 +0300 Subject: [PATCH] support preset in yt-dlp/url/info endpoint. --- app/routes/api/yt_dlp.py | 37 ++++++++++++++++++++--------------- ui/components/Dropdown.vue | 2 +- ui/components/GetInfo.vue | 16 ++++++++++++++- ui/components/History.vue | 5 +++-- ui/components/NewDownload.vue | 25 ++++++++++++++++++++--- ui/components/Queue.vue | 26 ++++++++++++------------ ui/pages/index.vue | 35 ++++++++++++++++++++------------- 7 files changed, 97 insertions(+), 49 deletions(-) diff --git a/app/routes/api/yt_dlp.py b/app/routes/api/yt_dlp.py index a735b3a4..eb6bfeb5 100644 --- a/app/routes/api/yt_dlp.py +++ b/app/routes/api/yt_dlp.py @@ -77,13 +77,14 @@ async def convert(request: Request) -> Response: @route("GET", "api/yt-dlp/url/info/", "get_info") -async def get_info(request: Request, cache: Cache) -> Response: +async def get_info(request: Request, cache: Cache, config: Config) -> Response: """ Get the video info. Args: request (Request): The request object. cache (Cache): The cache instance. + config (Config): The config instance. Returns: Response: The response object @@ -91,25 +92,27 @@ async def get_info(request: Request, cache: Cache) -> Response: """ url: str | None = request.query.get("url") if not url: - return web.json_response(data={"error": "URL is required."}, status=web.HTTPBadRequest.status_code) + return web.json_response( + data={"status": False, "message": "URL is required.", "error": "URL is required."}, + status=web.HTTPBadRequest.status_code, + ) try: validate_url(url) except ValueError as e: - return web.json_response(data={"error": str(e)}, status=web.HTTPBadRequest.status_code) + return web.json_response( + data={"status": False, "message": str(e), "error": str(e)}, + status=web.HTTPBadRequest.status_code, + ) - config = Config.get_instance() - - preset = request.query.get("preset") - if preset: - exists: Preset | None = Presets.get_instance().get(preset) - if not exists: - return web.json_response( - data={"status": False, "message": f"Preset '{preset}' does not exist."}, - status=web.HTTPBadRequest.status_code, - ) - else: - preset: str = config.default_preset + preset: str = request.query.get("preset", config.default_preset) + exists: Preset | None = Presets.get_instance().get(preset) + if not exists: + msg: str = f"Preset '{preset}' does not exist." + return web.json_response( + data={"status": False, "message": msg, "error": msg}, + status=web.HTTPBadRequest.status_code, + ) try: key: str = cache.hash(f"{preset}:{url}") @@ -118,6 +121,7 @@ async def get_info(request: Request, cache: Cache) -> Response: data: Any | None = cache.get(key) data["_cached"] = { "status": "hit", + "preset": preset, "key": key, "ttl": data.get("_cached", {}).get("ttl", 300), "ttl_left": data.get("_cached", {}).get("expires", time.time() + 300) - time.time(), @@ -130,7 +134,7 @@ async def get_info(request: Request, cache: Cache) -> Response: if ytdlp_proxy := config.get_ytdlp_args().get("proxy", None): opts["proxy"] = ytdlp_proxy - ytdlp_opts = YTDLPOpts.get_instance().preset(name=preset).add(opts).get_all() + ytdlp_opts: dict = YTDLPOpts.get_instance().preset(name=preset).add(opts).get_all() data = extract_info( config=ytdlp_opts, @@ -153,6 +157,7 @@ async def get_info(request: Request, cache: Cache) -> Response: data["_cached"] = { "status": "miss", + "preset": preset, "key": key, "ttl": 300, "ttl_left": 300, diff --git a/ui/components/Dropdown.vue b/ui/components/Dropdown.vue index 9add139f..6702393e 100644 --- a/ui/components/Dropdown.vue +++ b/ui/components/Dropdown.vue @@ -1,7 +1,7 @@ - + yt-dlp Information @@ -357,7 +357,8 @@ - + yt-dlp Information diff --git a/ui/components/NewDownload.vue b/ui/components/NewDownload.vue index d330f1da..6cd0acdd 100644 --- a/ui/components/NewDownload.vue +++ b/ui/components/NewDownload.vue @@ -172,11 +172,29 @@ -
-
+
+ + + + yt-dlp Information + + + + Remove from archive + + + + + + Reset local settings + + +
+
+
-
+
diff --git a/ui/components/Queue.vue b/ui/components/Queue.vue index 25f86c0b..1e4c3684 100644 --- a/ui/components/Queue.vue +++ b/ui/components/Queue.vue @@ -120,18 +120,19 @@ Cancel Item - + @@ -227,10 +228,11 @@ Play video - + - + yt-dlp Information diff --git a/ui/pages/index.vue b/ui/pages/index.vue index a2c6af3c..b1b8c27b 100644 --- a/ui/pages/index.vue +++ b/ui/pages/index.vue @@ -60,14 +60,16 @@
- - + - - + @@ -83,8 +85,11 @@ const bg_opacity = useStorage('random_bg_opacity', 0.85) const display_style = useStorage('display_style', 'cards') const show_thumbnail = useStorage('show_thumbnail', true) -const get_info = ref('') -const get_info_use_url = ref(false) +const info_view = ref({ + url: '', + preset: '', + useUrl: false, +}) as Ref<{ url: string, preset: string, useUrl: boolean }> const item_form = ref({}) const query = ref() const toggleFilter = ref(false) @@ -126,16 +131,18 @@ const pauseDownload = () => { } const close_info = () => { - get_info.value = '' - get_info_use_url.value = false + info_view.value.url = '' + info_view.value.preset = '' + info_view.value.useUrl = false } -const view_info = (url: string, useUrl: boolean = false) => { - get_info.value = url - get_info_use_url.value = useUrl +const view_info = (url: string, useUrl: boolean = false, preset: string = '') => { + info_view.value.url = url + info_view.value.useUrl = useUrl + info_view.value.preset = preset } -watch(get_info, v => { +watch(() => info_view.value.url, v => { if (!bg_enable.value) { return }