diff options
Diffstat (limited to 'player/lua/ytdl_hook.lua')
-rw-r--r-- | player/lua/ytdl_hook.lua | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index 3161da6194..7b4c9bfe66 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -27,14 +27,14 @@ end) local chapter_list = {} local playlist_cookies = {} -function Set (t) +local function Set (t) local set = {} for _, v in pairs(t) do set[v] = true end return set end -- ?: surrogate (keep in mind that there is no lazy evaluation) -function iif(cond, if_true, if_false) +local function iif(cond, if_true, if_false) if cond then return if_true end @@ -129,7 +129,7 @@ local function set_http_headers(http_headers) mp.set_property("file-local-options/user-agent", useragent) end local additional_fields = {"Cookie", "Referer", "X-Forwarded-For"} - for idx, item in pairs(additional_fields) do + for _, item in pairs(additional_fields) do local field_value = http_headers[item] if field_value then headers[#headers + 1] = item .. ": " .. field_value @@ -335,7 +335,7 @@ local function make_absolute_url(base_url, url) rest:gsub("([^/]+)", function(c) table.insert(segs, c) end) url:gsub("([^/]+)", function(c) table.insert(segs, c) end) local resolved_url = {} - for i, v in ipairs(segs) do + for _, v in ipairs(segs) do if v == ".." then table.remove(resolved_url) elseif v ~= "." then @@ -478,7 +478,7 @@ local function formats_to_edl(json, formats, use_all_formats) local streams = {} local tbr_only = true - for index, track in ipairs(formats) do + for _, track in ipairs(formats) do tbr_only = tbr_only and track["tbr"] and (not track["abr"]) and (not track["vbr"]) end @@ -492,8 +492,7 @@ local function formats_to_edl(json, formats, use_all_formats) -- Iterate in reverse to get best track first. for index = #formats, 1, -1 do local track = formats[index] - local edl_track = nil - edl_track = edl_track_joined(track.fragments, + local edl_track = edl_track_joined(track.fragments, track.protocol, json.is_live, track.fragment_base_url) if not edl_track and not url_is_safe(track.url) then @@ -686,8 +685,7 @@ local function add_single_video(json) if streamurl == "" and json.url then format_info = "youtube-dl (single)" - local edl_track = nil - edl_track = edl_track_joined(json.fragments, json.protocol, + local edl_track = edl_track_joined(json.fragments, json.protocol, json.is_live, json.fragment_base_url) if not edl_track and not url_is_safe(json.url) then @@ -768,8 +766,9 @@ local function add_single_video(json) msg.verbose("adding thumbnail") mp.commandv("video-add", thumb_info.url, "auto") thumb_height = 0 - elseif (thumb_preference ~= nil and (thumb_info.preference or -math.huge) > thumb_preference) or - (thumb_preference == nil and ((thumb_info.height or 0) > thumb_height)) then + elseif (thumb_preference ~= nil and + (thumb_info.preference or -math.huge) > thumb_preference) or + (thumb_preference == nil and (thumb_info.height or 0) > thumb_height) then thumb = thumb_info.url thumb_height = thumb_info.height or 0 thumb_preference = thumb_info.preference @@ -879,7 +878,7 @@ local function check_version(ytdl_path) end end -function run_ytdl_hook(url) +local function run_ytdl_hook(url) local start_time = os.clock() -- strip ytdl:// @@ -951,7 +950,8 @@ function run_ytdl_hook(url) for _, path in pairs(ytdl.paths_to_search) do -- search for youtube-dl in mpv's config dir - local exesuf = platform_is_windows() and not path:lower():match("%.exe$") and ".exe" or "" + local exesuf = platform_is_windows() and not path:lower():match("%.exe$") + and ".exe" or "" local ytdl_cmd = mp.find_config_file(path .. exesuf) if ytdl_cmd then msg.verbose("Found youtube-dl at: " .. ytdl_cmd) @@ -960,11 +960,13 @@ function run_ytdl_hook(url) result = exec(command) break else - msg.verbose("No youtube-dl found with path " .. path .. exesuf .. " in config directories") + msg.verbose("No youtube-dl found with path " .. path .. exesuf .. + " in config directories") command[1] = path result = exec(command) if result.error_string == "init" then - msg.verbose("youtube-dl with path " .. path .. " not found in PATH or not enough permissions") + msg.verbose("youtube-dl with path " .. path .. + " not found in PATH or not enough permissions") else msg.verbose("Found youtube-dl with path " .. path .. " in PATH") ytdl.path = path @@ -996,7 +998,7 @@ function run_ytdl_hook(url) msg.verbose("stderr:", result.stderr) -- trim our stderr to avoid spurious newlines - ytdl_err = result.stderr:gsub("^%s*(.-)%s*$", "%1") + local ytdl_err = result.stderr:gsub("^%s*(.-)%s*$", "%1") msg.error(ytdl_err) local err = "youtube-dl failed: " if result.error_string and result.error_string == "init" then @@ -1075,7 +1077,7 @@ function run_ytdl_hook(url) json.entries[entry_wsubs].duration ~= nil then for j, req in pairs(json.entries[entry_wsubs].requested_subtitles) do local subfile = "edl://" - for i, entry in pairs(json.entries) do + for _, entry in pairs(json.entries) do if entry.requested_subtitles ~= nil and entry.requested_subtitles[j] ~= nil and url_is_safe(entry.requested_subtitles[j].url) then @@ -1096,7 +1098,7 @@ function run_ytdl_hook(url) else local playlist_index = parse_yt_playlist(url, json) local playlist = {"#EXTM3U"} - for i, entry in pairs(json.entries) do + for _, entry in pairs(json.entries) do local site = entry.url local title = entry.title |