mirror of
https://github.com/ksyasuda/mpv-youtube-queue.git
synced 2024-11-22 03:19:54 -08:00
* Fix reorder queue function for when from_index < to_index * update default config * Fix clipboard function and linting errors * Update README.md with improved descriptions and installation instructions
This commit is contained in:
parent
84a860f596
commit
870f7473cf
38
README.md
38
README.md
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
|
|
||||||
A Lua script that implements the YouTube 'Add to Queue' functionality for mpv
|
A Lua script that replicates and extends the YouTube "Add to Queue" feature for mpv
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -10,37 +10,27 @@ A Lua script that implements the YouTube 'Add to Queue' functionality for mpv
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Add videos to a queue from the clipboard
|
- **Interactive Queue Management:** A menu-driven interface for adding, removing, and rearranging videos in your queue
|
||||||
- Works with links from any site
|
- **yt-dlp Integration:** Works with any link supported by [yt-dlp](https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md "yd-dlp supported sites page") and supports downloading a supported video in the queue
|
||||||
[supported by yt-dlp](https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md "yd-dlp supported sites page")
|
- **Internal Playlist Integration:** Seamlessly integrates with mpv's internal playlist for a unified playback experience
|
||||||
- An interactive menu to show the queue, to select a video to play, or to edit the order of the queue
|
- **Customizable Keybindings:** Assign your preferred hotkeys to interact with the currently playing video and queue
|
||||||
- Customizable keybindings to interact with the currrently playing video and the
|
|
||||||
queue
|
|
||||||
- Open the URL or channel page of the currently playing video in a new browser tab
|
|
||||||
- Download a video in the queue using yt-dlp
|
|
||||||
- Customizable download options
|
|
||||||
- Integrates with the internal mpv playlist
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
- This script uses the Linux `xclip` utility to read from the clipboard.
|
|
||||||
If you're on macOS or Windows, you'll need to adjust the `clipboard_command`
|
|
||||||
config variable in [mpv-youtube-queue.conf](./mpv-youtube-queue.conf)
|
|
||||||
- When adding videos to the queue, the script fetches the video name using
|
|
||||||
`yt-dlp`. Ensure you have `yt-dlp` installed and in your PATH.
|
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
This script requires the following software to be installed on the system
|
This script requires the following software to be installed on the system
|
||||||
|
|
||||||
- [xclip](https://github.com/astrand/xclip)
|
- One of [xclip](https://github.com/astrand/xclip), [wl-clipboard](https://github.com/bugaevc/wl-clipboard), or any command-line utility that can paste from the system clipboard
|
||||||
|
- Windows users can utilize `Get-Clipboard` from powershell by setting the `clipboard_command` in `mpv-youtube-queue.conf` file to the following: `clipboard_command=powershell -command Get-Clipboard`
|
||||||
- [yt-dlp](https://github.com/yt-dlp/yt-dlp)
|
- [yt-dlp](https://github.com/yt-dlp/yt-dlp)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
- Copy the `mpv-youtube-queue.lua` script to your `~~/scripts` directory
|
- Copy `mpv-youtube-queue.lua` script to your `~~/scripts` directory
|
||||||
(`~/.config/mpv` on Linux)
|
- `~/.config/mpv/scripts` on Linux
|
||||||
- Optionally copy the `mpv-youtube-queue.conf` to the `~~/script-opts` directory
|
- `%APPDATA%\mpv\scripts` on Windows
|
||||||
|
- Optionally copy `mpv-youtube-queue.conf` to the `~~/script-opts` directory
|
||||||
|
- `~/.config/mpv/script-opts` on Linux
|
||||||
|
- `%APPDATA%\mpv\script-opts` on Windows
|
||||||
to customize the script configuration as described in the next section
|
to customize the script configuration as described in the next section
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
@ -67,7 +57,7 @@ This script requires the following software to be installed on the system
|
|||||||
- `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
|
||||||
|
|
||||||
### Default Option
|
### Default Options
|
||||||
|
|
||||||
- `browser - firefox`: The browser to use when opening a video or channel page
|
- `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
|
||||||
|
@ -19,7 +19,7 @@ display_limit=10
|
|||||||
download_directory=~/videos/YouTube
|
download_directory=~/videos/YouTube
|
||||||
download_quality=720p
|
download_quality=720p
|
||||||
downloader=curl
|
downloader=curl
|
||||||
font_name=JetBrains Mono
|
font_name=JetBrainsMono
|
||||||
font_size=12
|
font_size=12
|
||||||
marked_icon=⇅
|
marked_icon=⇅
|
||||||
menu_timeout=5
|
menu_timeout=5
|
||||||
|
@ -158,11 +158,15 @@ local function open_url_in_browser(url)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function open_video_in_browser()
|
local function open_video_in_browser()
|
||||||
|
if current_video and current_video.video_url then
|
||||||
open_url_in_browser(current_video.video_url)
|
open_url_in_browser(current_video.video_url)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function open_channel_in_browser()
|
local function open_channel_in_browser()
|
||||||
|
if current_video and current_video.channel_url then
|
||||||
open_url_in_browser(current_video.channel_url)
|
open_url_in_browser(current_video.channel_url)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function _print_internal_playlist()
|
local function _print_internal_playlist()
|
||||||
@ -181,6 +185,29 @@ local function toggle_print()
|
|||||||
YouTubeQueue.print_queue()
|
YouTubeQueue.print_queue()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Function to remove leading and trailing quotes from the first and last arguments of a command table in-place
|
||||||
|
local function _remove_command_quotes(s)
|
||||||
|
-- if the first character of the first argument is a quote, remove it
|
||||||
|
if string.sub(s[1], 1, 1) == "'" or string.sub(s[1], 1, 1) == "\"" then
|
||||||
|
s[1] = string.sub(s[1], 2)
|
||||||
|
end
|
||||||
|
-- if the last character of the last argument is a quote, remove it
|
||||||
|
if string.sub(s[#s], -1) == "'" or string.sub(s[#s], -1) == "\"" then
|
||||||
|
s[#s] = string.sub(s[#s], 1, -2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Function to split the clipboard_command into it's parts and return as a table
|
||||||
|
local function _split_command(cmd)
|
||||||
|
local components = {}
|
||||||
|
for arg in cmd:gmatch("%S+") do
|
||||||
|
table.insert(components, arg)
|
||||||
|
end
|
||||||
|
_remove_command_quotes(components)
|
||||||
|
return components
|
||||||
|
end
|
||||||
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
-- QUEUE GETTERS AND SETTERS {{{
|
-- QUEUE GETTERS AND SETTERS {{{
|
||||||
@ -195,12 +222,15 @@ end
|
|||||||
|
|
||||||
-- returns the content of the clipboard
|
-- returns the content of the clipboard
|
||||||
function YouTubeQueue.get_clipboard_content()
|
function YouTubeQueue.get_clipboard_content()
|
||||||
local command, args = options.clipboard_command:match("(%S+)%s+(%S+)")
|
local command = _split_command(options.clipboard_command)
|
||||||
|
for i, v in ipairs(command) do
|
||||||
|
print(i, v)
|
||||||
|
end
|
||||||
local res = mp.command_native({
|
local res = mp.command_native({
|
||||||
name = "subprocess",
|
name = "subprocess",
|
||||||
playback_only = false,
|
playback_only = false,
|
||||||
capture_stdout = true,
|
capture_stdout = true,
|
||||||
args = { command, args }
|
args = command
|
||||||
})
|
})
|
||||||
|
|
||||||
if res.status ~= 0 then
|
if res.status ~= 0 then
|
||||||
@ -241,12 +271,14 @@ end
|
|||||||
function YouTubeQueue.print_current_video()
|
function YouTubeQueue.print_current_video()
|
||||||
destroy()
|
destroy()
|
||||||
local current = current_video
|
local current = current_video
|
||||||
if is_file(current.video_url) then
|
if current and current.vidro_url and is_file(current.video_url) then
|
||||||
print_osd_message("Playing: " .. current.video_name, 3)
|
print_osd_message("Playing: " .. current.video_name, 3)
|
||||||
else
|
else
|
||||||
|
if current and current.video_url then
|
||||||
print_osd_message("Playing: " .. current.video_name .. ' by ' ..
|
print_osd_message("Playing: " .. current.video_name .. ' by ' ..
|
||||||
current.channel_name, 3)
|
current.channel_name, 3)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- }}}
|
-- }}}
|
||||||
@ -324,8 +356,10 @@ function YouTubeQueue.reorder_queue(from_index, to_index)
|
|||||||
-- playlist-move is 0-indexed
|
-- playlist-move is 0-indexed
|
||||||
if from_index < to_index and to_index == #video_queue then
|
if from_index < to_index and to_index == #video_queue then
|
||||||
mp.commandv("playlist-move", from_index - 1, to_index)
|
mp.commandv("playlist-move", from_index - 1, to_index)
|
||||||
|
if to_index > index then index = index - 1 end
|
||||||
elseif from_index < to_index then
|
elseif from_index < to_index then
|
||||||
mp.commandv("playlist-move", to_index - 1, from_index - 1)
|
mp.commandv("playlist-move", from_index - 1, to_index)
|
||||||
|
if to_index > index then index = index - 1 end
|
||||||
else
|
else
|
||||||
mp.commandv("playlist-move", from_index - 1, to_index - 1)
|
mp.commandv("playlist-move", from_index - 1, to_index - 1)
|
||||||
end
|
end
|
||||||
@ -566,8 +600,10 @@ function YouTubeQueue.remove_from_queue()
|
|||||||
end
|
end
|
||||||
table.remove(video_queue, selected_index)
|
table.remove(video_queue, selected_index)
|
||||||
mp.commandv("playlist-remove", selected_index - 1)
|
mp.commandv("playlist-remove", selected_index - 1)
|
||||||
|
if current_video and current_video.video_name then
|
||||||
print_osd_message("Deleted " .. current_video.video_name .. " from queue.",
|
print_osd_message("Deleted " .. current_video.video_name .. " from queue.",
|
||||||
MSG_DURATION)
|
MSG_DURATION)
|
||||||
|
end
|
||||||
if selected_index > 1 then selected_index = selected_index - 1 end
|
if selected_index > 1 then selected_index = selected_index - 1 end
|
||||||
index = index - 1
|
index = index - 1
|
||||||
YouTubeQueue.print_queue()
|
YouTubeQueue.print_queue()
|
||||||
|
Loading…
Reference in New Issue
Block a user