Compare commits

..

No commits in common. "b46116e976ecc7ff2a32e45cfa467fbef77bd98e" and "d41d85b0e3e9ba748878a6d387787e81bde7521b" have entirely different histories.

2 changed files with 30 additions and 34 deletions

View File

@ -15,5 +15,4 @@ cursor_icon=🠺
font_size=24 font_size=24
font_name=JetBrains Mono font_name=JetBrains Mono
download_quality=720p download_quality=720p
download_directory=~/videos/YouTube download_directory=~/Videos/YouTube
downloader=curl

View File

@ -43,8 +43,7 @@ local options = {
font_size = 14, font_size = 14,
font_name = "JetBrains Mono", font_name = "JetBrains Mono",
download_quality = "720p", download_quality = "720p",
download_directory = "~/videos/YouTube", download_directory = "~/Videos/YouTube"
downloader = "curl"
} }
local colors = { local colors = {
@ -219,15 +218,28 @@ function YouTubeQueue.update_current_index()
for i, v in ipairs(video_queue) do for i, v in ipairs(video_queue) do
if v.video_url == current_url then if v.video_url == current_url then
index = i index = i
selected_index = index
current_video = YouTubeQueue.get_video_at(index)
return return
end end
end end
-- if not found, reset the index -- if not found, reset the index
index = 0 index = 0
selected_index = index
current_video = YouTubeQueue.get_video_at(index)
end end
-- Function to be called when the end-file event is triggered
function YouTubeQueue.on_end_file(event)
if event.reason == "eof" then -- The file ended normally
YouTubeQueue.update_current_index()
end
end
-- Function to be called when the track-changed event is triggered
function YouTubeQueue.on_track_changed() YouTubeQueue.update_current_index() end
-- Function to be called when the playback-restart event is triggered
function YouTubeQueue.on_playback_restart() YouTubeQueue.update_current_index() end
function YouTubeQueue.print_queue(duration) function YouTubeQueue.print_queue(duration)
local current_index = index local current_index = index
if not duration then duration = 3 end if not duration then duration = 3 end
@ -410,33 +422,30 @@ local function download_current_video()
local v = current_video local v = current_video
local q = o.download_quality:sub(1, -2) local q = o.download_quality:sub(1, -2)
local command = 'yt-dlp -f \'bestvideo[height<=' .. q .. local command = 'yt-dlp -f \'bestvideo[height<=' .. q ..
']+bestaudio/best[height<=' .. q .. ']\' -o "' .. ']+bestaudio/best[height<=' .. q ..
']\' --newline -o "' ..
expanduser(o.download_directory) .. '/' .. expanduser(o.download_directory) .. '/' ..
v.channel_name .. '/' .. v.video_name .. v.channel_name .. '/' .. v.video_name ..
'.%(ext)s" ' .. '--downloader ' .. o.downloader .. '.%(ext)s" ' .. v.video_url
' ' .. v.video_url
-- Run the download command -- Run the download command
local handle = io.popen(command) local handle = io.popen(command)
if not handle then if not handle then
print_osd_message("Error starting download.", MSG_DURATION, mp.osd_message("Error starting download.")
style.error)
return return
end end
print_osd_message("Starting download for " .. v.video_name, MSG_DURATION)
local result = handle:read("*a") local result = handle:read("*a")
handle:close()
if not result then if not result then
print_osd_message("Error starting download.", MSG_DURATION, mp.osd_message("Error starting download.")
style.error)
return return
end end
handle:close()
mp.msg.log("info", "RESULTS: " .. result)
if result then if result then
print_osd_message("Finished downloading " .. v.video_name, print_osd_message("Downloading " .. v.video_name, MSG_DURATION)
MSG_DURATION)
else else
print_osd_message("Error downloading " .. v.video_name, print_osd_message("Error starting download for " .. v.video_name,
MSG_DURATION, style.error) MSG_DURATION, style.error)
end end
else else
@ -444,19 +453,6 @@ local function download_current_video()
end end
end end
-- Function to be called when the end-file event is triggered
local function on_end_file(event)
if event.reason == "eof" then -- The file ended normally
YouTubeQueue.update_current_index()
end
end
-- Function to be called when the track-changed event is triggered
local function on_track_changed() YouTubeQueue.update_current_index() end
-- Function to be called when the playback-restart event is triggered
local function on_playback_restart() YouTubeQueue.update_current_index() end
-- }}} -- }}}
-- KEY BINDINGS {{{ -- KEY BINDINGS {{{
@ -481,7 +477,8 @@ mp.add_key_binding(options.open_channel_in_browser, "open_channel_in_browser",
mp.add_key_binding(options.download_current_video, "download_current_video", mp.add_key_binding(options.download_current_video, "download_current_video",
download_current_video) download_current_video)
mp.register_event("end-file", on_end_file) -- Listen for the file-loaded event
mp.register_event("track-changed", on_track_changed) mp.register_event("end-file", YouTubeQueue.on_end_file)
mp.register_event("playback-restart", on_playback_restart) mp.register_event("track-changed", YouTubeQueue.on_track_changed)
mp.register_event("playback-restart", YouTubeQueue.on_playback_restart)
-- }}} -- }}}