diff --git a/youtube-quality.lua b/youtube-quality.lua index b587f37..6fd98bc 100644 --- a/youtube-quality.lua +++ b/youtube-quality.lua @@ -112,7 +112,7 @@ function show_menu() draw_menu() end function choose_prefix(i) - if i == selected and i == active then return opts.selected_and_active + if i == selected and i == active then return opts.selected_and_active elseif i == selected then return opts.selected_and_inactive end if i ~= selected and i == active then return opts.unselected_and_active @@ -157,11 +157,26 @@ function show_menu() mp.add_forced_key_binding(opts.toggle_menu_binding, "escape", destroy) draw_menu() - return + return +end + +-- Function to check if a command is executable +function isExecutable(command) + local f = io.popen("which " .. command) + local path = f:read("*a") + f:close() + return string.len(path) > 0 +end + +-- Check if youtube-dl or yt-dlp is in PATH +if isExecutable("youtube-dl") then + yt_tool = "youtube-dl" +elseif isExecutable("yt-dlp") then + yt_tool = "yt-dlp" end local ytdl = { - path = "youtube-dl", + path = yt_tool, searched = false, blacklisted = {} } @@ -186,7 +201,7 @@ function download_formats() url = string.gsub(url, "ytdl://", "") -- Strip possible ytdl:// prefix. -- don't fetch the format list if we already have it - if format_cache[url] ~= nil then + if format_cache[url] ~= nil then local res = format_cache[url] return res, table_size(res) end @@ -240,7 +255,7 @@ end -- register script message to show menu -mp.register_script_message("toggle-quality-menu", +mp.register_script_message("toggle-quality-menu", function() if destroyer ~= nil then destroyer()