Created
June 25, 2024 21:34
-
-
Save mattiasghodsian/45ea5dd29c7af2053ec551cc9343b5c5 to your computer and use it in GitHub Desktop.
[PowerShell] Bulk File Downloader
This file contains 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
# Author: Mattias Ghodsian | |
# Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5 | |
# Donate coffee: https://www.buymeacoffee.com/mattiasghodsian | |
# Example: .\BulkDownloader.ps1 -urlTemplate "https://example/uploads/AUDIO/book/**.mp3" -maxInterval 54 | |
param ( | |
[string]$urlTemplate, # URL template with ** | |
[int]$maxInterval # Maximum interval number | |
) | |
# Get the current directory | |
$destination = Get-Location | |
for ($i = 1; $i -le $maxInterval; $i++) { | |
$formattedInterval = "{0:D2}" -f $i # Format the interval as two digits | |
$url = $urlTemplate -replace '\*\*', $formattedInterval | |
$fileName = [System.IO.Path]::GetFileName($url) | |
$destinationFilePath = Join-Path -Path $destination -ChildPath $fileName | |
try { | |
Write-Host "Downloading $url to $destinationFilePath" | |
Invoke-WebRequest -Uri $url -OutFile $destinationFilePath | |
Write-Host "Downloaded $fileName successfully." | |
} catch { | |
Write-Host "Failed to download $url" | |
} | |
# Wait for the file to be fully downloaded | |
while (-not (Test-Path $destinationFilePath)) { | |
Start-Sleep -Seconds 1 | |
} | |
} | |
Write-Host "All downloads completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment