Created
November 9, 2024 06:46
-
-
Save alighafoori/00008f94bd56ab5b2d2b304c73a589c0 to your computer and use it in GitHub Desktop.
check yt-dlp for new version and then download video from youtube
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define the GitHub API URL for yt-dlp releases | |
$repoUrl = "https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest" | |
# Enter your GitHub token here (to avoid rate limits) | |
$githubToken = "your_personal_access_token_here" | |
# Function to check and update yt-dlp | |
function Update-ytDlp { | |
# Send a web request to get the latest release data from GitHub | |
$response = Invoke-RestMethod -Uri $repoUrl -Headers @{ | |
"User-Agent" = "PowerShell" | |
"Authorization" = "token $githubToken" | |
} | |
# Extract the latest version tag | |
$latestVersion = $response.tag_name | |
Write-Output "Latest yt-dlp version: $latestVersion" | |
# Check if yt-dlp exists locally and get its version | |
if (Test-Path -Path ".\yt-dlp.exe") { | |
# Get the local version by running yt-dlp and checking the output | |
$localVersion = .\yt-dlp.exe --version | |
Write-Output "Local yt-dlp version: $localVersion" | |
# Compare local version with the latest release version | |
if ($localVersion -ne $latestVersion) { | |
Write-Output "A new version of yt-dlp is available: $latestVersion" | |
# Download the latest version | |
$downloadUrl = ($response.assets | Where-Object { $_.name -like "yt-dlp.exe" }).browser_download_url | |
$outputPath = ".\yt-dlp.exe" | |
Write-Output "Downloading latest version from $downloadUrl..." | |
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputPath -Headers @{ "User-Agent" = "PowerShell" } | |
Write-Output "yt-dlp has been updated to version $latestVersion." | |
} else { | |
Write-Output "You already have the latest version of yt-dlp." | |
} | |
} else { | |
Write-Output "yt-dlp is not found locally. Downloading the latest version." | |
# Download the latest version as yt-dlp.exe | |
$downloadUrl = ($response.assets | Where-Object { $_.name -like "yt-dlp.exe" }).browser_download_url | |
$outputPath = ".\yt-dlp.exe" | |
Write-Output "Downloading latest version from $downloadUrl..." | |
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputPath -Headers @{ "User-Agent" = "PowerShell" } | |
Write-Output "yt-dlp has been installed at version $latestVersion." | |
} | |
} | |
# Run the Update function to check and update yt-dlp | |
Update-ytDlp | |
# Read URLs from urls.txt for downloading | |
$urls = Get-Content -Path "urls.txt" | |
# Loop through each URL in urls.txt | |
foreach ($line in $urls) { | |
# Check if the line ends with 'mp3' | |
if ($line -match "mp3$") { | |
# Extract the actual URL part | |
$url = $line -replace "\s+mp3$", "" | |
# Download only audio as mp3 | |
.\yt-dlp --ffmpeg-location "G:\y\ffmpeg\bin" --cookies "G:\y\ffmpeg\y.txt" ` | |
--extract-audio --audio-format mp3 $url --proxy socks5://127.0.0.1:10809 --paths "G:\y" | |
} else { | |
# Treat the entire line as a URL for video download | |
$url = $line | |
# Download video with 1080p quality or lower | |
.\yt-dlp --ffmpeg-location "G:\y\ffmpeg\bin" --cookies "G:\y\ffmpeg\y.txt" ` | |
-f "bestvideo[height<=1080]+bestaudio/best[height<=1080]" $url --embed-subs en --write-auto-subs --write-subs ` | |
--proxy socks5://127.0.0.1:10809 --paths "G:\y" | |
} | |
} | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment