Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add yt-dlp as video downloader #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions youtube-quality.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {}
}
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down