mirror of
https://github.com/ksyasuda/mpv-youtube-queue.git
synced 2024-11-22 03:19:54 -08:00
Compare commits
No commits in common. "b46116e976ecc7ff2a32e45cfa467fbef77bd98e" and "d41d85b0e3e9ba748878a6d387787e81bde7521b" have entirely different histories.
b46116e976
...
d41d85b0e3
@ -15,5 +15,4 @@ cursor_icon=🠺
|
||||
font_size=24
|
||||
font_name=JetBrains Mono
|
||||
download_quality=720p
|
||||
download_directory=~/videos/YouTube
|
||||
downloader=curl
|
||||
download_directory=~/Videos/YouTube
|
||||
|
@ -43,8 +43,7 @@ local options = {
|
||||
font_size = 14,
|
||||
font_name = "JetBrains Mono",
|
||||
download_quality = "720p",
|
||||
download_directory = "~/videos/YouTube",
|
||||
downloader = "curl"
|
||||
download_directory = "~/Videos/YouTube"
|
||||
}
|
||||
|
||||
local colors = {
|
||||
@ -219,15 +218,28 @@ function YouTubeQueue.update_current_index()
|
||||
for i, v in ipairs(video_queue) do
|
||||
if v.video_url == current_url then
|
||||
index = i
|
||||
selected_index = index
|
||||
current_video = YouTubeQueue.get_video_at(index)
|
||||
return
|
||||
end
|
||||
end
|
||||
-- if not found, reset the index
|
||||
index = 0
|
||||
selected_index = index
|
||||
current_video = YouTubeQueue.get_video_at(index)
|
||||
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)
|
||||
local current_index = index
|
||||
if not duration then duration = 3 end
|
||||
@ -410,33 +422,30 @@ local function download_current_video()
|
||||
local v = current_video
|
||||
local q = o.download_quality:sub(1, -2)
|
||||
local command = 'yt-dlp -f \'bestvideo[height<=' .. q ..
|
||||
']+bestaudio/best[height<=' .. q .. ']\' -o "' ..
|
||||
']+bestaudio/best[height<=' .. q ..
|
||||
']\' --newline -o "' ..
|
||||
expanduser(o.download_directory) .. '/' ..
|
||||
v.channel_name .. '/' .. v.video_name ..
|
||||
'.%(ext)s" ' .. '--downloader ' .. o.downloader ..
|
||||
' ' .. v.video_url
|
||||
'.%(ext)s" ' .. v.video_url
|
||||
|
||||
-- Run the download command
|
||||
local handle = io.popen(command)
|
||||
if not handle then
|
||||
print_osd_message("Error starting download.", MSG_DURATION,
|
||||
style.error)
|
||||
mp.osd_message("Error starting download.")
|
||||
return
|
||||
end
|
||||
print_osd_message("Starting download for " .. v.video_name, MSG_DURATION)
|
||||
local result = handle:read("*a")
|
||||
handle:close()
|
||||
if not result then
|
||||
print_osd_message("Error starting download.", MSG_DURATION,
|
||||
style.error)
|
||||
mp.osd_message("Error starting download.")
|
||||
return
|
||||
end
|
||||
handle:close()
|
||||
|
||||
mp.msg.log("info", "RESULTS: " .. result)
|
||||
if result then
|
||||
print_osd_message("Finished downloading " .. v.video_name,
|
||||
MSG_DURATION)
|
||||
print_osd_message("Downloading " .. v.video_name, MSG_DURATION)
|
||||
else
|
||||
print_osd_message("Error downloading " .. v.video_name,
|
||||
print_osd_message("Error starting download for " .. v.video_name,
|
||||
MSG_DURATION, style.error)
|
||||
end
|
||||
else
|
||||
@ -444,19 +453,6 @@ local function download_current_video()
|
||||
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 {{{
|
||||
@ -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",
|
||||
download_current_video)
|
||||
|
||||
mp.register_event("end-file", on_end_file)
|
||||
mp.register_event("track-changed", on_track_changed)
|
||||
mp.register_event("playback-restart", on_playback_restart)
|
||||
-- Listen for the file-loaded event
|
||||
mp.register_event("end-file", YouTubeQueue.on_end_file)
|
||||
mp.register_event("track-changed", YouTubeQueue.on_track_changed)
|
||||
mp.register_event("playback-restart", YouTubeQueue.on_playback_restart)
|
||||
-- }}}
|
||||
|
Loading…
Reference in New Issue
Block a user