Created
March 18, 2023 15:44
-
-
Save vt-idiot/d916cac88e939d3edc08036f9eb6f41f to your computer and use it in GitHub Desktop.
Upload Catbox Album
This file contains hidden or 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
<# | |
.Description | |
an idiot's catbox album uploader v0.1 | |
.PARAMETER DirectoryPath | |
Where da files at? Script will upload all PNGs in the folder you point it at! | |
.PARAMETER UserHash | |
Your catbox userhash. If not specified, your albums cannot be edited or deleted after uploading. | |
.PARAMETER Title | |
Sets the title for your album, defaults to "Title" if not specified. | |
.PARAMETER Description | |
Sets the description for your album, defaults to "Description" if not specified. | |
.INPUTS | |
Images | |
.OUTPUTS | |
Individual Catbox URLs + an album URL. | |
.EXAMPLE | |
PS> .\catboxalbum.ps1 -DirectoryPath .\spacelumi | |
Uploads all the .png in .\spacelumi to a new, anonymous album with title "Title" and description "Description" | |
.EXAMPLE | |
PS> .\catboxalbum.ps1 -DirectoryPath .\ | |
Uploads all the .png in your current directory to a new, anonymous album with title "Title" and description "Description" | |
.EXAMPLE | |
PS> .\catboxalbum.ps1 -DirectoryPath C:\pictures\marinecenteropening -UserHash "17secondseason" -Title "ahoy" -Description "center opening, my beloved" | |
Uploads all the files in C:\pictures\marinecenteropening to a new album with the title "ahoy" and the shown description. Album can be edited and deleted because a userhash was supplied | |
.LINK | |
Source : https://gist.github.com/vt-idiot/ | |
.SYNOPSIS | |
1. Take a folder full of images | |
2. Upload them to catbox | |
3. Make an album | |
#> | |
param( | |
[Parameter(Mandatory=$true)] | |
[string]$DirectoryPath, | |
[string]$UserHash, | |
[string]$Title = "Title", | |
[string]$Description = "Description" | |
) | |
# Get the files in the directory | |
$files = Get-ChildItem -Path $DirectoryPath -File -Filter *.png | |
# Array to store uploaded file URLs | |
$fileUrls = @() | |
# Loop through each file and upload it | |
foreach ($file in $files) { | |
Write-Host "Uploading file $($file.Name)..." | |
$params = @{ | |
'reqtype' = 'fileupload' | |
'fileToUpload' = Get-Item $file | |
} | |
if ($UserHash) { | |
$params.Add('userhash', $UserHash) | |
} | |
try { | |
$response = Invoke-WebRequest -Uri "https://catbox.moe/user/api.php" -Method POST -Form $params -ErrorAction Stop | |
if ($response.StatusCode -eq 200) { | |
$fileUrl = $response.Content.Trim() | |
$fileUrls += $fileUrl | |
Write-Host "File $($file.Name) uploaded successfully. URL: $fileUrl" | |
} else { | |
Write-Host "Error uploading file $($file.Name): $($response.Content)" | |
} | |
} catch { | |
Write-Host "Error uploading file $($file.Name): $($_.Exception.Message)" | |
} | |
} | |
# Construct the album request | |
if ($fileUrls.Count -gt 0) { | |
$filesArg = $fileUrls -join ' ' -replace 'https://files.catbox.moe/', '' | |
$albumParams = @{ | |
'reqtype' = 'createalbum' | |
'title' = $Title | |
'desc' = $Description | |
'files' = $filesArg | |
} | |
if ($UserHash) { | |
$albumParams.Add('userhash', $UserHash) | |
} | |
# Send the album request | |
try { | |
$response = Invoke-WebRequest -Uri "https://catbox.moe/user/api.php" -Method POST -Form $albumParams -ErrorAction Stop | |
if ($response.StatusCode -eq 200) { | |
$albumUrl = $response.Content.Trim() | |
Write-Host "Album created successfully. URL: $albumUrl" | |
} else { | |
Write-Host "Error creating album: $($response.Content)" | |
} | |
} catch { | |
Write-Host "Error creating album: $($_.Exception.Message)" | |
} | |
} else { | |
Write-Host "No files found to upload." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment