Skip to content

Instantly share code, notes, and snippets.

@HotoRas
Created March 14, 2023 04:25
Show Gist options
  • Save HotoRas/03b589692ce0c5f2f5d56dffb494874f to your computer and use it in GitHub Desktop.
Save HotoRas/03b589692ce0c5f2f5d56dffb494874f to your computer and use it in GitHub Desktop.
The yt-dlp launch script for Windows Powershell.
# yt-dlp launcher
### Scripting trick:
### `"` is multiline! You can write multiline with just covering with `"`.
## Step 1. Set the batch path to where this `.ps1` is.
### TIP: This script is written assuming that it's placed with yt-dlp.
### You'd like to change the path part (`(Split-Path ~ .path)`)
### to where yt-dlp binary is.
### Example:
### If yt-dlp is C:\yt-dlp\yt-dlp.exe and the script is at %userprofile%\Downloads:
### cd C:\yt-dlp
cd (Split-Path ($MyInvocation.MyCommand).path)
## Step 2. Get URI and set as variable
### NOTE: You don't have to hardcode the URL. This script will get it when launched.
$uri = Read-Host -Prompt "Please paste the video URL you're about to download here"
## Step 3. Update yt-dlp
echo "
Updating yt-dlp... Please wait.
"
### Powershell doesn't trust the file at the same directory the console is pointing.
### With using .\ Powershell will trust the file since directory is defined,
### and in the end, launch it.
.\yt-dlp.exe -U
## Step 4. Run download
echo "yt-dlp is up-to-date: Now this'll download the video you've specified.
Downloading $uri...
"
### NOTE:
### 1. For some situations, the browser cookies are used to handle login features.
### yt-dlp will handle the login with ID/PASS, but handling with 2nd factor
### authentification is nearly impossible.
### So the browser cookie is used.
### 2. FFMPEG directory is set to `\ffmpeg\bin`. You can modify this.
### If you don't set, yt-dlp will try to launch FFMPEG
### as if it was at the same directory with FFMPEG.
### If the installation location is different, you should change it
### to where you've downloaded.
### 3. Browser profile is set to `Default`, the default profile for Chromium.
### If you're using different browser or profile, you should change it.
### Avaliable browsers are: brave, chrome, chromium, edge, firefox, opera, safari, vivaldi
#.\yt-dlp.exe $uri --cookies-from-browser chrome:Default #command when at ffmpeg bin dir
.\yt-dlp.exe $uri --ffmpeg-location="\ffmpeg\bin" --cookies-from-browser chrome:Default #command when ffmpeg at different dir
## Step 5. A quick pause to check the log
pause
@HotoRas
Copy link
Author

HotoRas commented Mar 14, 2023

Before launch:

Programs required:

- yt-dlp
- ffmpeg
  1. Unzip yt-dlp. (Tested: E:\Tools\yt-dlp\. Placing around C:\ would work.)
  2. Unzip ffmpeg and remember the directory. (Tested: E:\ffmpeg\bin\ Placing around C:\ would work.)
  3. Create the .ps1 script file and double-click to open it with notepad.
  4. Paste this gist and save it. Please set the encoding as UTF-8 for some irregular situations.
  5. Modify the strings like --ffmpeg-location="location" or --cookies-from-browser BROWSER:PROFILE to what matches to your environment.
  6. (If YouTube and you're to download Secret/Membership content, or you subscribed on Twitch channel/Nitro and you don't want the records containing ad breaks) Please log-in first to the channel you're using to the defined browser.
  7. Open the command prompt (or powershell or wsl bash or anything) and launch it as:
powershell PATH-TO-YOUR-PS1-FILE

(Example if the shell points to the directory the ps1 file (launch.ps1) exists: powershell .\launch.ps1)

@HotoRas
Copy link
Author

HotoRas commented Jan 11, 2024

WARNING: THIS SCRIPT IS DEPRECATED AND NOW DOESN'T WORK ON LATEST WINDOWS 11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment