add show_error config variable and fix add_to_queue to work for playing from command line again

This commit is contained in:
ksyasuda@umich.edu 2023-08-05 18:18:12 -07:00
parent c94ff7dcf2
commit 654e369940
2 changed files with 14 additions and 17 deletions

View File

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

View File

@ -47,7 +47,8 @@ local options = {
download_quality = "720p", download_quality = "720p",
font_name = "JetBrains Mono", font_name = "JetBrains Mono",
font_size = 14, font_size = 14,
display_limit = 6 display_limit = 6,
show_errors = false
} }
local colors = { local colors = {
@ -90,6 +91,7 @@ local display_offset = 0
local function sleep(n) os.execute("sleep " .. tonumber(n)) end local function sleep(n) os.execute("sleep " .. tonumber(n)) end
local function print_osd_message(message, duration, s) 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 s == nil then s = style.font .. "{" .. notransparent .. "}" end
if duration == nil then duration = MSG_DURATION end if duration == nil then duration = MSG_DURATION end
mp.osd_message(styleOn .. s .. message .. style.reset .. styleOff .. "\n", mp.osd_message(styleOn .. s .. message .. style.reset .. styleOff .. "\n",
@ -395,8 +397,7 @@ function YouTubeQueue.play_next_in_queue()
end end
-- add the video to the queue from the clipboard -- add the video to the queue from the clipboard
function YouTubeQueue.add_to_queue(url, check_queue) function YouTubeQueue.add_to_queue(url)
if check_queue == nil then check_queue = true end
if url == nil or url == "" then if url == nil or url == "" then
url = YouTubeQueue.get_clipboard_content() url = YouTubeQueue.get_clipboard_content()
if url == nil or url == "" then if url == nil or url == "" then
@ -405,20 +406,17 @@ function YouTubeQueue.add_to_queue(url, check_queue)
return return
end end
end end
if check_queue then
if YouTubeQueue.is_in_queue(url) then if YouTubeQueue.is_in_queue(url) then
print_osd_message("Video already in queue.", MSG_DURATION, print_osd_message("Video already in queue.", MSG_DURATION, style.error)
style.error)
return return
-- elseif not is_valid_ytdlp_url(url) then -- elseif not is_valid_ytdlp_url(url) then
-- mp.osd_message("Invalid URL.") -- mp.osd_message("Invalid URL.")
-- return -- return
end end
end
local channel_url, channel_name, video_name = get_video_info(url) local channel_url, channel_name, video_name = get_video_info(url)
if (channel_url == nil or channel_name == nil or video_name == nil) or if (channel_url == nil or channel_name == nil or video_name == nil) or
(channel_url == "" or channel_name == "" or video_name == "") then (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 return
end end
@ -508,13 +506,11 @@ local function on_track_changed() YouTubeQueue.update_current_index() end
-- Function to be called when the playback-restart event is triggered -- Function to be called when the playback-restart event is triggered
local function on_playback_restart() local function on_playback_restart()
local playlist_size = mp.get_property_number("playlist-count", 0) local playlist_size = mp.get_property_number("playlist-count", 0)
local state = mp.get_property("core-idle")
if playlist_size > 1 then if playlist_size > 1 then
YouTubeQueue.update_current_index() YouTubeQueue.update_current_index()
elseif state == "yes" then -- 1 item in playlist and not currently playing else
local url = mp.get_property("path") local url = mp.get_property("path")
print_osd_message("CHECKING URL: " .. url, MSG_DURATION) YouTubeQueue.add_to_queue(url)
YouTubeQueue.add_to_queue(url, false)
end end
end end