add error handling for is_valid_ytdlp_url

This commit is contained in:
ksyasuda@umich.edu 2023-08-02 16:14:31 -07:00
parent e2e4d2ddd5
commit b8ef352bf5

View File

@ -71,9 +71,10 @@ end
local function is_valid_ytdlp_url(url)
local command = 'yt-dlp --simulate \'' .. url .. '\' >/dev/null 2>&1'
mp.msg.log("info", "Checking if URL is valid: " .. command)
local handle = io.popen(command .. "; echo $?")
if not handle then return false end
local result = handle:read("*a")
if not result then return false end
handle:close()
return result:gsub("%s+$", "") == "0"
end