mirror of
https://github.com/ksyasuda/mpv-youtube-queue.git
synced 2024-11-22 03:19:54 -08:00
Compare commits
5 Commits
2d47774f6c
...
ac73fb2ba2
Author | SHA1 | Date | |
---|---|---|---|
|
ac73fb2ba2 | ||
|
0e041c22e6 | ||
fc7c5d44e8 | |||
|
a39a7c6a95 | ||
|
af81562606 |
10
.github/workflows/luackeck.yml
vendored
Normal file
10
.github/workflows/luackeck.yml
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
name: Luacheck
|
||||||
|
on: [push, pull_request]
|
||||||
|
jobs:
|
||||||
|
sile:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Luacheck linter
|
||||||
|
uses: lunarmodules/luacheck@v1
|
23
README.md
23
README.md
@ -1,6 +1,10 @@
|
|||||||
# mpv-youtube-queue
|
# mpv-youtube-queue
|
||||||
|
|
||||||
A Lua script that implements the YouTube 'Add to Queue' functionality for MPV
|
<div align="center">
|
||||||
|
|
||||||
|
A Lua script that implements the YouTube 'Add to Queue' functionality for mpv
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
![mpv-youtube-queue image](.assets/mpv-youtube-queue.png)
|
![mpv-youtube-queue image](.assets/mpv-youtube-queue.png)
|
||||||
|
|
||||||
@ -13,6 +17,7 @@ A Lua script that implements the YouTube 'Add to Queue' functionality for MPV
|
|||||||
- 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 or channel page of the currently playing video in a new browser tab
|
||||||
- Download the currently playing video
|
- Download the currently playing video
|
||||||
|
- Download a video in the queue
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
@ -42,21 +47,23 @@ This script requires the following software to be installed on the system
|
|||||||
|
|
||||||
- `add_to_queue - ctrl+a`: Add a video in the clipboard to the queue
|
- `add_to_queue - ctrl+a`: Add a video in the clipboard to the queue
|
||||||
- `download_current_video - ctrl+d`: Download the currently playing video
|
- `download_current_video - ctrl+d`: Download the currently playing video
|
||||||
- `move_cursor_down - ctrl+DOWN`: Move the cursor down one row in the queue
|
- `download_selected_video - ctrl+D`: Download the currently selected video
|
||||||
- `move_cursor_up - ctrl+UP`- Move the cursor up one row in the queue
|
in the queue
|
||||||
|
- `move_cursor_down - ctrl+j`: Move the cursor down one row in the queue
|
||||||
|
- `move_cursor_up - ctrl+k`- Move the cursor up one row in the queue
|
||||||
- `move_video - ctrl+m`: Mark/move the selected video in the queue
|
- `move_video - ctrl+m`: Mark/move the selected video in the queue
|
||||||
|
- `play_next_in_queue - ctrl+n`: Play the next video in the queue
|
||||||
|
- `open_video_in_browser - ctrl+o`: Open the currently playing video in the browser
|
||||||
- `open_channel_in_browser - ctrl+O`: Open the channel page for the currently
|
- `open_channel_in_browser - ctrl+O`: Open the channel page for the currently
|
||||||
playing video in the browser
|
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_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
|
|
||||||
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
|
- `remove_from_queue - ctrl+x`: Remove the currently selected video from the
|
||||||
queue
|
queue
|
||||||
|
- `play_selected_video - ctrl+ENTER`: Play the currently selected video in
|
||||||
|
the queue
|
||||||
|
|
||||||
### Default Option
|
### Default Option
|
||||||
|
|
||||||
@ -75,6 +82,8 @@ This script requires the following software to be installed on the system
|
|||||||
- `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
|
- `ytdlp_output_template - %(uploader)s/%(title)s.%(ext)s`: The [yt-dlp output
|
||||||
template string](https://github.com/yt-dlp/yt-dlp#output-template)
|
template string](https://github.com/yt-dlp/yt-dlp#output-template)
|
||||||
|
- Full path with the default `download_directory`
|
||||||
|
is: `~/videos/YouTube/<uploader>/<title>.<ext>`
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@ -1,23 +1,26 @@
|
|||||||
add_to_queue=ctrl+a
|
add_to_queue=ctrl+a
|
||||||
move_cursor_down=ctrl+DOWN
|
download_current_video=ctrl+d
|
||||||
move_cursor_up=ctrl+UP
|
download_selected_video=ctrl+D
|
||||||
open_channel_in_browser=ctrl+O
|
move_cursor_down=ctrl+j
|
||||||
open_video_in_browser=ctrl+o
|
move_cursor_up=ctrl+k
|
||||||
|
move_video=ctrl+m
|
||||||
play_next_in_queue=ctrl+n
|
play_next_in_queue=ctrl+n
|
||||||
|
open_video_in_browser=ctrl+o
|
||||||
|
open_channel_in_browser=ctrl+O
|
||||||
play_previous_in_queue=ctrl+p
|
play_previous_in_queue=ctrl+p
|
||||||
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
|
remove_from_queue=ctrl+x
|
||||||
|
play_selected_video=ctrl+ENTER
|
||||||
browser=firefox
|
browser=firefox
|
||||||
clipboard_command=xclip -o
|
clipboard_command=xclip -o
|
||||||
cursor_icon=➤
|
cursor_icon=➤
|
||||||
display_limit=6
|
display_limit=6
|
||||||
download_directory=~/videos/YouTube
|
download_directory=~/videos/YouTube
|
||||||
download_format_str=%(uploader)s/%(title)s.%(ext)s
|
|
||||||
download_quality=720p
|
download_quality=720p
|
||||||
downloader=curl
|
downloader=curl
|
||||||
font_name=JetBrains Mono
|
font_name=JetBrains Mono
|
||||||
font_size=12
|
font_size=12
|
||||||
marked_icon=⇅
|
marked_icon=⇅
|
||||||
show_errors=yes
|
show_errors=yes
|
||||||
|
ytdlp_output_template=%(uploader)s/%(title)s.%(ext)s
|
||||||
|
@ -15,42 +15,36 @@
|
|||||||
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
|
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
local mp = require 'mp'
|
local mp = require 'mp'
|
||||||
mp.options = require 'mp.options'
|
mp.options = require 'mp.options'
|
||||||
local YouTubeQueue = {}
|
|
||||||
local video_queue = {}
|
|
||||||
local current_video = nil
|
|
||||||
local index = 0
|
|
||||||
local selected_index = 1
|
|
||||||
local MSG_DURATION = 1.5
|
|
||||||
local marked_index = nil
|
|
||||||
local styleOn = mp.get_property("osd-ass-cc/0")
|
local styleOn = mp.get_property("osd-ass-cc/0")
|
||||||
local styleOff = mp.get_property("osd-ass-cc/1")
|
local styleOff = mp.get_property("osd-ass-cc/1")
|
||||||
|
|
||||||
local options = {
|
local options = {
|
||||||
add_to_queue = "ctrl+a",
|
add_to_queue = "ctrl+a",
|
||||||
download_current_video = "ctrl+d",
|
download_current_video = "ctrl+d",
|
||||||
move_cursor_down = "ctrl+DOWN",
|
download_selected_video = "ctrl+D",
|
||||||
move_cursor_up = "ctrl+UP",
|
move_cursor_down = "ctrl+j",
|
||||||
|
move_cursor_up = "ctrl+k",
|
||||||
move_video = "ctrl+m",
|
move_video = "ctrl+m",
|
||||||
open_channel_in_browser = "ctrl+O",
|
|
||||||
open_video_in_browser = "ctrl+o",
|
|
||||||
play_next_in_queue = "ctrl+n",
|
play_next_in_queue = "ctrl+n",
|
||||||
|
open_video_in_browser = "ctrl+o",
|
||||||
|
open_channel_in_browser = "ctrl+O",
|
||||||
play_previous_in_queue = "ctrl+p",
|
play_previous_in_queue = "ctrl+p",
|
||||||
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",
|
remove_from_queue = "ctrl+x",
|
||||||
clipboard_command = "xclip -o",
|
play_selected_video = "ctrl+ENTER",
|
||||||
browser = "firefox",
|
browser = "firefox",
|
||||||
|
clipboard_command = "xclip -o",
|
||||||
cursor_icon = "➤",
|
cursor_icon = "➤",
|
||||||
marked_icon = "⇅",
|
display_limit = 6,
|
||||||
download_directory = "~/videos/YouTube",
|
download_directory = "~/videos/YouTube",
|
||||||
download_format_str = "%(uploader)s/%(title)s.%(ext)s",
|
|
||||||
downloader = "curl",
|
|
||||||
download_quality = "720p",
|
download_quality = "720p",
|
||||||
|
downloader = "curl",
|
||||||
font_name = "JetBrains Mono",
|
font_name = "JetBrains Mono",
|
||||||
font_size = 12,
|
font_size = 12,
|
||||||
display_limit = 6,
|
marked_icon = "⇅",
|
||||||
show_errors = false
|
show_errors = true,
|
||||||
|
ytdlp_output_template = "%(uploader)s/%(title)s.%(ext)s"
|
||||||
}
|
}
|
||||||
|
|
||||||
mp.options.read_options(options, "mpv-youtube-queue")
|
mp.options.read_options(options, "mpv-youtube-queue")
|
||||||
@ -84,8 +78,15 @@ local style = {
|
|||||||
sortoftransparent .. "}"
|
sortoftransparent .. "}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local YouTubeQueue = {}
|
||||||
|
local video_queue = {}
|
||||||
|
local MSG_DURATION = 1.5
|
||||||
local display_limit = options.display_limit
|
local display_limit = options.display_limit
|
||||||
|
local index = 0
|
||||||
|
local selected_index = 1
|
||||||
local display_offset = 0
|
local display_offset = 0
|
||||||
|
local marked_index = nil
|
||||||
|
local current_video = nil
|
||||||
|
|
||||||
-- HELPERS {{{
|
-- HELPERS {{{
|
||||||
|
|
||||||
@ -387,6 +388,8 @@ function YouTubeQueue.play_next_in_queue()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local current_index = YouTubeQueue.get_current_index()
|
local current_index = YouTubeQueue.get_current_index()
|
||||||
|
-- if the current video is not the first in the queue, then play the video
|
||||||
|
-- else, check if the video is playing and if not play the video with replace
|
||||||
if YouTubeQueue.size() > 1 then
|
if YouTubeQueue.size() > 1 then
|
||||||
mp.set_property_number("playlist-pos", current_index - 1)
|
mp.set_property_number("playlist-pos", current_index - 1)
|
||||||
else
|
else
|
||||||
@ -429,6 +432,8 @@ function YouTubeQueue.add_to_queue(url)
|
|||||||
channel_name = channel_name
|
channel_name = channel_name
|
||||||
}
|
}
|
||||||
table.insert(video_queue, video)
|
table.insert(video_queue, video)
|
||||||
|
-- if the queue was empty, start playing the video
|
||||||
|
-- otherwise, add the video to the playlist
|
||||||
if not YouTubeQueue.get_current_video() then
|
if not YouTubeQueue.get_current_video() then
|
||||||
YouTubeQueue.play_next_in_queue()
|
YouTubeQueue.play_next_in_queue()
|
||||||
else
|
else
|
||||||
@ -452,46 +457,54 @@ function YouTubeQueue.play_previous_video()
|
|||||||
sleep(MSG_DURATION)
|
sleep(MSG_DURATION)
|
||||||
end
|
end
|
||||||
|
|
||||||
function YouTubeQueue.download_current_video()
|
function YouTubeQueue.download_video_at(idx)
|
||||||
if current_video and current_video ~= "" then
|
|
||||||
local o = options
|
local o = options
|
||||||
local v = current_video
|
local v = video_queue[idx]
|
||||||
local q = o.download_quality:sub(1, -2)
|
local q = o.download_quality:sub(1, -2)
|
||||||
local dl_dir = expanduser(o.download_directory)
|
local dl_dir = expanduser(o.download_directory)
|
||||||
local command = 'yt-dlp -f \'bestvideo[height<=' .. q ..
|
local command = 'yt-dlp -f \'bestvideo[height<=' .. q ..
|
||||||
']+bestaudio/best[height<=' .. q .. ']\' -o "' ..
|
']+bestaudio/best[height<=' .. q .. ']\' -o "' .. dl_dir ..
|
||||||
dl_dir .. "/" .. options.download_format_str ..
|
"/" .. options.ytdlp_output_template ..
|
||||||
'" --downloader ' .. o.downloader .. ' ' ..
|
'" --downloader ' .. o.downloader .. ' ' .. v.video_url
|
||||||
v.video_url
|
|
||||||
|
|
||||||
-- Run the download command
|
-- Run the download command
|
||||||
local handle = io.popen(command)
|
local handle = io.popen(command)
|
||||||
if handle == nil then
|
if handle == nil then
|
||||||
print_osd_message("Error starting download.", MSG_DURATION,
|
print_osd_message("Error starting download.", MSG_DURATION, style.error)
|
||||||
style.error)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
print_osd_message("Starting download for " .. v.video_name, MSG_DURATION)
|
print_osd_message("Starting download for " .. v.video_name, MSG_DURATION)
|
||||||
local result = handle:read("*a")
|
local result = handle:read("*a")
|
||||||
handle:close()
|
handle:close()
|
||||||
if result == nil then
|
if result == nil then
|
||||||
print_osd_message("Error starting download.", MSG_DURATION,
|
print_osd_message("Error starting download.", MSG_DURATION, style.error)
|
||||||
style.error)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if result then
|
if result then
|
||||||
print_osd_message("Finished downloading " .. v.video_name,
|
print_osd_message("Finished downloading " .. v.video_name, MSG_DURATION)
|
||||||
MSG_DURATION)
|
|
||||||
else
|
else
|
||||||
print_osd_message("Error downloading " .. v.video_name,
|
print_osd_message("Error downloading " .. v.video_name, MSG_DURATION,
|
||||||
MSG_DURATION, style.error)
|
style.error)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function YouTubeQueue.download_current_video()
|
||||||
|
if current_video ~= nil and current_video ~= "" then
|
||||||
|
YouTubeQueue.download_video_at(index)
|
||||||
else
|
else
|
||||||
print_osd_message("No video to download.", MSG_DURATION, style.error)
|
print_osd_message("No video to download.", MSG_DURATION, style.error)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function YouTubeQueue.download_selected_video()
|
||||||
|
if selected_index == 1 and current_video == nil then
|
||||||
|
print_osd_message("No video to download.", MSG_DURATION, style.error)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
YouTubeQueue.download_video_at(selected_index)
|
||||||
|
end
|
||||||
|
|
||||||
function YouTubeQueue.remove_from_queue()
|
function YouTubeQueue.remove_from_queue()
|
||||||
if index == selected_index then
|
if index == selected_index then
|
||||||
print_osd_message("Cannot remove current video", MSG_DURATION,
|
print_osd_message("Cannot remove current video", MSG_DURATION,
|
||||||
@ -555,6 +568,8 @@ mp.add_key_binding(options.open_channel_in_browser, "open_channel_in_browser",
|
|||||||
open_channel_in_browser)
|
open_channel_in_browser)
|
||||||
mp.add_key_binding(options.download_current_video, "download_current_video",
|
mp.add_key_binding(options.download_current_video, "download_current_video",
|
||||||
YouTubeQueue.download_current_video)
|
YouTubeQueue.download_current_video)
|
||||||
|
mp.add_key_binding(options.download_selected_video, "download_selected_video",
|
||||||
|
YouTubeQueue.download_selected_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",
|
mp.add_key_binding(options.remove_from_queue, "delete_video",
|
||||||
|
Loading…
Reference in New Issue
Block a user