From 1ef53f094b4362afdfd54770a59b6d3da3551ee5 Mon Sep 17 00:00:00 2001 From: Christoph Heinrich Date: Sun, 10 Jul 2022 23:59:30 +0200 Subject: ytdl_hook: consistant behavior for single format One would expect that e.g. `--script-opts=ytdl_hook-all_formats=no --ytdl-format=bestaudio` and `--script-opts=ytdl_hook-all_formats=yes --ytdl-format=bestaudio` to play the exact same tracks without manual intervention. This already worked when two formats were requested. For a single format with `all_formats=yes` it would also play a track that was not requested when available. This was inconsistant with the behavior of `all_formats=no` (default), which would not play a second track when only a single one was requested. This combined with #10395 now plays the exact same tracks with `all_formats=yes` as without, even when only one format is requested. --- player/lua/ytdl_hook.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'player/lua') diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index 04bb3c30b4..5457efbe58 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -410,6 +410,8 @@ local function formats_to_edl(json, formats, use_all_formats) (not track["abr"]) and (not track["vbr"]) end + local has_requested_video = false + local has_requested_audio = false for index, track in ipairs(formats) do local edl_track = nil edl_track = edl_track_joined(track.fragments, @@ -419,12 +421,16 @@ local function formats_to_edl(json, formats, use_all_formats) return nil end + local is_default = default_formats[track["format_id"]] local tracks = {} if track.vcodec and track.vcodec ~= "none" then tracks[#tracks + 1] = { media_type = "video", codec = map_codec_to_mpv(track.vcodec), } + if is_default then + has_requested_video = true + end end -- Tries to follow the strange logic that vcodec unset means it's -- an audio stream, even if acodec is sometimes unset. @@ -434,6 +440,9 @@ local function formats_to_edl(json, formats, use_all_formats) codec = map_codec_to_mpv(track.acodec) or ext_map[track.ext], } + if is_default then + has_requested_audio = true + end end if #tracks == 0 then return nil @@ -482,7 +491,7 @@ local function formats_to_edl(json, formats, use_all_formats) title = title .. "muxed-" .. index end local flags = {} - if default_formats[track["format_id"]] then + if is_default then flags[#flags + 1] = "default" end hdr[#hdr + 1] = "!track_meta,title=" .. @@ -518,6 +527,13 @@ local function formats_to_edl(json, formats, use_all_formats) return nil end + if has_requested_audio ~= has_requested_video then + local not_req_prop = has_requested_video and "aid" or "vid" + if mp.get_property(not_req_prop) == "auto" then + mp.set_property("file-local-options/" .. not_req_prop, "no") + end + end + return res end -- cgit v1.2.3