Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param (
- [string]$Url # URL passed as a parameter
- )
- # Define the path to the yt-dlp binary
- $ytDlpPath = "D:\yt-dlp\yt-dlp.exe" # Change this to the actual path of yt-dlp
- # Define the maximum number of retries
- $maxRetries = 50
- # Function to run yt-dlp
- function Run-YtDlp {
- Write-Host "Starting yt-dlp with URL: $Url (Attempt: $($retryCount + 1))"
- # Start the process and wait for it to exit
- $arguments = "$Url --cookies-from-browser firefox"
- $process = Start-Process -FilePath $ytDlpPath -ArgumentList $arguments -NoNewWindow -PassThru
- $process.WaitForExit()
- Write-Host "yt-dlp stopped."
- }
- # Main loop to retry yt-dlp
- do {
- Run-YtDlp
- $retryCount++
- if ($retryCount -lt $maxRetries) {
- Write-Host "Retrying in 5 seconds..."
- Start-Sleep -Seconds 5 # Optional: wait before retrying
- # Reset the retry count if the process successfully restarts
- if ($process.HasExited -eq $false) {
- Write-Host "yt-dlp restarted successfully. Resetting retry count."
- $retryCount = 0
- }
- }
- } while ($retryCount -lt $maxRetries)
- Write-Host "yt-dlp stopped after $retryCount attempts. Exiting."
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment