Skip to content

Instantly share code, notes, and snippets.

@quad-damage
Created October 24, 2023 16:28
Show Gist options
  • Save quad-damage/e9f7e048688c5f616ee28b67a27aef76 to your computer and use it in GitHub Desktop.
Save quad-damage/e9f7e048688c5f616ee28b67a27aef76 to your computer and use it in GitHub Desktop.
YT-DLP Setup Script
$Global:WorkingDir = $null
clear
function Create-WorkingDir {
mkdir ytdlp | Out-Null
cd ytdlp | Out-Null
}
function Update-WorkingDir {
$Global:WorkingDir = Get-Location
}
function Check-WorkingDir {
Update-WorkingDir
if ((Get-ChildItem -Path $WorkingDir -Force | Measure-Object).Count -ne 0) {
echo(" ")
echo "The current working directory($Global:WorkingDir) isn't empty. Would you like to create a new one?"
$ChangeWorkingDir = Read-Host "(y - Create new folder | n - Download and setup in current directory)"
if ($ChangeWorkingDir -eq 'y') {
Create-WorkingDir
Check-WorkingDir
}
}
}
function Download-YTDLP {
wget "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe" -OutFile "yt-dlp.exe"
}
function Download-FFmpeg-Choice {
echo(" ")
echo("FFmpeg is required by yt-dlp to work correctly. If you already have FFmpeg downloaded and added to path,")
echo("you can skip this step. Downloading FFmpeg might take a long time. Would you like to download FFmpeg?");
$DownloadFFmpeg = Read-Host "(y - Download FFmpeg and extract it here | n - Don't download FFmpeg)"
if ($DownloadFFmpeg -eq 'y') {
wget "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip" -OutFile "ffmpeg-release-essentials.zip"
Expand-Archive ".\ffmpeg-release-essentials.zip" -DestinationPath ".\ffmpeg-release-essentials"
mv ".\ffmpeg-release-essentials\*\bin\*.exe" ".\"
rm ".\ffmpeg-release-essentials.zip"
rm ".\ffmpeg-release-essentials\" -Recurse
}
}
Check-WorkingDir
Download-YTDLP
Download-FFmpeg-Choice
echo("@echo off") | Out-File "download.bat" -Encoding ascii
echo("title YT-DLP Download MP4") | Out-File "download.bat" -Encoding ascii -NoClobber -Append
echo("set /p `"link=Download video > `"") | Out-File "download.bat" -Encoding ascii -NoClobber -Append
echo("yt-dlp.exe --update > nul") | Out-File "download.bat" -Encoding ascii -NoClobber -Append
echo("yt-dlp.exe -f bestvideo --format mp4 --add-metadata --embed-thumbnail %link%") | Out-File "download.bat" -Encoding ascii -NoClobber -Append
echo("@echo off") | Out-File "download-mp3.bat" -Encoding ascii
echo("title YT-DLP Download MP3") | Out-File "download-mp3.bat" -Encoding ascii -NoClobber -Append
echo("set /p `"link=Download audio > `"") | Out-File "download-mp3.bat" -Encoding ascii -NoClobber -Append
echo("yt-dlp.exe --update > nul") | Out-File "download-mp3.bat" -Encoding ascii -NoClobber -Append
echo("yt-dlp.exe -f bestaudio -x --audio-format mp3 --audio-quality 0 --add-metadata --embed-thumbnail %link%") | Out-File "download-mp3.bat" -Encoding ascii -NoClobber -Append
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment