catbox_downloader/downloader.ps1

101 lines
No EOL
2 KiB
PowerShell

#Requires -Version 7
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2023 v5.8.227
Created on: 2024/01/08 12:09:49 AM
Created by: yuuki
Organization:
Filename: downloader.ps1
===========================================================================
.DESCRIPTION
Downloader for my Catbox game uploads.
#>
class Catbox {
Catbox()
{
}
[void]Download()
{
Get-ChildItem -Path "./" -Filter "y2k12-*.txt" |
Foreach-Object {
$index = 0
$fileNames = @()
$content = Get-Content $_.FullName
$links = ""
ForEach ($line in $($content -Split "`r`n"))
{
If ($line.StartsWith("mv "))
{
$f = $line.Substring($line.IndexOf('y2k12-'))
$fileNames += $f
}
}
ForEach ($line in $($content -Split "`r`n"))
{
If ($line.StartsWith("https://files.catbox.moe/"))
{
$f = $line.Substring($line.IndexOf(".moe/") + 5)
If ([System.IO.File]::Exists($fileNames[$index]))
{
Write-Host "File already downloaded."
}
Else
{
Write-Host "Downloading" $fileNames[$index] "(" $line ")"
Invoke-WebRequest -Uri $line -OutFile $fileNames[$index]
}
$index += 1
}
}
}
}
}
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()
}