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. "33918e87d02839f9fd1f46427bb7869e9d8f495c" and "c67ac189b0ad1809c91da5b8d8617e1e1d9b442d" have entirely different histories.
33918e87d0
...
c67ac189b0
26
README.md
26
README.md
@ -1,6 +1,7 @@
|
|||||||
# mpv-youtube-queue
|
# mpv-youtube-queue
|
||||||
|
|
||||||
A Lua script that implements the YouTube 'Add to Queue' functionality in MPV
|
A Lua script for mpv that allows you to add YouTube videos to a queue,
|
||||||
|
navigate through the queue, and select a video to play.
|
||||||
|
|
||||||
![mpv-youtube-queue image](.assets/mpv-youtube-queue.png)
|
![mpv-youtube-queue image](.assets/mpv-youtube-queue.png)
|
||||||
|
|
||||||
@ -11,7 +12,8 @@ A Lua script that implements the YouTube 'Add to Queue' functionality in MPV
|
|||||||
- Select a video to play from the queue with an interactive menu,
|
- Select a video to play from the queue with an interactive menu,
|
||||||
or navigate through the queue with keyboard shortcuts
|
or navigate through the queue with keyboard shortcuts
|
||||||
- Edit the order of videos in the queue
|
- Edit the order of videos in the queue
|
||||||
- Open the URL or channel page of the currently playing video in a new browser tab
|
- Open the URL of the currently playing video in a new browser tab
|
||||||
|
- Open the channel page of the currently playing video
|
||||||
- Download the currently playing video
|
- Download the currently playing video
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
@ -50,31 +52,27 @@ This script requires the following software to be installed on the system
|
|||||||
- `open_video_in_browser - ctrl+o`: Open the currently playing video in the browser
|
- `open_video_in_browser - ctrl+o`: Open the currently playing video in the browser
|
||||||
- `play_next_in_queue - ctrl+n`: Play the next video in the queue
|
- `play_next_in_queue - ctrl+n`: Play the next video in the queue
|
||||||
- `play_previous_in_queue - ctrl+p`: Play the previous video in the queue
|
- `play_previous_in_queue - ctrl+p`: Play the previous video in the queue
|
||||||
- `play_selected_video - ctrl+ENTER`: Play the currently selected video in
|
`play_selected_video - ctrl+ENTER`: Play the currently selected video in
|
||||||
the queue
|
the queue
|
||||||
- `print_current_video - ctrl+P`: Print the name and channel of the currently
|
- `print_current_video - ctrl+P`: Print the name and channel of the currently
|
||||||
playing video to the OSD
|
playing video to the OSD
|
||||||
- `print_queue - ctrl+q`: Print the contents of the queue to the OSD
|
- `print_queue - ctrl+q`: Print the contents of the queue to the OSD
|
||||||
- `remove_from_queue - ctrl+x`: Remove the currently selected video from the
|
|
||||||
queue
|
|
||||||
|
|
||||||
### Default Option
|
### Default Option
|
||||||
|
|
||||||
- `browser - firefox`: The browser to use when opening a video or channel page
|
|
||||||
- `clipboard_command - xclip -o`: The command to use to get the contents of the clipboard
|
- `clipboard_command - xclip -o`: The command to use to get the contents of the clipboard
|
||||||
|
- `browser - firefox`: The browser to use when opening a video or channel page
|
||||||
- `cursor_icon - ➤`: The icon to use for the cursor
|
- `cursor_icon - ➤`: The icon to use for the cursor
|
||||||
- `display_limit - 6`: The maximum amount of videos to show on the OSD at once
|
- `marked_icon - ⇅`: The icon to use to mark a video as ready to be moved in
|
||||||
- `download_directory - ~/videos/YouTube`: The directory to use when
|
the queue
|
||||||
downloading a video
|
- `download_directory ~/videos/YouTube`: The directory to use when downloading
|
||||||
- `download_quality 720p`: The maximum download quality
|
a video
|
||||||
- `downloader - curl`: The name of the program to use to download the video
|
- `downloader - curl`: The name of the program to use to download the video
|
||||||
|
- `download_quality 720p`: The maximum download quality
|
||||||
- `font_name - JetBrains Mono`: The name of the font to use
|
- `font_name - JetBrains Mono`: The name of the font to use
|
||||||
- `font_size - 12`: Size of the font
|
- `font_size - 12`: Size of the font
|
||||||
- `marked_icon - ⇅`: The icon to use to mark a video as ready to be moved
|
- `display_limit - 6`: The maximum amount of videos to show on the OSD at once
|
||||||
in the queue
|
|
||||||
- `show_errors - yes`: Show error messages on the OSD
|
- `show_errors - yes`: Show error messages on the OSD
|
||||||
- `ytdlp_output_template - %(uploader)s/%(title)s.%(ext)s`: The [yt-dlp output
|
|
||||||
template string](https://github.com/yt-dlp/yt-dlp#output-template)
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@ -1,23 +1,22 @@
|
|||||||
add_to_queue=ctrl+a
|
add_to_queue=ctrl+a
|
||||||
move_cursor_down=ctrl+DOWN
|
|
||||||
move_cursor_up=ctrl+UP
|
|
||||||
open_channel_in_browser=ctrl+O
|
|
||||||
open_video_in_browser=ctrl+o
|
|
||||||
play_next_in_queue=ctrl+n
|
play_next_in_queue=ctrl+n
|
||||||
play_previous_in_queue=ctrl+p
|
play_previous_in_queue=ctrl+p
|
||||||
play_selected_video=ctrl+ENTER
|
|
||||||
print_current_video=ctrl+P
|
|
||||||
print_queue=ctrl+q
|
print_queue=ctrl+q
|
||||||
remove_from_queue=ctrl+x
|
move_cursor_up=ctrl+UP
|
||||||
|
move_cursor_down=ctrl+DOWN
|
||||||
|
play_selected_video=ctrl+ENTER
|
||||||
|
open_video_in_browser=ctrl+o
|
||||||
|
open_channel_in_browser=ctrl+O
|
||||||
|
print_current_video=ctrl+P
|
||||||
browser=firefox
|
browser=firefox
|
||||||
clipboard_command=xclip -o
|
clipboard_command=xclip -o
|
||||||
cursor_icon=➤
|
|
||||||
display_limit=6
|
display_limit=6
|
||||||
|
cursor_icon=➤
|
||||||
|
marked_icon=⇅
|
||||||
|
font_size=12
|
||||||
|
font_name=JetBrains Mono
|
||||||
|
download_quality=720p
|
||||||
download_directory=~/videos/YouTube
|
download_directory=~/videos/YouTube
|
||||||
download_format_str=%(uploader)s/%(title)s.%(ext)s
|
download_format_str=%(uploader)s/%(title)s.%(ext)s
|
||||||
download_quality=720p
|
|
||||||
downloader=curl
|
downloader=curl
|
||||||
font_name=JetBrains Mono
|
|
||||||
font_size=12
|
|
||||||
marked_icon=⇅
|
|
||||||
show_errors=yes
|
show_errors=yes
|
||||||
|
@ -38,7 +38,6 @@ local options = {
|
|||||||
play_selected_video = "ctrl+ENTER",
|
play_selected_video = "ctrl+ENTER",
|
||||||
print_current_video = "ctrl+P",
|
print_current_video = "ctrl+P",
|
||||||
print_queue = "ctrl+q",
|
print_queue = "ctrl+q",
|
||||||
remove_from_queue = "ctrl+x",
|
|
||||||
clipboard_command = "xclip -o",
|
clipboard_command = "xclip -o",
|
||||||
browser = "firefox",
|
browser = "firefox",
|
||||||
cursor_icon = "➤",
|
cursor_icon = "➤",
|
||||||
@ -134,6 +133,28 @@ local function open_channel_in_browser()
|
|||||||
open_url_in_browser(YouTubeQueue.get_current_video().channel_url)
|
open_url_in_browser(YouTubeQueue.get_current_video().channel_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_video_info(url)
|
||||||
|
local command =
|
||||||
|
'yt-dlp --print channel_url --print uploader --print title --playlist-items 1 ' ..
|
||||||
|
url
|
||||||
|
local handle = io.popen(command)
|
||||||
|
if handle == nil then return nil, nil, nil end
|
||||||
|
|
||||||
|
local result = handle:read("*a")
|
||||||
|
handle:close()
|
||||||
|
|
||||||
|
-- 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 ~= nil then channel_url = channel_url:gsub("%s+$", "") end
|
||||||
|
if channel_name ~= nil then channel_name = channel_name:gsub("%s+$", "") end
|
||||||
|
if video_name ~= nil then video_name = video_name:gsub("%s+$", "") end
|
||||||
|
|
||||||
|
return channel_url, channel_name, video_name
|
||||||
|
end
|
||||||
|
|
||||||
-- local function is_valid_ytdlp_url(url)
|
-- local function is_valid_ytdlp_url(url)
|
||||||
-- local command = 'yt-dlp --simulate \'' .. url .. '\' >/dev/null 2>&1'
|
-- local command = 'yt-dlp --simulate \'' .. url .. '\' >/dev/null 2>&1'
|
||||||
-- local handle = io.popen(command .. "; echo $?")
|
-- local handle = io.popen(command .. "; echo $?")
|
||||||
@ -182,28 +203,6 @@ function YouTubeQueue.get_clipboard_content()
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
function YouTubeQueue.get_video_info(url)
|
|
||||||
local command =
|
|
||||||
'yt-dlp --print channel_url --print uploader --print title --playlist-items 1 ' ..
|
|
||||||
url
|
|
||||||
local handle = io.popen(command)
|
|
||||||
if handle == nil then return nil, nil, nil end
|
|
||||||
|
|
||||||
local result = handle:read("*a")
|
|
||||||
handle:close()
|
|
||||||
|
|
||||||
-- 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 ~= nil then channel_url = channel_url:gsub("%s+$", "") end
|
|
||||||
if channel_name ~= nil then channel_name = channel_name:gsub("%s+$", "") end
|
|
||||||
if video_name ~= nil then video_name = video_name:gsub("%s+$", "") end
|
|
||||||
|
|
||||||
return channel_url, channel_name, video_name
|
|
||||||
end
|
|
||||||
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
-- QUEUE FUNCTIONS {{{
|
-- QUEUE FUNCTIONS {{{
|
||||||
@ -414,8 +413,7 @@ function YouTubeQueue.add_to_queue(url)
|
|||||||
print_osd_message("Video already in queue.", MSG_DURATION, style.error)
|
print_osd_message("Video already in queue.", MSG_DURATION, style.error)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local channel_url, channel_name, video_name =
|
local channel_url, channel_name, video_name = get_video_info(url)
|
||||||
YouTubeQueue.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)
|
||||||
@ -492,21 +490,6 @@ function YouTubeQueue.download_current_video()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function YouTubeQueue.remove_from_queue()
|
|
||||||
if index == selected_index then
|
|
||||||
print_osd_message("Cannot remove current video", MSG_DURATION,
|
|
||||||
style.error)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
table.remove(video_queue, selected_index)
|
|
||||||
mp.commandv("playlist-remove", selected_index - 1)
|
|
||||||
print_osd_message("Deleted " .. current_video.video_name .. " from queue.",
|
|
||||||
MSG_DURATION)
|
|
||||||
if selected_index > 1 then selected_index = selected_index - 1 end
|
|
||||||
index = index - 1
|
|
||||||
YouTubeQueue.print_queue()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
-- LISTENERS {{{
|
-- LISTENERS {{{
|
||||||
@ -557,8 +540,6 @@ mp.add_key_binding(options.download_current_video, "download_current_video",
|
|||||||
YouTubeQueue.download_current_video)
|
YouTubeQueue.download_current_video)
|
||||||
mp.add_key_binding(options.move_video, "move_video",
|
mp.add_key_binding(options.move_video, "move_video",
|
||||||
YouTubeQueue.mark_and_move_video)
|
YouTubeQueue.mark_and_move_video)
|
||||||
mp.add_key_binding(options.remove_from_queue, "delete_video",
|
|
||||||
YouTubeQueue.remove_from_queue)
|
|
||||||
|
|
||||||
mp.register_event("end-file", on_end_file)
|
mp.register_event("end-file", on_end_file)
|
||||||
mp.register_event("track-changed", on_track_changed)
|
mp.register_event("track-changed", on_track_changed)
|
||||||
|
Loading…
Reference in New Issue
Block a user