0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

ytdl: Don't override user-set format in no-video mode

This commit is contained in:
ChrisK2 2015-09-30 22:28:01 +02:00
parent 739452361f
commit 1b7e8ff6c5

View File

@ -12,7 +12,7 @@ local function exec(args)
return ret.status, ret.stdout, ret return ret.status, ret.stdout, ret
end end
-- return if it was explicitly set on the command line -- return true if it was explicitly set on the command line
local function option_was_set(name) local function option_was_set(name)
return mp.get_property_bool("option-info/" .. name .. "/set-from-commandline", return mp.get_property_bool("option-info/" .. name .. "/set-from-commandline",
false) false)
@ -51,6 +51,11 @@ local function append_rtmp_prop(props, name, value)
return props..name.."=\""..value.."\"" return props..name.."=\""..value.."\""
end end
local function edl_escape(url)
return "%" .. string.len(url) .. "%" .. url
end
mp.add_hook("on_load", 10, function () mp.add_hook("on_load", 10, function ()
local url = mp.get_property("stream-open-filename") local url = mp.get_property("stream-open-filename")
@ -101,8 +106,11 @@ mp.add_hook("on_load", 10, function ()
"--sub-format", "ass/srt/best", "--no-playlist" "--sub-format", "ass/srt/best", "--no-playlist"
} }
-- Checks if video option is "no", change options accordingly -- Checks if video option is "no", change format accordingly,
if (mp.get_property("options/vid") == "no") then -- but only if user didn't explicitly set one
if (mp.get_property("options/vid") == "no")
and not option_was_set("ytdl-format") then
format = "bestaudio/best" format = "bestaudio/best"
msg.verbose("Video disabled. Only using audio") msg.verbose("Video disabled. Only using audio")
end end
@ -162,10 +170,7 @@ mp.add_hook("on_load", 10, function ()
local playlist = "edl://" local playlist = "edl://"
for i, entry in pairs(json.entries) do for i, entry in pairs(json.entries) do
playlist = playlist .. edl_escape(entry.url) .. ";"
local urllength = string.len(entry.url)
playlist = playlist .. "%" .. urllength .. "%" .. entry.url .. ";"
end end
msg.debug("EDL: " .. playlist) msg.debug("EDL: " .. playlist)
@ -206,14 +211,21 @@ mp.add_hook("on_load", 10, function ()
-- DASH? -- DASH?
if not (json["requested_formats"] == nil) then if not (json["requested_formats"] == nil) then
msg.info("Using DASH, expect inaccurate duration.")
if not (json.duration == nil) then
msg.info("Actual duration: " .. mp.format_time(json.duration))
end
-- video url -- video url
streamurl = json["requested_formats"][1].url streamurl = json["requested_formats"][1].url
-- fake duration
--if (true) and not (json.duration == nil) then
-- streamurl = "edl://" .. edl_escape(streamurl)
-- .. ",0," .. json.duration .. ";"
-- msg.info("Faking duration, ignore the following warning.")
--elseif not (json.duration == nil) then
msg.info("Using DASH, expect inaccurate duration.")
msg.info("Actual duration: " .. mp.format_time(json.duration))
--end
-- audio url -- audio url
mp.set_property("file-local-options/audio-file", mp.set_property("file-local-options/audio-file",
json["requested_formats"][2].url) json["requested_formats"][2].url)