mirror of
https://github.com/ksyasuda/mpv-youtube-queue.git
synced 2024-11-22 03:19:54 -08:00
update styling and improve performance
- fix transparency - add channel name to print function - gather video info in single function
This commit is contained in:
parent
cc4f11cb1c
commit
894bc5b8e6
Binary file not shown.
Before Width: | Height: | Size: 614 KiB After Width: | Height: | Size: 565 KiB |
@ -39,7 +39,7 @@ local options = {
|
|||||||
clipboard_command = "xclip -o",
|
clipboard_command = "xclip -o",
|
||||||
display_limit = 6,
|
display_limit = 6,
|
||||||
cursor_icon = "🠺",
|
cursor_icon = "🠺",
|
||||||
font_size = 12,
|
font_size = 14,
|
||||||
font_name = "JetBrains Mono"
|
font_name = "JetBrains Mono"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,17 +53,21 @@ local colors = {
|
|||||||
text = "BFBFBF"
|
text = "BFBFBF"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local notransparent = "\\alpha&H00&"
|
||||||
|
local semitransparent = "\\alpha&H4D&"
|
||||||
|
local transparent = "\\alpha&H73&"
|
||||||
|
|
||||||
local style = {
|
local style = {
|
||||||
error = "{\\c&" .. colors.error .. "&\\alpha&H00&}",
|
error = "{\\c&" .. colors.error .. "&" .. notransparent .. "}",
|
||||||
selected = "{\\c&" .. colors.selected .. "&\\alpha&H40&}",
|
selected = "{\\c&" .. colors.selected .. "&" .. semitransparent .. "}",
|
||||||
hover_selected = "{\\c&" .. colors.hover_selected .. "&\\alpha&H20&}",
|
hover_selected = "{\\c&" .. colors.hover_selected .. "&\\alpha&H33&}",
|
||||||
cursor = "{\\c&" .. colors.cursor .. "&}",
|
cursor = "{\\c&" .. colors.cursor .. "&" .. notransparent .. "}",
|
||||||
reset = "{\\c&" .. colors.text .. "&}",
|
reset = "{\\c&" .. colors.text .. "&" .. transparent .. "}",
|
||||||
header = "{\\c&" .. colors.header .. "}",
|
header = "{\\fn" .. options.font_name .. "\\fs" .. options.font_size * 1.5 ..
|
||||||
hover = "{\\c&" .. colors.hover .. "&}",
|
"\\u1\\b1\\c&" .. colors.header .. "&" .. notransparent .. "}",
|
||||||
font = "{\\fn" .. options.font_name .. "\\fs" .. options.font_size ..
|
hover = "{\\c&" .. colors.hover .. "&" .. semitransparent .. "}",
|
||||||
"\\alpha&H80&}",
|
font = "{\\fn" .. options.font_name .. "\\fs" .. options.font_size .. "{" ..
|
||||||
notransparency = "{\\alpha&H00&}"
|
transparent .. "}"
|
||||||
}
|
}
|
||||||
|
|
||||||
mp.options.read_options(options, "mpv-youtube-queue")
|
mp.options.read_options(options, "mpv-youtube-queue")
|
||||||
@ -86,27 +90,29 @@ 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.name, duration)
|
print_osd_message('Playing: ' .. video.video_name, duration)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function to get the video name from a YouTube URL
|
local function get_video_info(url)
|
||||||
local function get_video_name(url)
|
local command =
|
||||||
local command = 'yt-dlp --get-title ' .. url
|
'yt-dlp --print channel_url --print uploader --print title --playlist-items 1 ' ..
|
||||||
|
url
|
||||||
local handle = io.popen(command)
|
local handle = io.popen(command)
|
||||||
if not handle then return nil end
|
if not handle then return nil, nil, nil end
|
||||||
local result = handle:read("*a")
|
|
||||||
handle:close()
|
|
||||||
return result:gsub("%s+$", "")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- get the channel url from a video url
|
|
||||||
local function get_channel_url(url)
|
|
||||||
local command = 'yt-dlp --print channel_url --playlist-items 1 ' .. url
|
|
||||||
local handle = io.popen(command)
|
|
||||||
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+$", "")
|
|
||||||
|
-- Split the result into URL, name, and video title
|
||||||
|
local channel_url, channel_name, video_name = result:match(
|
||||||
|
"(.-)\n(.-)\n(.*)")
|
||||||
|
|
||||||
|
-- Remove trailing whitespace
|
||||||
|
if channel_url then channel_url = channel_url:gsub("%s+$", "") end
|
||||||
|
if channel_name then channel_name = channel_name:gsub("%s+$", "") end
|
||||||
|
if video_name then video_name = video_name:gsub("%s+$", "") end
|
||||||
|
|
||||||
|
return channel_url, channel_name, video_name
|
||||||
end
|
end
|
||||||
|
|
||||||
local function is_valid_ytdlp_url(url)
|
local function is_valid_ytdlp_url(url)
|
||||||
@ -216,26 +222,34 @@ function YouTubeQueue.print_queue(duration)
|
|||||||
display_offset = start_index - 1
|
display_offset = start_index - 1
|
||||||
|
|
||||||
local message =
|
local message =
|
||||||
styleOn .. style.header .. "{\\fn" .. options.font_name .. "\\fs" ..
|
styleOn .. style.header .. "MPV-YOUTUBE-QUEUE{\\u0\\b0}" ..
|
||||||
options.font_size * 1.5 .. "\\b1}" .. "MPV-YOUTUBE-QUEUE{\\b0}" ..
|
|
||||||
style.reset .. style.font .. "\n"
|
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 style.cursor ..
|
||||||
style.notransparency .. options.cursor_icon ..
|
options.cursor_icon .. " " .. style.reset or
|
||||||
" " .. style.reset or " "
|
" "
|
||||||
if i == current_index and i == selected_index then
|
if i == current_index and i == selected_index then
|
||||||
|
mp.msg.log("info", "YES")
|
||||||
message =
|
message =
|
||||||
message .. prefix .. style.hover_selected .. i .. ". " ..
|
message .. prefix .. style.hover_selected .. i .. ". " ..
|
||||||
video_queue[i].name .. style.reset .. "\n"
|
video_queue[i].video_name .. " - (" ..
|
||||||
|
video_queue[i].channel_name .. ")" .. style.reset ..
|
||||||
|
"\n"
|
||||||
elseif i == current_index then
|
elseif i == current_index then
|
||||||
message = message .. prefix .. style.selected .. i .. ". " ..
|
message = message .. prefix .. style.selected .. i .. ". " ..
|
||||||
video_queue[i].name .. style.reset .. "\n"
|
video_queue[i].video_name .. " - (" ..
|
||||||
|
video_queue[i].channel_name .. ")" .. style.reset ..
|
||||||
|
"\n"
|
||||||
elseif i == selected_index then
|
elseif i == selected_index then
|
||||||
message = message .. prefix .. style.hover .. i .. ". " ..
|
message = message .. prefix .. style.hover .. i .. ". " ..
|
||||||
video_queue[i].name .. style.reset .. "\n"
|
video_queue[i].video_name .. " - (" ..
|
||||||
|
video_queue[i].channel_name .. ")" .. style.reset ..
|
||||||
|
"\n"
|
||||||
else
|
else
|
||||||
message = message .. prefix .. style.reset .. i .. ". " ..
|
message = message .. prefix .. style.reset .. i .. ". " ..
|
||||||
video_queue[i].name .. style.reset .. "\n"
|
video_queue[i].video_name .. " - (" ..
|
||||||
|
video_queue[i].channel_name .. ")" .. style.reset ..
|
||||||
|
"\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
message = message .. styleOff
|
message = message .. styleOff
|
||||||
@ -334,29 +348,25 @@ local function add_to_queue()
|
|||||||
-- mp.osd_message("Invalid URL.")
|
-- mp.osd_message("Invalid URL.")
|
||||||
-- return
|
-- return
|
||||||
end
|
end
|
||||||
local name = get_video_name(url)
|
local channel_url, channel_name, video_name = get_video_info(url)
|
||||||
if not name or name == "" then
|
if (not channel_url or not channel_name or not video_name) or
|
||||||
print_osd_message("Error getting video name.", MSG_DURATION,
|
(channel_url == "" or channel_name == "" or video_name == "") then
|
||||||
colors.error)
|
print_osd_message("Error getting video info.", MSG_DURATION,
|
||||||
return
|
|
||||||
end
|
|
||||||
local channel_url = get_channel_url(url)
|
|
||||||
if not channel_url or 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,
|
||||||
name = name,
|
video_name = video_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 " .. name .. " to queue.", MSG_DURATION)
|
print_osd_message("Added " .. video_name .. " to queue.", MSG_DURATION)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -387,7 +397,9 @@ local function open_channel_in_browser()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function print_current_video()
|
local function print_current_video()
|
||||||
print_osd_message("Currently playing " .. current_video.name, 3)
|
print_osd_message(
|
||||||
|
"Currently playing " .. current_video.video_name .. ' by ' ..
|
||||||
|
current_video.video_name, 3)
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user