Skip to content

Instantly share code, notes, and snippets.

@x-limitless-x
Last active November 12, 2022 00:40
Show Gist options
  • Save x-limitless-x/a25273bc53a78588d29e7b592f9f705b to your computer and use it in GitHub Desktop.
Save x-limitless-x/a25273bc53a78588d29e7b592f9f705b to your computer and use it in GitHub Desktop.
Remove any duplicates from sabnzbd programmatically
#Author: Blake Drumm
#Created: October 23rd, 2022
#Modified: November 11th, 2022
$ServerAddress = '<sabnzbd_weburl>'
$APIKey = '<sabnzbd_apikey>'
# Grab List of Duplicates
[array]$listOfNzbs = (((Invoke-WebRequest "$ServerAddress/api?mode=queue&output=json&apikey=$APIKey" -UseBasicParsing).Content | ConvertFrom-Json).Queue.Slots |
Group-Object -Property filename |
Where-Object -FilterScript {
$_.Count -gt 1
} |
Select-Object -ExpandProperty Group)
if ($listOfNzbs)
{
$sizeInGB = (($listOfNzbs | Where { $_.Size -match " GB" } | Select-Object Size -ExpandProperty Size).Replace(" GB", '') -join " + ");
}
else
{
$sizeInGB = '0 GB'
}
$calculatedSizeTotal = "$(Invoke-Command -ScriptBlock { $result = . ([ScriptBlock]::Create($sizeInGB)); return [math]::Round($result) }) GB"
$listOfNzbIds = $listOfNzbs | Select-Object nzo_id -ExpandProperty nzo_id
Write-Output @"
This script will delete duplicate items with similar nzb names, from SABNZBD via the API.
To be removed:
Total Count: $($listOfNzbIds.Count)
Total Size: $calculatedSizeTotal
"@
pause
# If the list of Nzb's to be removed are more than 100
if ($listOfNzbIds.Count -gt 100)
{
foreach ($nzb in $listOfNzbIds)
{
# Delete all found duplicates individually
(Invoke-WebRequest "$ServerAddress/api?mode=queue&name=delete&value=$nzb&del_files=1&apikey=$APIKey" -UseBasicParsing).Content
}
}
# If the list of Nzb's to be removed are more than 0 and less than 100
elseif ($listOfNzbIds.Count -gt 0)
{
# Delete all found duplicates at once
(Invoke-WebRequest "$ServerAddress/api?mode=queue&name=delete&value=$($listOfNzbIds -join "," | Out-String)&del_files=1&apikey=$APIKey" -UseBasicParsing).Content
}
Write-Output "Script completed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment