Add support for excluding specific trackers in qBittorrent script
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
[string] $qbtUser = $ENV:QBTUSER
|
[string] $qbtUser = $ENV:QBTUSER
|
||||||
[string] $qbtPassword = $ENV:QBTPASSWORD
|
[string] $qbtPassword = $ENV:QBTPASSWORD
|
||||||
[string] $notificationWebhookURL = $ENV:NOTIFICATIONWEBHOOKURL
|
[string] $notificationWebhookURL = $ENV:NOTIFICATIONWEBHOOKURL
|
||||||
|
[string[]] $excludedTrackers = $ENV:EXCLUDEDTRACKERS -split ','
|
||||||
|
|
||||||
# Function to authenticate and get a session
|
# Function to authenticate and get a session
|
||||||
function Get-QBittorrentSession {
|
function Get-QBittorrentSession {
|
||||||
@@ -34,6 +35,7 @@ function Get-Torrents {
|
|||||||
function Remove-Torrent {
|
function Remove-Torrent {
|
||||||
param (
|
param (
|
||||||
[Microsoft.PowerShell.Commands.WebRequestSession]$session,
|
[Microsoft.PowerShell.Commands.WebRequestSession]$session,
|
||||||
|
[string]$name,
|
||||||
[string]$hash
|
[string]$hash
|
||||||
)
|
)
|
||||||
$qbtHeaders = @{
|
$qbtHeaders = @{
|
||||||
@@ -51,17 +53,17 @@ function Remove-Torrent {
|
|||||||
"Content-Type"="application/json"
|
"Content-Type"="application/json"
|
||||||
}
|
}
|
||||||
$body = @{
|
$body = @{
|
||||||
content="Removed torrent with hash $hash"
|
content="Removed torrent $name with hash $hash"
|
||||||
}
|
}
|
||||||
$json = $body | ConvertTo-Json
|
$json = $body | ConvertTo-Json
|
||||||
Invoke-WebRequest -URI $notificationWebhookURL -Method post -Body $json -Headers $headers
|
Invoke-WebRequest -URI $notificationWebhookURL -Method post -Body $json -Headers $headers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while ($true)
|
|
||||||
{
|
|
||||||
# Main script
|
# Main script
|
||||||
$session = Get-QBittorrentSession
|
$session = Get-QBittorrentSession
|
||||||
|
while ($true)
|
||||||
|
{
|
||||||
$torrents = Get-Torrents -session $session
|
$torrents = Get-Torrents -session $session
|
||||||
|
|
||||||
foreach ($torrent in $torrents) {
|
foreach ($torrent in $torrents) {
|
||||||
@@ -74,15 +76,12 @@ while ($true)
|
|||||||
}
|
}
|
||||||
if (-not ($trackers | Where-Object { $excludedTrackers -contains $_ })) {
|
if (-not ($trackers | Where-Object { $excludedTrackers -contains $_ })) {
|
||||||
# Delete the torrent
|
# Delete the torrent
|
||||||
Write-Host "Would delete: $($torrent.name)"
|
Write-Host "Delete: $($torrent.name) $($toreent.hash)"
|
||||||
Remove-Torrent -session $session -hash $torrent.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..."
|
Write-Host "Sleeping for $schedule minutes..."
|
||||||
Start-Sleep ($schedule * 60)
|
Start-Sleep ($schedule * 60)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,3 +11,4 @@ services:
|
|||||||
- QBTUSER=admin # qbittorrent webUI username
|
- QBTUSER=admin # qbittorrent webUI username
|
||||||
- QBTPASSWORD=adminpass # qbittorrent webUI password
|
- 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
|
||||||
Reference in New Issue
Block a user