45 lines
1.3 KiB
PowerShell
45 lines
1.3 KiB
PowerShell
function Download-YTDLP {
|
|
Param(
|
|
[Parameter(Mandatory=$true)]
|
|
[string]$videoUrl,
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
[string]$OutputPath,
|
|
|
|
[string]$RejectString,
|
|
|
|
[switch]$WithCookies
|
|
)
|
|
|
|
$ytDlpPath = "D:\yt-dlp\yt-dlp.exe"
|
|
|
|
# Start building an array of arguments using strict comma separation (Recommended format)
|
|
$arguments = @(
|
|
$videoUrl,
|
|
"--write-info-json",
|
|
"--write-thumbnail",
|
|
"--convert-thumbnails", "jpg",
|
|
"--no-progress",
|
|
"-t", "sleep",
|
|
"--rate-limit", "5M",
|
|
"-o", $OutputPath,
|
|
'-f', "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best",
|
|
"-S", "vcodec:h264",
|
|
"--reject-title", $RejectString,
|
|
"--playlist-reverse"
|
|
)
|
|
|
|
# --- Conditional Logic Applied Here ---
|
|
if ($WithCookies) {
|
|
Write-Verbose "--- Using browser cookies for download. ---" -Verbose
|
|
$arguments += "--cookies-from-browser", "firefox" # Added comma here too
|
|
} else {
|
|
Write-Verbose "--- Downloading without specific cookie credentials. ---" -Verbose
|
|
}
|
|
|
|
# Execute yt-dlp using the call operator (&) and passing the arguments array (@)
|
|
& $ytDlpPath $arguments
|
|
}
|
|
|
|
# Example Usage:
|
|
# Download-Video -videoUrl "URL_HERE" -OutputPath "./output" -WithCookies |