mirror of
https://github.com/ksyasuda/mpv-youtube-queue.git
synced 2024-11-22 03:19:54 -08:00
Compare commits
4 Commits
f9ac4b6d18
...
894bc5b8e6
Author | SHA1 | Date | |
---|---|---|---|
|
894bc5b8e6 | ||
|
cc4f11cb1c | ||
|
dfdbe42b33 | ||
|
28c3855370 |
Binary file not shown.
Before Width: | Height: | Size: 861 KiB After Width: | Height: | Size: 565 KiB |
@ -39,16 +39,35 @@ local options = {
|
|||||||
clipboard_command = "xclip -o",
|
clipboard_command = "xclip -o",
|
||||||
display_limit = 6,
|
display_limit = 6,
|
||||||
cursor_icon = "🠺",
|
cursor_icon = "🠺",
|
||||||
font_size = 24,
|
font_size = 14,
|
||||||
font_name = "JetBrains Mono"
|
font_name = "JetBrains Mono"
|
||||||
}
|
}
|
||||||
|
|
||||||
local colors = {
|
local colors = {
|
||||||
error = "676EFF",
|
error = "676EFF",
|
||||||
text = "BFBFBF",
|
selected = "F993BD",
|
||||||
selected_color = "F993BD",
|
hover_selected = "FAA9CA",
|
||||||
cursor = "FDE98B",
|
cursor = "FDE98B",
|
||||||
reset = "{\\c&BFBFBF&}"
|
header = "8CFAF1",
|
||||||
|
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")
|
||||||
@ -71,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)
|
||||||
@ -195,27 +216,43 @@ 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 styleOn .. "{\\c&" ..
|
local prefix = (i == selected_index) and style.cursor ..
|
||||||
colors.cursor .. "&}" .. options.cursor_icon ..
|
options.cursor_icon .. " " .. style.reset or
|
||||||
" " .. colors.reset .. styleOff or " "
|
" "
|
||||||
if i == current_index then
|
if i == current_index and i == selected_index then
|
||||||
message = message .. prefix .. styleOn .. "{\\b1\\c&" ..
|
mp.msg.log("info", "YES")
|
||||||
colors.selected_color .. "&}" .. i .. ". " ..
|
message =
|
||||||
video_queue[i].name .. "{\\b0}" .. colors.reset ..
|
message .. prefix .. style.hover_selected .. i .. ". " ..
|
||||||
styleOff .. "\n"
|
video_queue[i].video_name .. " - (" ..
|
||||||
|
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 .. styleOn .. colors.reset ..
|
message = message .. prefix .. style.reset .. i .. ". " ..
|
||||||
styleOff .. i .. ". " .. video_queue[i].name ..
|
video_queue[i].video_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,
|
||||||
@ -311,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 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 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
|
||||||
|
|
||||||
@ -364,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