52 lines
1.6 KiB
PowerShell
52 lines
1.6 KiB
PowerShell
# 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", "")
|