mirror of
https://github.com/mpv-player/mpv
synced 2025-01-10 08:59:45 +00:00
ytdl_hook: enable default selection via --ytdl-format with all_formats
In all_formats mode, we've ignored what --ytdl-format did so far, since we've converted the full format list, instead of just the formats selected by youtube-dl. But we can easily restore --ytdl-format behavior: just mark the selected tracks as default tracks.
This commit is contained in:
parent
a77780e6be
commit
4c32468241
@ -841,13 +841,16 @@ Program Behavior
|
|||||||
If 'yes' will attempt to add all formats found reported by youtube-dl
|
If 'yes' will attempt to add all formats found reported by youtube-dl
|
||||||
(default: no). Each format is added as a separate track. In addition,
|
(default: no). Each format is added as a separate track. In addition,
|
||||||
they are delay-loaded, and actually opened only when a track is selected
|
they are delay-loaded, and actually opened only when a track is selected
|
||||||
(this should keep load times as low as without this option). It also
|
(this should keep load times as low as without this option).
|
||||||
adds average bitrate metadata, if available, which means
|
|
||||||
``--hls-bitrate`` will decide which track to select. (HLS used to be the
|
It adds average bitrate metadata, if available, which means you can use
|
||||||
|
``--hls-bitrate`` to decide which track to select. (HLS used to be the
|
||||||
only format whose alternative quality streams were exposed in a similar
|
only format whose alternative quality streams were exposed in a similar
|
||||||
way, thus the option name.)
|
way, thus the option name.)
|
||||||
|
|
||||||
The ``--ytdl-format`` option is essentially ignored.
|
Tracks which represent formats that were selected by youtube-dl as
|
||||||
|
default will have the default flag set. This means mpv should generally
|
||||||
|
still select formats chosen with ``--ytdl-format`` by default.
|
||||||
|
|
||||||
Although this mechanism makes it possible to switch streams at runtime,
|
Although this mechanism makes it possible to switch streams at runtime,
|
||||||
it's not suitable for this purpose for various technical reasons. (It's
|
it's not suitable for this purpose for various technical reasons. (It's
|
||||||
|
@ -25,6 +25,14 @@ function Set (t)
|
|||||||
return set
|
return set
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- ?: surrogate (keep in mind that there is no lazy evaluation)
|
||||||
|
function iif(cond, if_true, if_false)
|
||||||
|
if cond then
|
||||||
|
return if_true
|
||||||
|
end
|
||||||
|
return if_false
|
||||||
|
end
|
||||||
|
|
||||||
local safe_protos = Set {
|
local safe_protos = Set {
|
||||||
"http", "https", "ftp", "ftps",
|
"http", "https", "ftp", "ftps",
|
||||||
"rtmp", "rtmps", "rtmpe", "rtmpt", "rtmpts", "rtmpte",
|
"rtmp", "rtmps", "rtmpe", "rtmpt", "rtmpts", "rtmpte",
|
||||||
@ -340,6 +348,17 @@ local function formats_to_edl(json, formats, use_all_formats)
|
|||||||
muxed_needed = false,
|
muxed_needed = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local default_formats = {}
|
||||||
|
local requested_formats = json["requested_formats"]
|
||||||
|
if use_all_formats and requested_formats then
|
||||||
|
for _, track in ipairs(requested_formats) do
|
||||||
|
local id = track["format_id"]
|
||||||
|
if id then
|
||||||
|
default_formats[id] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local duration = as_integer(json["duration"])
|
local duration = as_integer(json["duration"])
|
||||||
local single_url = nil
|
local single_url = nil
|
||||||
local streams = {}
|
local streams = {}
|
||||||
@ -414,8 +433,13 @@ local function formats_to_edl(json, formats, use_all_formats)
|
|||||||
end
|
end
|
||||||
title = title .. "muxed-" .. index
|
title = title .. "muxed-" .. index
|
||||||
end
|
end
|
||||||
|
local flags = {}
|
||||||
|
if default_formats[track["format_id"]] then
|
||||||
|
flags[#flags + 1] = "default"
|
||||||
|
end
|
||||||
hdr[#hdr + 1] = "!track_meta,title=" ..
|
hdr[#hdr + 1] = "!track_meta,title=" ..
|
||||||
edl_escape(title) .. ",byterate=" .. byterate
|
edl_escape(title) .. ",byterate=" .. byterate ..
|
||||||
|
iif(#flags > 0, ",flags=" .. table.concat(flags, "+"), "")
|
||||||
end
|
end
|
||||||
|
|
||||||
if duration > 0 then
|
if duration > 0 then
|
||||||
|
Loading…
Reference in New Issue
Block a user