From df5dc8240dc83b1c01f17187d63c22ce6bfc1173 Mon Sep 17 00:00:00 2001 From: Yuuki Chan Date: Thu, 18 Jul 2024 11:59:29 +0900 Subject: [PATCH] Updated to accept first argument as a URL. E.g. https://raiza.dev/Downloads/y2k12-something.txt --- Catbox Downloader.psprojs | 1 - downloader.ps1 | 41 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Catbox Downloader.psprojs b/Catbox Downloader.psprojs index 9d25784..58f8b3a 100644 --- a/Catbox Downloader.psprojs +++ b/Catbox Downloader.psprojs @@ -4,6 +4,5 @@ downloader.ps1 - Startup.pss \ No newline at end of file diff --git a/downloader.ps1 b/downloader.ps1 index 7fa4fa2..136e306 100644 --- a/downloader.ps1 +++ b/downloader.ps1 @@ -60,5 +60,42 @@ class Catbox { } } -$catbox = [Catbox]::new() -$catbox.Download() +If ($args.Length -eq 1 -and $args[0] -and $args[0].ToString().Contains("https://raiza.dev/Downloads/y2k12-") -and $args[0].ToString().EndsWith(".txt")) +{ + $statuscode = 404 + $file = $null + + try + { + $statuscode = (Invoke-WebRequest -Uri $args[0] -UseBasicParsing | Select-Object StatusCode).StatusCode + $file = $args[0].Substring($args[0].IndexOf(".dev/Downloads/") + 15) + + Write-Host "Downloading" $file "..." + } + catch + { + $statuscode = 404 + $file = $null + } + finally + { + If ($statuscode -eq 200 -and $file) + { + Invoke-WebRequest -Uri $args[0] -OutFile $file + + Write-Host "" + + $catbox = [Catbox]::new() + $catbox.Download() + } + Else + { + Write-Host "File not found on the server." + } + } +} +Else +{ + $catbox = [Catbox]::new() + $catbox.Download() +} \ No newline at end of file