<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Download a Youtube video by passing the URL as a parameter]]></title><description><![CDATA[<p dir="auto">I made this <a href="https://youtu.be/KqfRiPy5gFs" rel="nofollow ugc">YouTube video</a> to show how this works.</p>
<p dir="auto">Make sure to adjust the folder paths.  I doubt you'll put your script in d:\appdev\triggercmd\youtube-dl or put your downloaded files in m:\videos\youtube like I did.</p>
<p dir="auto">Create a folder, open a cmd window in that folder, and type these to create the virtual environment with the yt_dlp python module:</p>
<pre><code>python3 -m venv myenv
myenv\Scripts\activate.bat
pip3 install yt_dlp
</code></pre>
<p dir="auto"><strong>youtube-dl.bat contents:</strong></p>
<pre><code class="language-@echo">setlocal enabledelayedexpansion

:: This version of the script differs from the one in the Youtube video in that it handles any of these Youtube URL formats:
:: https://www.youtube.com/watch?v=KqfRiPy5gFs
:: https://youtu.be/KqfRiPy5gFs
:: KqfRiPy5gFs

:: Combine all arguments into a single string
set "input="
for %%A in (%*) do (
    set "input=!input! %%A"
)

:: Remove leading spaces
set "input=%input:~1%"

:: Check if the input contains "youtu.be" format and extract the video ID
echo %input% | findstr /C:"youtu.be" &gt;nul
if not errorlevel 1 (
    set "id=%input:~17%"  :: Strip "https://youtu.be/"
)

:: Check if the input contains "youtube.com/watch?v=" format and extract the video ID
if not defined id (
    echo %input% | findstr /C:"youtube.com/watch?v=" &gt;nul
    if not errorlevel 1 (
        set "id=%input:~32%"  :: Strip "https://www.youtube.com/watch?v="
    )
)

:: If input is just the ID, no need for stripping
if not defined id (
    set "id=%input%"
)

:: Ensure the ID is exactly 11 characters long
set "id=%id:~0,11%"

echo YouTube Video ID: %id%

:: Go to the folder where I want the files to be created
cd /d m:\videos\youtube

:: Activate the Python virtual environment that has the yt_dlp module installed
call d:\appdev\triggercmd\youtube-dl\myenv\Scripts\activate.bat

:: Run the python script to download the video and metadata
python d:\appdev\triggercmd\youtube-dl\youtube-dl.py %id%  &gt; debug.log 2&gt;&amp;1
</code></pre>
<p dir="auto"><strong><a href="http://youtube-dl.py" rel="nofollow ugc">youtube-dl.py</a> contents:</strong></p>
<pre><code>import yt_dlp
import json, uuid, sys

def download_video_metadata(video_url):
    ydl_opts = {
        'quiet': True,
        'skip_download': True,
        'force_generic_extractor': False,
    }
    
    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        try:
            info_dict = ydl.extract_info(video_url, download=False)
            return info_dict
        except Exception as e:
            print(f"Error: {e}")
            return None

def download_video(video_url):
    ydl_opts = {
        'quiet': False,
        'outtmpl': '%(title)s.%(ext)s',
    }
    
    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        try:
            ydl.download([video_url])
        except Exception as e:
            print(f"Error: {e}")

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python3 youtube-dl.py &lt;YouTube Video URL&gt;")
        sys.exit(1)

    video_url = sys.argv[1]
    metadata = download_video_metadata(video_url)
    
    if metadata:
        print("Metadata:")

        filename=metadata.get('title', uuid.uuid4()) + ".json"
        with open(filename, "w") as file:
            json.dump(metadata, file, indent=4)

        print("Downloading video...")
        download_video(video_url)
</code></pre>
<p dir="auto">Make sure you enable parameters:<br />
<img src="/forum/assets/uploads/files/1743379672751-9f121796-6f1f-4241-9d2e-c0e83a221fc2-image.png" alt="9f121796-6f1f-4241-9d2e-c0e83a221fc2-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">If you want to create a panel, you can use this regex to accept any text:  ^.*$<br />
<img src="/forum/assets/uploads/files/1743379762238-8ac7a7eb-9e94-44e6-b259-93c72efd841c-image.png" alt="8ac7a7eb-9e94-44e6-b259-93c72efd841c-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://www.triggercmd.com/forum/topic/3232/download-a-youtube-video-by-passing-the-url-as-a-parameter</link><generator>RSS for Node</generator><lastBuildDate>Wed, 12 Aug 2026 02:11:33 GMT</lastBuildDate><atom:link href="https://www.triggercmd.com/forum/topic/3232.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 31 Mar 2025 00:05:39 GMT</pubDate><ttl>60</ttl></channel></rss>