diff --git a/DOCS/interface-changes/ytdl_hook-include.txt b/DOCS/interface-changes/ytdl_hook-include.txt new file mode 100644 index 0000000000..8affad81e0 --- /dev/null +++ b/DOCS/interface-changes/ytdl_hook-include.txt @@ -0,0 +1 @@ +add `ytdl_hook-include` script-opt diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 55a0674773..887e81458b 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -919,6 +919,13 @@ Program Behavior See more lua patterns here: https://www.lua.org/manual/5.1/manual.html#5.4.1 + ``include=`` 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, diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index ff12e9e2f2..10ccc15dbe 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -4,6 +4,7 @@ local options = require 'mp.options' local o = { exclude = "", + include = "^%w+%.youtube%.com/|^youtube%.com/|^youtu%.be/|^%w+%.twitch%.tv/|^twitch%.tv/", try_ytdl_first = false, use_manifests = false, all_formats = false, @@ -283,6 +284,26 @@ local function extract_chapters(data, video_length) return ret end +local function is_whitelisted(url) + url = url:match("https?://(.+)") + + if url == nil then + return false + end + + url = url:lower() + + for match in o.include:gmatch('%|?([^|]+)') do + if url:find(match) then + msg.verbose("URL matches included substring " .. match .. + ". Trying ytdl first.") + return true + end + end + + return false +end + local function is_blacklisted(url) if o.exclude == "" then return false end if #ytdl.blacklisted == 0 then @@ -1177,7 +1198,7 @@ end local function on_load_hook(load_fail) local url = mp.get_property("stream-open-filename", "") local force = url:find("^ytdl://") - local early = force or o.try_ytdl_first + local early = force or o.try_ytdl_first or is_whitelisted(url) if early == load_fail then return end