Add support for excluding specific trackers in qBittorrent script #2

Merged
blinkfink182 merged 1 commits from v0.2 into main 2024-12-28 07:37:59 -06:00
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
}
}
# Main script
$session = Get-QBittorrentSession
while ($true)
{
# Main script
$session = Get-QBittorrentSession
$torrents = Get-Torrents -session $session
foreach ($torrent in $torrents) {
@@ -74,14 +76,11 @@ 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)
+2 -1
View File
@@ -10,4 +10,5 @@ services:
- QBTPORT=8787 # qbittorrent port
- QBTUSER=admin # qbittorrent webUI username
- QBTPASSWORD=adminpass # qbittorrent webUI password
- NOTIFICATIONWEBHOOKURL=https://discord.com/api/webhooks/<webhookURL> # discord notification wehook URL
- NOTIFICATIONWEBHOOKURL=https://discord.com/api/webhooks/<webhookURL> # discord notification wehook URL
- EXCLUDEDTRACKERS=tracker1.com,tracker2.com # comma separated list of tracker names to exclude