Jump to content

Recommended Posts

Posted

The LUA script yt-dlp4vlc reads the video quality preset by the user in VLC's settings only once while starting the player. If this setting is changed by the user at some point, the player has of course to be restarted to take the new setting into account. :P


Posted (edited)

Since the ytdlp-silent-xp.exe file for starting yt-dlp hidden provided by FalloNero is still not working, I modified the code again and cleaned up all unnecessary lines of code. From now on, my PowerShell command "PowerShell.exe -windowstyle hidden cmd /c &" will be executed in the case the hidecon.exe file doesn't exist. If, however, the hidecon.exe file is present in the main folder of VLC, my reduced hidecon command "hidecon &" will be used instead to start yt-dlp hidden. Here is my new mod of the LUA script yt-dlp4vlc:

-- YouTube Link Resolver for VLC with Separate Video and Audio URLs
-- Place this script in VLC's lua/playlist directory

local yt_dlp_path = 'yt-dlp.exe'
local yt_dlp_silent_path = 'hidecon.exe'

function sleep(s)
    local ntime = os.time() + s
    repeat until os.time() > ntime
end

function probe()
    -- Check if the input is a YouTube link
    return vlc.access == "http" or vlc.access == "https" and 
           (string.match(vlc.path, "youtube%.com") or string.match(vlc.path, "youtu%.be"))
end

function parse()
    -- Construct the full YouTube URL
    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 &

    -- Get the preferred resolution preset by the user in VLC
    local prefres = vlc.var.inherit(nil, "preferred-resolution")
    if prefres < 0 then
        prefres = 2160 -- Best quality set to 2160p to overwrite VLC's native value of -1
    end

    local allowed_qualities = {
        ["240"] = true,
        ["360"] = true,
        ["480"] = true,
        ["720"] = true,
        ["1080"] = true,
        ["2160"] = true
    }

    -- Default quality limited to the preferred resolution taken from VLC's settings
    local format_string = string.format("bestvideo[height<=%i]+bestaudio", prefres)
  
    if quality and allowed_qualities[quality] then
        format_string = string.format("bestvideo[height<=%i]+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 = 'hidecon &' -- Start cmd hidden and ...
    -- No better codec than h264 (an important switch for older hardware). This can of course be changed by the users according to their needs.
    local codec_limit = '-S "codec:h264"'
    local video_url = ''
    local audio_url = ''

    local yt_dlp_silent_exists = io.open(yt_dlp_silent_path, "r") ~= nil
    if not yt_dlp_silent_exists then
        vlc.msg.info(yt_dlp_silent_path .. " not found. Falling back to " .. yt_dlp_path)
        cmd_hidden = 'PowerShell.exe -windowstyle hidden cmd /c &' -- Start cmd hidden and ...
        local cmd = string.format(
            '%s "%s" %s -f \"%s\" -g "%s"',
            cmd_hidden,
            yt_dlp_path,
            codec_limit,
            format_string,
            youtube_url
        )
        local handle = io.popen(cmd)
        video_url = handle:read("*l")
        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 -f \"%s\" -g "%s"',
            cmd_hidden,
            yt_dlp_path,
            codec_limit,
            format_string,
            youtube_url
        )
        local handle = io.popen(cmd)
        video_url = handle:read("*l")
        audio_url = handle:read("*l")
        handle:close()
    end

    video_url = video_url and video_url:gsub("^%s+", ""):gsub("%s+$", "") or ""
    audio_url = audio_url and audio_url:gsub("^%s+", ""):gsub("%s+$", "") or ""

    vlc.msg.info("[YouTube Resolver] Original URL: " .. youtube_url)
    vlc.msg.info("[YouTube Resolver] Video URL: " .. video_url)

    if audio_url and audio_url ~= "" then
        return {
            {
                path = video_url,
                name = vlc.path .. " (Video)",
                options = {
                    ":input-slave=" .. audio_url
                }
            }
        }
    else
        return {
            {
                path = video_url,
                name = vlc.path .. " (Video + Audio)"
            }
        }
    end
end


Cheers, AstroSkipper matrix.gif

Edited by AstroSkipper
Posted (edited)
On 1/3/2026 at 3:49 PM, AstroSkipper said:

Since the ytdlp-silent-xp.exe file for starting yt-dlp hidden provided by FalloNero is still not working, I modified the code again and cleaned up all unnecessary lines of code. From now on, my PowerShell command "PowerShell.exe -windowstyle hidden cmd /c &" will be executed in the case the hidecon.exe file doesn't exist. If, however, the hidecon.exe file is present in the main folder of VLC, my reduced hidecon command "hidecon &" will be used instead to start yt-dlp hidden. Here is my new mod of the LUA script yt-dlp4vlc:

-- YouTube Link Resolver for VLC with Separate Video and Audio URLs
-- Place this script in VLC's lua/playlist directory

local yt_dlp_path = 'yt-dlp.exe'
local yt_dlp_silent_path = 'hidecon.exe'

function sleep(s)
    local ntime = os.time() + s
    repeat until os.time() > ntime
end

function probe()
    -- Check if the input is a YouTube link
    return vlc.access == "http" or vlc.access == "https" and 
           (string.match(vlc.path, "youtube%.com") or string.match(vlc.path, "youtu%.be"))
end

function parse()
    -- Construct the full YouTube URL
    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 &

    -- Get the preferred resolution preset by the user in VLC
    local prefres = vlc.var.inherit(nil, "preferred-resolution")
    if prefres < 0 then
        prefres = 2160 -- Best quality set to 2160p to overwrite VLC's native value of -1
    end

    local allowed_qualities = {
        ["240"] = true,
        ["360"] = true,
        ["480"] = true,
        ["720"] = true,
        ["1080"] = true,
        ["2160"] = true
    }

    -- Default quality limited to the preferred resolution taken from VLC's settings
    local format_string = string.format("bestvideo[height<=%i]+bestaudio", prefres)
  
    if quality and allowed_qualities[quality] then
        format_string = string.format("bestvideo[height<=%i]+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 = 'hidecon &' -- Start cmd hidden and ...
    -- No better codec than h264 (an important switch for older hardware). This can of course be changed by the users according to their needs.
    local codec_limit = '-S "codec:h264"'
    local video_url = ''
    local audio_url = ''

    local yt_dlp_silent_exists = io.open(yt_dlp_silent_path, "r") ~= nil
    if not yt_dlp_silent_exists then
        vlc.msg.info(yt_dlp_silent_path .. " not found. Falling back to " .. yt_dlp_path)
        cmd_hidden = 'PowerShell.exe -windowstyle hidden cmd /c &' -- Start cmd hidden and ...
        local cmd = string.format(
            '%s "%s" %s -f \"%s\" -g "%s"',
            cmd_hidden,
            yt_dlp_path,
            codec_limit,
            format_string,
            youtube_url
        )
        local handle = io.popen(cmd)
        video_url = handle:read("*l")
        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 -f \"%s\" -g "%s"',
            cmd_hidden,
            yt_dlp_path,
            codec_limit,
            format_string,
            youtube_url
        )
        local handle = io.popen(cmd)
        video_url = handle:read("*l")
        audio_url = handle:read("*l")
        handle:close()
    end

    video_url = video_url and video_url:gsub("^%s+", ""):gsub("%s+$", "") or ""
    audio_url = audio_url and audio_url:gsub("^%s+", ""):gsub("%s+$", "") or ""

    vlc.msg.info("[YouTube Resolver] Original URL: " .. youtube_url)
    vlc.msg.info("[YouTube Resolver] Video URL: " .. video_url)

    if audio_url and audio_url ~= "" then
        return {
            {
                path = video_url,
                name = vlc.path .. " (Video)",
                options = {
                    ":input-slave=" .. audio_url
                }
            }
        }
    else
        return {
            {
                path = video_url,
                name = vlc.path .. " (Video + Audio)"
            }
        }
    end
end


Cheers, AstroSkipper matrix.gif

For anyone who isn't familiar with LUA scripts. My mod of the LUA script yt-dlp4vlc does the following:

  • YouTube links entered in VLC are now processed by the YouTube downloader yt-dlp and are then transferred to VLC and played back. Credits to FalloNero.
  • The console window is hidden either by a PowerShell command or by the tool hidecon if the latter exists in VLC's programme folder.
  • Video links without appended quality parameter can now be played again with the quality preset by the user in the VLC settings.
  • The default video codec has been preset by me to h264 so that even older hardware is supported. This can of course be changed in the script by the users according to their needs.
Edited by AstroSkipper
Posted (edited)
56 minutes ago, VistaLover said:

Does this refer to yesterday's latest offering :dubbio:?

https://github.com/FalloNero/yt-dlp4vlc/commit/93ad2eeffdcdaf2cc0a6ef685b57399d7787c789

(built with VC2005 ?)

Yes. All builds of ytdlp-silent-xp.exe have been tested by me on my Windows XP computer. Unfortunately, none of them are working, not even the latest.

Edited by AstroSkipper

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...