mirror of
https://github.com/ksyasuda/mpv-youtube-queue.git
synced 2024-10-28 04:44:11 -07:00
Compare commits
3 Commits
d41d85b0e3
...
b46116e976
Author | SHA1 | Date | |
---|---|---|---|
|
b46116e976 | ||
|
2ca1234ee4 | ||
|
14e57bd9b4 |
@ -15,4 +15,5 @@ cursor_icon=🠺
|
||||
font_size=24
|
||||
font_name=JetBrains Mono
|
||||
download_quality=720p
|
||||
download_directory=~/Videos/YouTube
|
||||
download_directory=~/videos/YouTube
|
||||
downloader=curl
|
||||
|
@ -43,7 +43,8 @@ local options = {
|
||||
font_size = 14,
|
||||
font_name = "JetBrains Mono",
|
||||
download_quality = "720p",
|
||||
download_directory = "~/Videos/YouTube"
|
||||
download_directory = "~/videos/YouTube",
|
||||
downloader = "curl"
|
||||
}
|
||||
|
||||
local colors = {
|
||||
@ -218,28 +219,15 @@ 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
|
||||
@ -422,30 +410,33 @@ 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 ..
|
||||
']\' --newline -o "' ..
|
||||
']+bestaudio/best[height<=' .. q .. ']\' -o "' ..
|
||||
expanduser(o.download_directory) .. '/' ..
|
||||
v.channel_name .. '/' .. v.video_name ..
|
||||
'.%(ext)s" ' .. v.video_url
|
||||
'.%(ext)s" ' .. '--downloader ' .. o.downloader ..
|
||||
' ' .. v.video_url
|
||||
|
||||
-- Run the download command
|
||||
local handle = io.popen(command)
|
||||
if not handle then
|
||||
mp.osd_message("Error starting download.")
|
||||
print_osd_message("Error starting download.", MSG_DURATION,
|
||||
style.error)
|
||||
return
|
||||
end
|
||||
print_osd_message("Starting download for " .. v.video_name, MSG_DURATION)
|
||||
local result = handle:read("*a")
|
||||
handle:close()
|
||||
if not result then
|
||||
mp.osd_message("Error starting download.")
|
||||
print_osd_message("Error starting download.", MSG_DURATION,
|
||||
style.error)
|
||||
return
|
||||
end
|
||||
handle:close()
|
||||
|
||||
mp.msg.log("info", "RESULTS: " .. result)
|
||||
if result then
|
||||
print_osd_message("Downloading " .. v.video_name, MSG_DURATION)
|
||||
print_osd_message("Finished downloading " .. v.video_name,
|
||||
MSG_DURATION)
|
||||
else
|
||||
print_osd_message("Error starting download for " .. v.video_name,
|
||||
print_osd_message("Error downloading " .. v.video_name,
|
||||
MSG_DURATION, style.error)
|
||||
end
|
||||
else
|
||||
@ -453,6 +444,19 @@ 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 {{{
|
||||
@ -477,8 +481,7 @@ 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)
|
||||
|
||||
-- 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)
|
||||
mp.register_event("end-file", on_end_file)
|
||||
mp.register_event("track-changed", on_track_changed)
|
||||
mp.register_event("playback-restart", on_playback_restart)
|
||||
-- }}}
|
||||
|
Loading…
Reference in New Issue
Block a user