mirror of
https://github.com/ksyasuda/mpv-youtube-queue.git
synced 2024-10-28 04:44:11 -07:00
* convert get_video_info to use mp functions and add menu_timeout option * add menu_timeout config option * fix add_to_queue not returning when given invalid url or path
This commit is contained in:
parent
7b9a061118
commit
fa2014acd6
@ -81,6 +81,7 @@ This script requires the following software to be installed on the system
|
|||||||
- `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 in
|
- `marked_icon - ⇅`: The icon to use to mark a video as ready to be moved in
|
||||||
the queue
|
the queue
|
||||||
|
- `menu_timeout - 5`: The number of seconds until the menu times out
|
||||||
- `show_errors - yes`: Show error messages on the OSD
|
- `show_errors - yes`: Show error messages on the OSD
|
||||||
- `ytdlp_file_format - mp4`: The preferred file format for downloaded videos
|
- `ytdlp_file_format - mp4`: The preferred file format for downloaded videos
|
||||||
- `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
|
||||||
|
@ -22,6 +22,7 @@ downloader=curl
|
|||||||
font_name=JetBrains Mono
|
font_name=JetBrains Mono
|
||||||
font_size=12
|
font_size=12
|
||||||
marked_icon=⇅
|
marked_icon=⇅
|
||||||
|
menu_timeout=5
|
||||||
show_errors=yes
|
show_errors=yes
|
||||||
ytdlp_file_format=mp4
|
ytdlp_file_format=mp4
|
||||||
ytdlp_output_template=%(uploader)s/%(title)s.%(ext)s
|
ytdlp_output_template=%(uploader)s/%(title)s.%(ext)s
|
||||||
|
@ -55,6 +55,7 @@ local options = {
|
|||||||
font_name = "JetBrains Mono",
|
font_name = "JetBrains Mono",
|
||||||
font_size = 12,
|
font_size = 12,
|
||||||
marked_icon = "⇅",
|
marked_icon = "⇅",
|
||||||
|
menu_timeout = 5,
|
||||||
show_errors = true,
|
show_errors = true,
|
||||||
ytdlp_file_format = "mp4",
|
ytdlp_file_format = "mp4",
|
||||||
ytdlp_output_template = "%(uploader)s/%(title)s.%(ext)s"
|
ytdlp_output_template = "%(uploader)s/%(title)s.%(ext)s"
|
||||||
@ -67,7 +68,7 @@ local function destroy()
|
|||||||
destroyer = nil
|
destroyer = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
timeout = mp.add_periodic_timer(5, destroy)
|
timeout = mp.add_periodic_timer(options.menu_timeout, destroy)
|
||||||
|
|
||||||
-- STYLE {{{
|
-- STYLE {{{
|
||||||
local colors = {
|
local colors = {
|
||||||
@ -212,25 +213,29 @@ function YouTubeQueue.get_clipboard_content()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function YouTubeQueue.get_video_info(url)
|
function YouTubeQueue.get_video_info(url)
|
||||||
local command =
|
local res = mp.command_native({
|
||||||
'yt-dlp --print channel_url --print uploader --print title --playlist-items 1 ' ..
|
name = "subprocess",
|
||||||
surround_with_quotes(url)
|
playback_only = false,
|
||||||
local handle = io.popen(command)
|
capture_stdout = true,
|
||||||
if handle == nil then return nil, nil, nil end
|
args = {
|
||||||
|
"yt-dlp", "--print", "channel_url", "--print", "uploader",
|
||||||
|
"--print", "title", "--playlist-items", "1", url
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
local result = handle:read("*a")
|
if res.status ~= 0 then
|
||||||
handle:close()
|
print_osd_message("Failed to get video info", MSG_DURATION, style.error)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
-- Split the result into URL, name, and video title
|
local channel_url, uploader, title = res.stdout:match("(.*)\n(.*)\n(.*)\n")
|
||||||
local channel_url, channel_name, video_name = result:match(
|
if channel_url == nil or uploader == nil or title == nil or channel_url ==
|
||||||
"(.-)\n(.-)\n(.*)")
|
"" or uploader == "" or title == "" then
|
||||||
|
print_osd_message("Failed to get video info", MSG_DURATION, style.error)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
-- Remove trailing whitespace
|
return channel_url, uploader, title
|
||||||
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
|
end
|
||||||
|
|
||||||
function YouTubeQueue.print_current_video()
|
function YouTubeQueue.print_current_video()
|
||||||
@ -473,6 +478,7 @@ function YouTubeQueue.add_to_queue(url, update_internal_playlist)
|
|||||||
(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,
|
print_osd_message("Error getting video info.", MSG_DURATION,
|
||||||
style.error)
|
style.error)
|
||||||
|
return
|
||||||
else
|
else
|
||||||
video = {
|
video = {
|
||||||
video_url = url,
|
video_url = url,
|
||||||
@ -487,6 +493,7 @@ function YouTubeQueue.add_to_queue(url, update_internal_playlist)
|
|||||||
video_name == "" then
|
video_name == "" then
|
||||||
print_osd_message("Error getting video info.", MSG_DURATION,
|
print_osd_message("Error getting video info.", MSG_DURATION,
|
||||||
style.error)
|
style.error)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
video = {
|
video = {
|
||||||
video_url = url,
|
video_url = url,
|
||||||
@ -521,7 +528,6 @@ function YouTubeQueue.download_video_at(idx)
|
|||||||
|
|
||||||
print_osd_message("Downloading " .. v.video_name .. "...", MSG_DURATION)
|
print_osd_message("Downloading " .. v.video_name .. "...", MSG_DURATION)
|
||||||
-- Run the download command
|
-- Run the download command
|
||||||
-- local handle = io.popen(command)
|
|
||||||
mp.command_native_async({
|
mp.command_native_async({
|
||||||
name = "subprocess",
|
name = "subprocess",
|
||||||
capture_stderr = true,
|
capture_stderr = true,
|
||||||
|
Loading…
Reference in New Issue
Block a user