From 813dfe19242bc7672470077cc37c373f92730e05 Mon Sep 17 00:00:00 2001 From: Christoph Heinrich Date: Sun, 10 Jul 2022 20:07:50 +0200 Subject: ytdl_hook: fix default track for single format Tracks are marked as default tracks based on what yt-dlp/youtube-dl returns in the field `requested_formats`. The problem is that this field only exists when there is more then one requested format. So `ytdl-format=bestvideo+bestaudio` would have that field, but `ytdl-format=bestaudio` would not, leading to no tracks being marked as default tracks. The requested formats can also be found under `requested_downloads`, which exists regardless of the number of requested formats. However when there is more then one requested format, `requested_downloads` doesn't contain those formats directly and instead has a field `requested_formats` that is identical to the other `requested_formats`. Therefore use `requested_downloads` as a fallback for when `requested_formats` doesn't exist. --- player/lua/ytdl_hook.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'player') diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index 41fe97bf33..04bb3c30b4 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -390,7 +390,7 @@ local function formats_to_edl(json, formats, use_all_formats) } local default_formats = {} - local requested_formats = json["requested_formats"] + local requested_formats = json["requested_formats"] or json["requested_downloads"] if use_all_formats and requested_formats then for _, track in ipairs(requested_formats) do local id = track["format_id"] @@ -525,7 +525,7 @@ local function add_single_video(json) local streamurl = "" local format_info = "" local max_bitrate = 0 - local requested_formats = json["requested_formats"] + local requested_formats = json["requested_formats"] or json["requested_downloads"] local all_formats = json["formats"] local has_requested_formats = requested_formats and #requested_formats > 0 local http_headers = has_requested_formats -- cgit v1.2.3