Guest User

Untitled

a guest
Aug 8th, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. param (
  2. [string]$Url # URL passed as a parameter
  3. )
  4.  
  5. # Define the path to the yt-dlp binary
  6. $ytDlpPath = "D:\yt-dlp\yt-dlp.exe" # Change this to the actual path of yt-dlp
  7.  
  8. # Define the maximum number of retries
  9. $maxRetries = 50
  10.  
  11. # Function to run yt-dlp
  12. function Run-YtDlp {
  13. Write-Host "Starting yt-dlp with URL: $Url (Attempt: $($retryCount + 1))"
  14.  
  15. # Start the process and wait for it to exit
  16. $arguments = "$Url --cookies-from-browser firefox"
  17. $process = Start-Process -FilePath $ytDlpPath -ArgumentList $arguments -NoNewWindow -PassThru
  18. $process.WaitForExit()
  19.  
  20. Write-Host "yt-dlp stopped."
  21. }
  22.  
  23. # Main loop to retry yt-dlp
  24. do {
  25. Run-YtDlp
  26. $retryCount++
  27.  
  28. if ($retryCount -lt $maxRetries) {
  29. Write-Host "Retrying in 5 seconds..."
  30. Start-Sleep -Seconds 5 # Optional: wait before retrying
  31.  
  32. # Reset the retry count if the process successfully restarts
  33. if ($process.HasExited -eq $false) {
  34. Write-Host "yt-dlp restarted successfully. Resetting retry count."
  35. $retryCount = 0
  36. }
  37. }
  38. } while ($retryCount -lt $maxRetries)
  39.  
  40. Write-Host "yt-dlp stopped after $retryCount attempts. Exiting."
  41. exit 0
Advertisement
Add Comment
Please, Sign In to add comment