diff options
Diffstat (limited to 'player/lua/ytdl_hook.lua')
-rw-r--r-- | player/lua/ytdl_hook.lua | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index d59b3a4fd9..b947fdec86 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -7,13 +7,37 @@ local ytdl = { vercheck = nil, } -mp.add_hook("on_load", 10, function () - - local function exec(args) - local ret = utils.subprocess({args = args}) - return ret.status, ret.stdout +local function exec(args) + local ret = utils.subprocess({args = args}) + return ret.status, ret.stdout +end + +-- return if it was explicitly set on the command line +local function option_was_set(name) + return mp.get_property_bool("option-info/" .. name .. "/set-from-commandline", + false) +end + +-- youtube-dl may set special http headers for some sites (user-agent, cookies) +local function set_http_headers(http_headers) + if not http_headers then + return + end + local headers = {} + local useragent = http_headers["User-Agent"] + if useragent and not option_was_set("user-agent") then + mp.set_property("file-local-options/user-agent", useragent) + end + local cookies = http_headers["Cookie"] + if cookies then + headers[#headers + 1] = "Cookie: " .. cookies end + if #headers > 0 and not option_was_set("http-header-fields") then + mp.set_property_native("file-local-options/http-header-fields", headers) + end +end +mp.add_hook("on_load", 10, function () local url = mp.get_property("stream-open-filename") if (url:find("http://") == 1) or (url:find("https://") == 1) @@ -117,6 +141,10 @@ mp.add_hook("on_load", 10, function () msg.debug("EDL: " .. playlist) + -- can't change the http headers for each entry, so use the 1st + if json.entries[1] then + set_http_headers(json.entries[1].http_headers) + end mp.set_property("stream-open-filename", playlist) if not (json.title == nil) then @@ -168,6 +196,7 @@ mp.add_hook("on_load", 10, function () elseif not (json.url == nil) then -- normal video streamurl = json.url + set_http_headers(json.http_headers) else msg.error("No URL found in JSON data.") return |