From d82c1551fa771ee6ff7c3c66356e0363e4f153e3 Mon Sep 17 00:00:00 2001 From: Kelly Thomas Reardon Date: Fri, 27 Dec 2024 12:18:21 -0600 Subject: [PATCH] initial commit --- Invoke-QBTCleanarr.ps1 | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Invoke-QBTCleanarr.ps1 diff --git a/Invoke-QBTCleanarr.ps1 b/Invoke-QBTCleanarr.ps1 new file mode 100644 index 0000000..13a4925 --- /dev/null +++ b/Invoke-QBTCleanarr.ps1 @@ -0,0 +1,51 @@ +# Configuration +$qbittorrentUrl = 'http://localhost:8080' # Change if necessary +$username = 'your_username' +$password = 'your_password' +$excludedTrackers = @('tracker1.com', 'tracker2.com') + +# Function to authenticate and get a session +function Get-QBittorrentSession { + $session = New-Object System.Net.WebClient + $session.Headers.Add("Content-Type", "application/x-www-form-urlencoded") + + # Authenticate + $session.UploadString("$qbittorrentUrl/api/v2/auth/login", "username=$username&password=$password") + return $session +} + +# Function to get all torrents +function Get-Torrents { + param ( + [System.Net.WebClient]$session + ) + $response = $session.DownloadString("$qbittorrentUrl/api/v2/torrents/info") + return $response | ConvertFrom-Json +} + +# Function to delete a torrent +function Delete-Torrent { + param ( + [System.Net.WebClient]$session, + [string]$hash + ) + $session.UploadString("$qbittorrentUrl/api/v2/torrents/delete", "hashes=$hash") +} + +# Main script +$session = Get-QBittorrentSession +$torrents = Get-Torrents -session $session + +foreach ($torrent in $torrents) { + if ($torrent.state -eq 'completed') { + # Check if any of the excluded trackers are in the torrent's tracker list + $trackers = $torrent.trackers | ForEach-Object { $_.url } + if (-not ($trackers | Where-Object { $excludedTrackers -contains $_ })) { + # Delete the torrent + Delete-Torrent -session $session -hash $torrent.hash + } + } +} + +# Logout (optional, but good practice) +$session.UploadString("$qbittorrentUrl/api/v2/auth/logout", "")