Compare commits

..

No commits in common. "894bc5b8e6fef95d9a9f2d7dfaf7dfae8b530ccc" and "f9ac4b6d1876b6ea7cd20dd512da8f4360923d0a" have entirely different histories.

2 changed files with 43 additions and 78 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 565 KiB

After

Width:  |  Height:  |  Size: 861 KiB

View File

@ -39,35 +39,16 @@ local options = {
clipboard_command = "xclip -o", clipboard_command = "xclip -o",
display_limit = 6, display_limit = 6,
cursor_icon = "🠺", cursor_icon = "🠺",
font_size = 14, font_size = 24,
font_name = "JetBrains Mono" font_name = "JetBrains Mono"
} }
local colors = { local colors = {
error = "676EFF", error = "676EFF",
selected = "F993BD", text = "BFBFBF",
hover_selected = "FAA9CA", selected_color = "F993BD",
cursor = "FDE98B", cursor = "FDE98B",
header = "8CFAF1", reset = "{\\c&BFBFBF&}"
hover = "F2F8F8",
text = "BFBFBF"
}
local notransparent = "\\alpha&H00&"
local semitransparent = "\\alpha&H4D&"
local transparent = "\\alpha&H73&"
local style = {
error = "{\\c&" .. colors.error .. "&" .. notransparent .. "}",
selected = "{\\c&" .. colors.selected .. "&" .. semitransparent .. "}",
hover_selected = "{\\c&" .. colors.hover_selected .. "&\\alpha&H33&}",
cursor = "{\\c&" .. colors.cursor .. "&" .. notransparent .. "}",
reset = "{\\c&" .. colors.text .. "&" .. transparent .. "}",
header = "{\\fn" .. options.font_name .. "\\fs" .. options.font_size * 1.5 ..
"\\u1\\b1\\c&" .. colors.header .. "&" .. notransparent .. "}",
hover = "{\\c&" .. colors.hover .. "&" .. semitransparent .. "}",
font = "{\\fn" .. options.font_name .. "\\fs" .. options.font_size .. "{" ..
transparent .. "}"
} }
mp.options.read_options(options, "mpv-youtube-queue") mp.options.read_options(options, "mpv-youtube-queue")
@ -90,29 +71,27 @@ end
local function print_video_name(video, duration) local function print_video_name(video, duration)
if not video then return end if not video then return end
if not duration then duration = 2 end if not duration then duration = 2 end
print_osd_message('Playing: ' .. video.video_name, duration) print_osd_message('Playing: ' .. video.name, duration)
end end
local function get_video_info(url) -- Function to get the video name from a YouTube URL
local command = local function get_video_name(url)
'yt-dlp --print channel_url --print uploader --print title --playlist-items 1 ' .. local command = 'yt-dlp --get-title ' .. url
url
local handle = io.popen(command) local handle = io.popen(command)
if not handle then return nil, nil, nil end if not handle then return nil end
local result = handle:read("*a") local result = handle:read("*a")
handle:close() handle:close()
return result:gsub("%s+$", "")
end
-- Split the result into URL, name, and video title -- get the channel url from a video url
local channel_url, channel_name, video_name = result:match( local function get_channel_url(url)
"(.-)\n(.-)\n(.*)") local command = 'yt-dlp --print channel_url --playlist-items 1 ' .. url
local handle = io.popen(command)
-- Remove trailing whitespace if not handle then return nil end
if channel_url then channel_url = channel_url:gsub("%s+$", "") end local result = handle:read("*a")
if channel_name then channel_name = channel_name:gsub("%s+$", "") end handle:close()
if video_name then video_name = video_name:gsub("%s+$", "") end return result:gsub("%s+$", "")
return channel_url, channel_name, video_name
end end
local function is_valid_ytdlp_url(url) local function is_valid_ytdlp_url(url)
@ -216,43 +195,27 @@ 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
if #video_queue > 0 then if #video_queue > 0 then
local message = ""
local start_index = math.max(1, selected_index - display_limit / 2) local start_index = math.max(1, selected_index - display_limit / 2)
local end_index = local end_index =
math.min(#video_queue, start_index + display_limit - 1) math.min(#video_queue, start_index + display_limit - 1)
display_offset = start_index - 1 display_offset = start_index - 1
local message =
styleOn .. style.header .. "MPV-YOUTUBE-QUEUE{\\u0\\b0}" ..
style.reset .. style.font .. "\n"
for i = start_index, end_index do for i = start_index, end_index do
local prefix = (i == selected_index) and style.cursor .. local prefix = (i == selected_index) and styleOn .. "{\\c&" ..
options.cursor_icon .. " " .. style.reset or colors.cursor .. "&}" .. options.cursor_icon ..
" " " " .. colors.reset .. styleOff or " "
if i == current_index and i == selected_index then if i == current_index then
mp.msg.log("info", "YES") message = message .. prefix .. styleOn .. "{\\b1\\c&" ..
message = colors.selected_color .. "&}" .. i .. ". " ..
message .. prefix .. style.hover_selected .. i .. ". " .. video_queue[i].name .. "{\\b0}" .. colors.reset ..
video_queue[i].video_name .. " - (" .. styleOff .. "\n"
video_queue[i].channel_name .. ")" .. style.reset ..
"\n"
elseif i == current_index then
message = message .. prefix .. style.selected .. i .. ". " ..
video_queue[i].video_name .. " - (" ..
video_queue[i].channel_name .. ")" .. style.reset ..
"\n"
elseif i == selected_index then
message = message .. prefix .. style.hover .. i .. ". " ..
video_queue[i].video_name .. " - (" ..
video_queue[i].channel_name .. ")" .. style.reset ..
"\n"
else else
message = message .. prefix .. style.reset .. i .. ". " .. message = message .. prefix .. styleOn .. colors.reset ..
video_queue[i].video_name .. " - (" .. styleOff .. i .. ". " .. video_queue[i].name ..
video_queue[i].channel_name .. ")" .. style.reset ..
"\n" "\n"
end end
end end
message = message .. styleOff
mp.osd_message(message, duration) mp.osd_message(message, duration)
else else
print_osd_message("No videos in the queue or history.", duration, print_osd_message("No videos in the queue or history.", duration,
@ -348,25 +311,29 @@ local function add_to_queue()
-- mp.osd_message("Invalid URL.") -- mp.osd_message("Invalid URL.")
-- return -- return
end end
local channel_url, channel_name, video_name = get_video_info(url) local name = get_video_name(url)
if (not channel_url or not channel_name or not video_name) or if not name then
(channel_url == "" or channel_name == "" or video_name == "") then print_osd_message("Error getting video name.", MSG_DURATION,
print_osd_message("Error getting video info.", MSG_DURATION, colors.error)
return
end
local channel_url = get_channel_url(url)
if not channel_url then
print_osd_message("Error getting channel URL.", MSG_DURATION,
colors.error) colors.error)
return return
end end
YouTubeQueue.add_to_queue({ YouTubeQueue.add_to_queue({
url = url, url = url,
video_name = video_name, name = name,
channel_url = channel_url, channel_url = channel_url
channel_name = channel_name
}) })
if not YouTubeQueue.get_current_video() then if not YouTubeQueue.get_current_video() then
play_next_in_queue() play_next_in_queue()
else else
mp.commandv("loadfile", url, "append-play") mp.commandv("loadfile", url, "append-play")
print_osd_message("Added " .. video_name .. " to queue.", MSG_DURATION) print_osd_message("Added " .. name .. " to queue.", MSG_DURATION)
end end
end end
@ -397,9 +364,7 @@ local function open_channel_in_browser()
end end
local function print_current_video() local function print_current_video()
print_osd_message( print_osd_message("Currently playing " .. current_video.name, 3)
"Currently playing " .. current_video.video_name .. ' by ' ..
current_video.video_name, 3)
end end
-- }}} -- }}}