Add support for excluding specific trackers in qBittorrent script

This commit is contained in:
Kelly Thomas Reardon
2024-12-28 07:37:17 -06:00
parent 7d1930e1b6
commit dde1ea182b
2 changed files with 9 additions and 9 deletions
+7 -8
View File
@@ -5,6 +5,7 @@
[string] $qbtUser = $ENV:QBTUSER
[string] $qbtPassword = $ENV:QBTPASSWORD
[string] $notificationWebhookURL = $ENV:NOTIFICATIONWEBHOOKURL
[string[]] $excludedTrackers = $ENV:EXCLUDEDTRACKERS -split ','
# Function to authenticate and get a session
function Get-QBittorrentSession {
@@ -34,6 +35,7 @@ function Get-Torrents {
function Remove-Torrent {
param (
[Microsoft.PowerShell.Commands.WebRequestSession]$session,
[string]$name,
[string]$hash
)
$qbtHeaders = @{
@@ -51,17 +53,17 @@ function Remove-Torrent {
"Content-Type"="application/json"
}
$body = @{
content="Removed torrent with hash $hash"
content="Removed torrent $name with hash $hash"
}
$json = $body | ConvertTo-Json
Invoke-WebRequest -URI $notificationWebhookURL -Method post -Body $json -Headers $headers
}
}
while ($true)
{
# Main script
$session = Get-QBittorrentSession
while ($true)
{
$torrents = Get-Torrents -session $session
foreach ($torrent in $torrents) {
@@ -74,15 +76,12 @@ while ($true)
}
if (-not ($trackers | Where-Object { $excludedTrackers -contains $_ })) {
# Delete the torrent
Write-Host "Would delete: $($torrent.name)"
Remove-Torrent -session $session -hash $torrent.hash
Write-Host "Delete: $($torrent.name) $($toreent.hash)"
Remove-Torrent -session $session -hash $torrent.hash -name $torrent.name
}
}
}
# Logout (optional, but good practice)
# $session.UploadString("$qbittorrentUrl/api/v2/auth/logout", "")
Write-Host "Sleeping for $schedule minutes..."
Start-Sleep ($schedule * 60)
}
+1
View File
@@ -11,3 +11,4 @@ services:
- QBTUSER=admin # qbittorrent webUI username
- QBTPASSWORD=adminpass # qbittorrent webUI password
- NOTIFICATIONWEBHOOKURL=https://discord.com/api/webhooks/<webhookURL> # discord notification wehook URL
- EXCLUDEDTRACKERS=tracker1.com,tracker2.com # comma separated list of tracker names to exclude