mirror of
https://github.com/FalloNero/yt-dlp4vlc.git
synced 2026-04-30 06:36:03 -04:00
added quality switch
add &quality=xxx to select the video quality, omit to default to maximum quality possible 360p 480p 720p 1080p 2160p
This commit is contained in:
148
youtube.lua
148
youtube.lua
@@ -18,106 +18,106 @@ end
|
|||||||
function parse()
|
function parse()
|
||||||
-- Construct the full YouTube URL
|
-- Construct the full YouTube URL
|
||||||
local youtube_url = vlc.access .. "://" .. vlc.path
|
local youtube_url = vlc.access .. "://" .. vlc.path
|
||||||
|
|
||||||
|
-- Extract "quality" query parameter if present
|
||||||
|
local quality = youtube_url:match("[&?]quality=(%d+)[pP]?")
|
||||||
|
youtube_url = youtube_url:gsub("[&?]quality=%d+[pP]?", ""):gsub("[&?]$", "") -- Remove trailing ? or &
|
||||||
|
|
||||||
|
local allowed_qualities = {
|
||||||
|
["360"] = true,
|
||||||
|
["480"] = true,
|
||||||
|
["720"] = true,
|
||||||
|
["1080"] = true,
|
||||||
|
["2160"] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
local format_string = "bestvideo+bestaudio" -- Default to highest available
|
||||||
|
if quality and allowed_qualities[quality] then
|
||||||
|
format_string = string.format("bestvideo[height=%s]+bestaudio", quality)
|
||||||
|
vlc.msg.info("Using requested quality: " .. quality .. "p")
|
||||||
|
else
|
||||||
|
vlc.msg.info("No valid quality specified. Defaulting to best available.")
|
||||||
|
end
|
||||||
|
|
||||||
local cmd_hidden = yt_dlp_silent_path
|
local cmd_hidden = yt_dlp_silent_path
|
||||||
|
local video_url = ''
|
||||||
|
local audio_url = ''
|
||||||
local video_url = '';
|
|
||||||
local audio_url = '';
|
|
||||||
|
|
||||||
-- Check if ytp-dlp-silent.exe exists, if not, fall back to Powershell
|
|
||||||
local yt_dlp_silent_exists = io.open(yt_dlp_silent_path, "r") ~= nil
|
local yt_dlp_silent_exists = io.open(yt_dlp_silent_path, "r") ~= nil
|
||||||
if not yt_dlp_silent_exists then
|
if not yt_dlp_silent_exists then
|
||||||
vlc.msg.info(yt_dlp_silent_path .. " not found. Falling back to " .. yt_dlp_path)
|
vlc.msg.info(yt_dlp_silent_path .. " not found. Falling back to " .. yt_dlp_path)
|
||||||
cmd_hidden = 'PowerShell.exe -windowstyle hidden cmd /c &'
|
cmd_hidden = 'PowerShell.exe -windowstyle hidden cmd /c &'
|
||||||
|
|
||||||
local cmd = string.format(
|
|
||||||
'%s "%s" -g %s',
|
|
||||||
cmd_hidden,
|
|
||||||
yt_dlp_path,
|
|
||||||
youtube_url
|
|
||||||
)
|
|
||||||
|
|
||||||
-- Execute yt-dlp to get the direct video and audio URLs
|
local cmd = string.format(
|
||||||
local handle = io.popen(cmd)
|
'%s "%s" -f \"%s\" -g %s',
|
||||||
|
cmd_hidden,
|
||||||
-- Read video URL (first line)
|
yt_dlp_path,
|
||||||
video_url = handle:read("*l")
|
format_string,
|
||||||
|
youtube_url
|
||||||
-- Read audio URL (second line)
|
)
|
||||||
audio_url = handle:read("*l")
|
|
||||||
|
|
||||||
handle:close()
|
|
||||||
else
|
|
||||||
vlc.msg.info(yt_dlp_silent_path .. " found. Running program")
|
|
||||||
local cmd = string.format(
|
|
||||||
'%s -s "%s -g %s"',
|
|
||||||
cmd_hidden,
|
|
||||||
yt_dlp_path,
|
|
||||||
youtube_url
|
|
||||||
)
|
|
||||||
|
|
||||||
local process = io.popen("start /B " .. cmd)
|
|
||||||
process:close()
|
|
||||||
|
|
||||||
-- Wait for yt-dlp-output.txt to be created
|
|
||||||
local output_file = "yt-dlp-output.txt"
|
|
||||||
local file_exists = false
|
|
||||||
local timeout = 0
|
|
||||||
local timeout_limit = 10 -- Timeout after 10 seconds
|
|
||||||
|
|
||||||
-- Check for file every 1 second until it's created
|
local handle = io.popen(cmd)
|
||||||
while not file_exists do
|
video_url = handle:read("*l")
|
||||||
local file_test = os.rename(output_file, output_file) -- Try renaming (checking file existence)
|
audio_url = handle:read("*l")
|
||||||
if file_test then
|
handle:close()
|
||||||
file_exists = true
|
else
|
||||||
else
|
vlc.msg.info(yt_dlp_silent_path .. " found. Running program")
|
||||||
-- Wait a little before trying again
|
local cmd = string.format(
|
||||||
vlc.msg.info("Waiting for output file...")
|
'%s -s "%s -f \"%s\" -g %s"',
|
||||||
sleep(1) -- Sleep for 1 second
|
cmd_hidden,
|
||||||
timeout = timeout + 1
|
yt_dlp_path,
|
||||||
if timeout > timeout_limit then
|
format_string,
|
||||||
vlc.msg.warn("Timeout reached. The output file was not created.")
|
youtube_url
|
||||||
break
|
)
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
vlc.msg.info("File found")
|
local process = io.popen("start /B " .. cmd)
|
||||||
-- Open the file to read the video and audio URLs
|
process:close()
|
||||||
local file = io.open(output_file, "r")
|
|
||||||
video_url = file:read("*l")
|
|
||||||
audio_url = file:read("*l")
|
|
||||||
file:close()
|
|
||||||
|
|
||||||
-- Delete the file after reading
|
local output_file = "yt-dlp-output.txt"
|
||||||
os.remove(output_file)
|
local file_exists = false
|
||||||
end
|
local timeout = 0
|
||||||
|
local timeout_limit = 10
|
||||||
vlc.msg.info("Video URL: " .. video_url)
|
|
||||||
vlc.msg.info("Audio URL: " .. audio_url)
|
while not file_exists do
|
||||||
|
local file_test = os.rename(output_file, output_file)
|
||||||
|
if file_test then
|
||||||
|
file_exists = true
|
||||||
|
else
|
||||||
|
vlc.msg.info("Waiting for output file...")
|
||||||
|
sleep(1)
|
||||||
|
timeout = timeout + 1
|
||||||
|
if timeout > timeout_limit then
|
||||||
|
vlc.msg.warn("Timeout reached. The output file was not created.")
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
vlc.msg.info("File found")
|
||||||
|
local file = io.open(output_file, "r")
|
||||||
|
video_url = file:read("*l")
|
||||||
|
audio_url = file:read("*l")
|
||||||
|
file:close()
|
||||||
|
os.remove(output_file)
|
||||||
|
end
|
||||||
|
|
||||||
-- Trim any whitespace
|
|
||||||
video_url = video_url and video_url:gsub("^%s+", ""):gsub("%s+$", "") or ""
|
video_url = video_url and video_url:gsub("^%s+", ""):gsub("%s+$", "") or ""
|
||||||
audio_url = audio_url and audio_url:gsub("^%s+", ""):gsub("%s+$", "") or ""
|
audio_url = audio_url and audio_url:gsub("^%s+", ""):gsub("%s+$", "") or ""
|
||||||
|
|
||||||
-- Log the resolved URLs
|
|
||||||
vlc.msg.info("[YouTube Resolver] Original URL: " .. youtube_url)
|
vlc.msg.info("[YouTube Resolver] Original URL: " .. youtube_url)
|
||||||
vlc.msg.info("[YouTube Resolver] Video URL: " .. video_url)
|
vlc.msg.info("[YouTube Resolver] Video URL: " .. video_url)
|
||||||
|
|
||||||
if audio_url and audio_url ~= "" then
|
if audio_url and audio_url ~= "" then
|
||||||
vlc.msg.info("[YouTube Resolver] Audio URL: " .. audio_url)
|
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
path = video_url,
|
path = video_url,
|
||||||
name = vlc.path .. " (Video)",
|
name = vlc.path .. " (Video)",
|
||||||
options = {
|
options = {
|
||||||
-- Add audio URL as input option
|
|
||||||
":input-slave=" .. audio_url
|
":input-slave=" .. audio_url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
vlc.msg.warn("[YouTube Resolver] No separate audio URL found. Playing single URL with both video and audio.")
|
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
path = video_url,
|
path = video_url,
|
||||||
|
|||||||
Reference in New Issue
Block a user