summaryrefslogtreecommitdiffstats
path: root/player/lua/ytdl_hook.lua
diff options
context:
space:
mode:
authorRicardo Constantino <wiiaboo@gmail.com>2017-07-08 14:43:37 +0100
committerRicardo Constantino <wiiaboo@gmail.com>2017-07-11 14:18:29 +0100
commit042e98f4c9afb5cb41c727a6cf61a1e447710d9b (patch)
treefe138a33b01a592595de963a696784f45849a7c9 /player/lua/ytdl_hook.lua
parentb1165ce3a22194d1f929c9af7ea65d19460fd941 (diff)
downloadmpv-042e98f4c9afb5cb41c727a6cf61a1e447710d9b.tar.bz2
mpv-042e98f4c9afb5cb41c727a6cf61a1e447710d9b.tar.xz
ytdl_hook: add option to exclude URLs from being parsed
This is more of a niche usecase than --ytdl-format and --ytdl-raw-options, so a simple script option should be enough. Either create lua-settings/ytdl_hook.conf with 'exclude=example.com,sub.example.com' option or "--script-opts=ytdl_hook-exclude=example.com,sub.example.com"
Diffstat (limited to 'player/lua/ytdl_hook.lua')
-rw-r--r--player/lua/ytdl_hook.lua34
1 files changed, 30 insertions, 4 deletions
diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua
index 11a252af00..b01bf68f30 100644
--- a/player/lua/ytdl_hook.lua
+++ b/player/lua/ytdl_hook.lua
@@ -1,9 +1,15 @@
local utils = require 'mp.utils'
local msg = require 'mp.msg'
+local options = require 'mp.options'
+
+local o = {
+ exclude = ""
+}
local ytdl = {
path = "youtube-dl",
- searched = false
+ searched = false,
+ blacklisted = {}
}
local chapter_list = {}
@@ -93,6 +99,27 @@ local function extract_chapters(data, video_length)
return ret
end
+local function is_blacklisted(url)
+ if o.blacklist == "" then return false end
+ if #ytdl.blacklisted == 0 then
+ local joined = o.blacklist
+ while joined:match(',?[^,]+') do
+ local _, e, domain = joined:find(',?([^,]+)')
+ table.insert(ytdl.blacklisted, domain)
+ joined = joined:sub(e+1)
+ end
+ end
+ if #ytdl.blacklisted > 0 then
+ url = url:match('https?://(.+)')
+ for _, exclude in ipairs(ytdl.blacklisted) do
+ if url:match(exclude) then
+ return true
+ end
+ end
+ end
+ return false
+end
+
local function edl_track_joined(fragments, protocol, is_live)
if not (type(fragments) == "table") or not fragments[1] then
msg.debug("No fragments to join into EDL")
@@ -244,9 +271,8 @@ end
mp.add_hook("on_load", 10, function ()
local url = mp.get_property("stream-open-filename")
local start_time = os.clock()
-
- if (url:find("http://") == 1) or (url:find("https://") == 1)
- or (url:find("ytdl://") == 1) then
+ if (url:find("ytdl://") == 1) or
+ ((url:find("https?://") == 1) and not is_blacklisted(url)) then
-- check for youtube-dl in mpv's config dir
if not (ytdl.searched) then