From b5c6cfddc79ae4c90b62a9037e5fe66ebd9c2a00 Mon Sep 17 00:00:00 2001 From: Alex Kup <116945542+Lifailon@users.noreply.github.com> Date: Sat, 4 Nov 2023 01:41:34 +0300 Subject: [PATCH] add module download image using jobs --- Scripts/Download-Image.psm1 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Scripts/Download-Image.psm1 diff --git a/Scripts/Download-Image.psm1 b/Scripts/Download-Image.psm1 new file mode 100644 index 0000000..e47079e --- /dev/null +++ b/Scripts/Download-Image.psm1 @@ -0,0 +1,31 @@ +function Download-Image { +param ( + [Parameter(Mandatory = $True)]$url +) + $folder = $url -replace "http.+://" -replace "/","-" -replace "-$" + $path = "$home\Pictures\$folder" + if (Test-Path $path) { + Remove-Item $path -Recurse -Force + New-Item -ItemType Directory $path > $null + } else { + New-Item -ItemType Directory $path > $null + } + $irm = Invoke-WebRequest -Uri $url + foreach ($img in $irm.Images.src) { + $name = $img -replace ".+/" + Start-Job { + Invoke-WebRequest $using:img -OutFile "$using:path\$using:name" + } > $null + } + while ($True){ + $status_job = (Get-Job).State[-1] + if ($status_job -like "Completed"){ + Get-Job | Remove-Job -Force + break + }} + $count_all = $irm.Images.src.Count + $count_down = (Get-Item $path\*).count + "Downloaded $count_down of $count_all files to $path" +} + +# Download-Image -url https://losst.pro/ \ No newline at end of file