mirror of
https://github.com/ksyasuda/mpv-youtube-queue.git
synced 2024-11-22 03:19:54 -08:00
Compare commits
No commits in common. "52a2197fbb13f4ba9fe6886ed0351f3a567fd1c7" and "c4f058bafe0caaa3262a07a275e0404258afe45c" have entirely different histories.
52a2197fbb
...
c4f058bafe
@ -11,6 +11,3 @@ print_current_video=ctrl+P
|
||||
browser=firefox
|
||||
clipboard_command=xclip -o
|
||||
display_limit=6
|
||||
cursor_icon=
|
||||
font_size=24
|
||||
font_name=JetBrains Mono
|
||||
|
@ -23,8 +23,6 @@ local current_video = nil
|
||||
local index = 0
|
||||
local selected_index = 1
|
||||
local MSG_DURATION = 1.5
|
||||
local styleOn = mp.get_property("osd-ass-cc/0")
|
||||
local styleOff = mp.get_property("osd-ass-cc/1")
|
||||
|
||||
local options = {
|
||||
add_to_queue = "ctrl+a",
|
||||
@ -39,19 +37,8 @@ local options = {
|
||||
print_current_video = "ctrl+P",
|
||||
browser = "firefox",
|
||||
clipboard_command = "xclip -o",
|
||||
display_limit = 6,
|
||||
cursor_icon = "",
|
||||
font_size = 24,
|
||||
font_name = "JetBrains Mono",
|
||||
display_limit = 6
|
||||
}
|
||||
|
||||
local colors = {
|
||||
error = "676EFF",
|
||||
text = "BFBFBF",
|
||||
selected_color = "F993BD",
|
||||
cursor = "FDE98B",
|
||||
}
|
||||
|
||||
mp.options.read_options(options, "mpv-youtube-queue")
|
||||
|
||||
local display_limit = options.display_limit
|
||||
@ -62,19 +49,11 @@ local display_offset = 0
|
||||
-- run sleep shell command for n seconds
|
||||
local function sleep(n) os.execute("sleep " .. tonumber(n)) end
|
||||
|
||||
local function print_osd_message(message, duration, color)
|
||||
if not color then
|
||||
color = colors.text
|
||||
end
|
||||
mp.osd_message(styleOn .. "{\\c&" .. color .. "&}" .. message .. "{\\c&" .. colors.text .. "&}" .. styleOff .. "\n",
|
||||
duration)
|
||||
end
|
||||
|
||||
-- print the name of the current video to the OSD
|
||||
local function print_video_name(video, duration)
|
||||
if not video then return end
|
||||
if not duration then duration = 2 end
|
||||
print_osd_message('Currently playing: ' .. video.name, duration)
|
||||
mp.osd_message('Currently playing: ' .. video.name, duration)
|
||||
end
|
||||
|
||||
-- Function to get the video name from a YouTube URL
|
||||
@ -117,16 +96,13 @@ function YouTubeQueue.get_current_index() return index end
|
||||
|
||||
function YouTubeQueue.get_video_queue() return video_queue end
|
||||
|
||||
function YouTubeQueue.set_current_index(idx)
|
||||
index = idx
|
||||
current_video = video_queue[idx]
|
||||
end
|
||||
function YouTubeQueue.set_current_index(idx) index = idx end
|
||||
|
||||
function YouTubeQueue.get_current_video() return current_video end
|
||||
|
||||
function YouTubeQueue.get_video_at(idx)
|
||||
if idx <= 0 or idx > #video_queue then
|
||||
print_osd_message("Invalid video index", MSG_DURATION, colors.error)
|
||||
mp.osd_message("Invalid video index")
|
||||
return nil
|
||||
end
|
||||
return video_queue[idx]
|
||||
@ -160,6 +136,18 @@ function YouTubeQueue.prev_in_queue()
|
||||
return current_video
|
||||
end
|
||||
|
||||
function YouTubeQueue.play_video_at(idx)
|
||||
if idx <= 0 or idx > #video_queue then
|
||||
mp.osd_message("Invalid video index")
|
||||
return nil
|
||||
end
|
||||
index = idx
|
||||
selected_index = index
|
||||
current_video = video_queue[index]
|
||||
mp.set_property_number("playlist-pos", index - 1) -- zero-based index
|
||||
return current_video
|
||||
end
|
||||
|
||||
function YouTubeQueue.is_in_queue(url)
|
||||
for _, v in ipairs(video_queue) do if v.url == url then return true end end
|
||||
return false
|
||||
@ -168,9 +156,6 @@ end
|
||||
-- Function to find the index of the currently playing video
|
||||
function YouTubeQueue.update_current_index()
|
||||
local current_url = mp.get_property("path")
|
||||
if #video_queue == 0 then
|
||||
return
|
||||
end
|
||||
for i, v in ipairs(video_queue) do
|
||||
if v.url == current_url then
|
||||
index = i
|
||||
@ -207,33 +192,15 @@ function YouTubeQueue.print_queue(duration)
|
||||
display_offset = start_index - 1
|
||||
|
||||
for i = start_index, end_index do
|
||||
local prefix = (i == selected_index) and
|
||||
styleOn ..
|
||||
"{\\c&" ..
|
||||
colors.cursor ..
|
||||
"&}" .. options.cursor_icon .. " " .. "{\\c&" .. colors.text .. "&}" .. styleOff
|
||||
or
|
||||
" "
|
||||
if i == current_index then
|
||||
message = message ..
|
||||
prefix ..
|
||||
styleOn .. "{\b1\\c&" .. colors.selected_color .. "&}" .. i .. ". " .. video_queue[i].name ..
|
||||
"{\\c&" .. colors.text .. "&\b0}" .. styleOff .. "\n"
|
||||
elseif i == 2 then
|
||||
message = message ..
|
||||
prefix ..
|
||||
styleOn .. "{\\c&" .. colors.text .. "&\b0}" .. styleOff .. i .. ". " .. video_queue[i].name ..
|
||||
local prefix = (i == current_index and i == selected_index) and
|
||||
"=>> " or (i == current_index) and "=> " or
|
||||
(i == selected_index) and "> " or " "
|
||||
message = message .. prefix .. i .. ". " .. video_queue[i].name ..
|
||||
"\n"
|
||||
else
|
||||
message = message ..
|
||||
prefix ..
|
||||
styleOn .. "{\\c&" .. colors.text .. "&\b0}" .. styleOff .. i .. ". " .. video_queue[i].name ..
|
||||
"\n"
|
||||
end
|
||||
end
|
||||
mp.osd_message(message, duration)
|
||||
else
|
||||
print_osd_message("No videos in the queue or history.", duration, colors.error)
|
||||
mp.osd_message("No videos in the queue or history.")
|
||||
end
|
||||
end
|
||||
|
||||
@ -245,7 +212,7 @@ end
|
||||
local function get_clipboard_content()
|
||||
local handle = io.popen(options.clipboard_command)
|
||||
if not handle then
|
||||
print_osd_message("Error getting clipboard content", MSG_DURATION, colors.error)
|
||||
mp.osd_message("Error getting clipboard content")
|
||||
return nil
|
||||
end
|
||||
local result = handle:read("*a")
|
||||
@ -254,6 +221,7 @@ local function get_clipboard_content()
|
||||
end
|
||||
|
||||
local function move_selection_up()
|
||||
-- selected_index = YouTubeQueue.get_current_index()
|
||||
if selected_index > 1 then
|
||||
selected_index = selected_index - 1
|
||||
if selected_index < display_offset + 1 then
|
||||
@ -264,8 +232,10 @@ local function move_selection_up()
|
||||
end
|
||||
|
||||
local function move_selection_down()
|
||||
-- selected_index = YouTubeQueue.get_current_index()
|
||||
if selected_index < YouTubeQueue.size() then
|
||||
selected_index = selected_index + 1
|
||||
-- YouTubeQueue.set_current_index(current_index)
|
||||
if selected_index > display_offset + display_limit then
|
||||
display_offset = display_offset + 1
|
||||
end
|
||||
@ -273,22 +243,9 @@ local function move_selection_down()
|
||||
end
|
||||
end
|
||||
|
||||
local function play_video_at(idx)
|
||||
local queue = YouTubeQueue.get_video_queue()
|
||||
if idx <= 0 or idx > #queue then
|
||||
print_osd_message("Invalid video index", MSG_DURATION, colors.error)
|
||||
return nil
|
||||
end
|
||||
YouTubeQueue.set_current_index(idx)
|
||||
selected_index = index
|
||||
mp.set_property_number("playlist-pos", index - 1) -- zero-based index
|
||||
return current_video
|
||||
end
|
||||
|
||||
|
||||
local function play_selected_video()
|
||||
-- local current_index = YouTubeQueue.get_current_index()
|
||||
local video = play_video_at(selected_index)
|
||||
local video = YouTubeQueue.play_video_at(selected_index)
|
||||
YouTubeQueue.print_queue(MSG_DURATION - 0.5)
|
||||
sleep(MSG_DURATION)
|
||||
print_video_name(video, MSG_DURATION)
|
||||
@ -313,27 +270,22 @@ end
|
||||
local function add_to_queue()
|
||||
local url = get_clipboard_content()
|
||||
if not url then
|
||||
print_osd_message("Nothing found in the clipboard.", MSG_DURATION, colors.error)
|
||||
mp.osd_message("Nothing found in the clipboard.")
|
||||
return
|
||||
end
|
||||
if not string.match(url, "^https://www.youtube.com") then
|
||||
mp.osd_message("Not a YouTube URL.")
|
||||
return
|
||||
end
|
||||
if YouTubeQueue.is_in_queue(url) then
|
||||
print_osd_message("Video already in queue.", MSG_DURATION, colors.error)
|
||||
mp.osd_message("Video already in queue.")
|
||||
return
|
||||
elseif not is_valid_ytdlp_url(url) then
|
||||
mp.osd_message("Invalid URL.")
|
||||
return
|
||||
-- elseif not is_valid_ytdlp_url(url) then
|
||||
-- mp.osd_message("Invalid URL.")
|
||||
-- return
|
||||
end
|
||||
local name = get_video_name(url)
|
||||
if not name then
|
||||
print_osd_message("Error getting video name.", 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)
|
||||
return
|
||||
end
|
||||
|
||||
YouTubeQueue.add_to_queue({
|
||||
url = url,
|
||||
name = name,
|
||||
@ -343,7 +295,7 @@ local function add_to_queue()
|
||||
play_next_in_queue()
|
||||
else
|
||||
mp.commandv("loadfile", url, "append-play")
|
||||
print_osd_message("Added " .. name .. " to queue.", MSG_DURATION)
|
||||
mp.osd_message("Added " .. name .. " to queue.")
|
||||
end
|
||||
end
|
||||
|
||||
@ -351,7 +303,7 @@ end
|
||||
local function play_previous_video()
|
||||
local previous_video = YouTubeQueue.prev_in_queue()
|
||||
if not previous_video then
|
||||
print_osd_message("No previous video available.", MSG_DURATION, colors.error)
|
||||
mp.osd_message("No previous video available.")
|
||||
return
|
||||
end
|
||||
mp.set_property_number("playlist-pos", YouTubeQueue.get_current_index() - 1)
|
||||
@ -371,7 +323,7 @@ local function open_channel_in_browser()
|
||||
end
|
||||
|
||||
local function print_current_video()
|
||||
print_osd_message("Currently playing " .. current_video.name, 3)
|
||||
mp.osd_message("Currently playing " .. current_video.name, 3)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user