diff options
author | Christoph Heinrich <christoph.heinrich@student.tugraz.at> | 2022-07-18 05:21:20 +0200 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2022-08-17 20:04:00 +0000 |
commit | 08dd30fde839d36b9df68ae20c959f880857d8bc (patch) | |
tree | 901a5f05ade272c494a02013a8acdc8ba79968f9 /player/lua | |
parent | 52e7269ea633b7ac3d83d7b5cba9b15c5fbcbef9 (diff) | |
download | mpv-08dd30fde839d36b9df68ae20c959f880857d8bc.tar.bz2 mpv-08dd30fde839d36b9df68ae20c959f880857d8bc.tar.xz |
ytdl_hook: improve track detection
Every format that was not detected as a video format was added to the
audio tracks. This resulted in e.g. YouTube storyboards from ending up
in the list of audio tracks.
Now formats that are already known to be neither video formats nor audio
formats, will also not end up in any track list.
Formats where it is unknown if they are video or audio get added to
tracks if `force_all_formats` is used, otherwise only
formats that are known to contain video or audio become video or audio
tracks respectively.
https://github.com/yt-dlp/yt-dlp/issues/4373#issuecomment-1186637357
Diffstat (limited to 'player/lua')
-rw-r--r-- | player/lua/ytdl_hook.lua | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index 5457efbe58..d950779f01 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -423,7 +423,9 @@ local function formats_to_edl(json, formats, use_all_formats) local is_default = default_formats[track["format_id"]] local tracks = {} - if track.vcodec and track.vcodec ~= "none" then + -- "none" means it is not a video + -- nil means it is unknown + if (o.force_all_formats or track.vcodec) and track.vcodec ~= "none" then tracks[#tracks + 1] = { media_type = "video", codec = map_codec_to_mpv(track.vcodec), @@ -432,9 +434,7 @@ local function formats_to_edl(json, formats, use_all_formats) 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. - if (#tracks == 0) or (track.acodec and track.acodec ~= "none") then + if (o.force_all_formats or track.acodec) and track.acodec ~= "none" then tracks[#tracks + 1] = { media_type = "audio", codec = map_codec_to_mpv(track.acodec) or @@ -444,13 +444,10 @@ local function formats_to_edl(json, formats, use_all_formats) has_requested_audio = true end end - if #tracks == 0 then - return nil - end local url = edl_track or track.url local hdr = {"!new_stream", "!no_clip", "!no_chapters"} - local skip = false + local skip = #tracks == 0 local params = "" if use_all_formats then @@ -504,12 +501,14 @@ local function formats_to_edl(json, formats, use_all_formats) end end - hdr[#hdr + 1] = edl_escape(url) .. params + if not skip then + hdr[#hdr + 1] = edl_escape(url) .. params - streams[#streams + 1] = table.concat(hdr, ";") - -- In case there is only 1 of these streams. - -- Note: assumes it has no important EDL headers - single_url = url + streams[#streams + 1] = table.concat(hdr, ";") + -- In case there is only 1 of these streams. + -- Note: assumes it has no important EDL headers + single_url = url + end end -- Merge all tracks into a single virtual file, but avoid EDL if it's |