Merge branch 'master' of github.com:ksyasuda/mpv-youtube-queue

This commit is contained in:
ksyasuda 2023-08-06 00:57:45 -07:00
commit 1bd0aa7c58
2 changed files with 18 additions and 14 deletions

View File

@ -18,3 +18,4 @@ font_name=JetBrains Mono
download_quality=720p
download_directory=~/videos/YouTube
downloader=curl
show_errors=no

View File

@ -47,7 +47,8 @@ local options = {
download_quality = "720p",
font_name = "JetBrains Mono",
font_size = 14,
display_limit = 6
display_limit = 6,
show_errors = false
}
mp.options.read_options(options, "mpv-youtube-queue")
@ -90,6 +91,7 @@ local display_offset = 0
local function sleep(n) os.execute("sleep " .. tonumber(n)) end
local function print_osd_message(message, duration, s)
if s == style.error and not options.show_errors then return end
if s == nil then s = style.font .. "{" .. notransparent .. "}" end
if duration == nil then duration = MSG_DURATION end
mp.osd_message(styleOn .. s .. message .. style.reset .. styleOff .. "\n",
@ -383,6 +385,11 @@ function YouTubeQueue.play_next_in_queue()
local current_index = YouTubeQueue.get_current_index()
if YouTubeQueue.size() > 1 then
mp.set_property_number("playlist-pos", current_index - 1)
else
local state = mp.get_property("core-idle")
if state == "yes" then
mp.commandv("loadfile", next_video.video_url, "replace")
end
end
print_current_video()
selected_index = current_index
@ -390,8 +397,7 @@ function YouTubeQueue.play_next_in_queue()
end
-- add the video to the queue from the clipboard
function YouTubeQueue.add_to_queue(url, check_queue)
if check_queue == nil then check_queue = true end
function YouTubeQueue.add_to_queue(url)
if url == nil or url == "" then
url = YouTubeQueue.get_clipboard_content()
if url == nil or url == "" then
@ -400,20 +406,17 @@ function YouTubeQueue.add_to_queue(url, check_queue)
return
end
end
if check_queue then
if YouTubeQueue.is_in_queue(url) then
print_osd_message("Video already in queue.", MSG_DURATION,
style.error)
print_osd_message("Video already in queue.", MSG_DURATION, style.error)
return
-- elseif not is_valid_ytdlp_url(url) then
-- mp.osd_message("Invalid URL.")
-- return
end
end
local channel_url, channel_name, video_name = get_video_info(url)
if (channel_url == nil or channel_name == nil or video_name == nil) or
(channel_url == "" or channel_name == "" or video_name == "") then
-- print_osd_message("Error getting video info.", MSG_DURATION, style.error)
print_osd_message("Error getting video info.", MSG_DURATION, style.error)
return
end
@ -507,7 +510,7 @@ local function on_playback_restart()
YouTubeQueue.update_current_index()
else
local url = mp.get_property("path")
YouTubeQueue.add_to_queue(url, false)
YouTubeQueue.add_to_queue(url)
end
end