Add Docker support and environment variable configuration for qBittorrent script
This commit is contained in:
+51
-29
@@ -1,13 +1,10 @@
|
||||
# Configuration
|
||||
$qbtHost = 'ktr.h4ck.me'
|
||||
$qbtPort = '7878'
|
||||
$qbtUser = 'kelly'
|
||||
$qbtPassword = 'KjBWnJC;cabA^gFxcN]5'
|
||||
$excludedTrackers = @(
|
||||
'digitalcore.club',
|
||||
'please.passthepopcorn.me:2710',
|
||||
'please.passthepopcorn.me'
|
||||
)
|
||||
[int] $schedule = $ENV:SCHEDULE
|
||||
[string] $qbtHost = $ENV:QBTHOST
|
||||
[string] $qbtPort = $ENV:QBTPORT
|
||||
[string] $qbtUser = $ENV:QBTUSER
|
||||
[string] $qbtPassword = $ENV:QBTPASSWORD
|
||||
[string] $notificationWebhookURL = $ENV:NOTIFICATIONWEBHOOKURL
|
||||
|
||||
# Function to authenticate and get a session
|
||||
function Get-QBittorrentSession {
|
||||
@@ -34,33 +31,58 @@ function Get-Torrents {
|
||||
}
|
||||
|
||||
# Function to delete a torrent
|
||||
function Delete-Torrent {
|
||||
function Remove-Torrent {
|
||||
param (
|
||||
[Microsoft.PowerShell.Commands.WebRequestSession]$session,
|
||||
[string]$hash
|
||||
)
|
||||
# $session.UploadString("$qbittorrentUrl/api/v2/torrents/delete", "hashes=$hash")
|
||||
}
|
||||
$qbtHeaders = @{
|
||||
Referer = "https://$($qbtHost):$($qbtPort)"
|
||||
}
|
||||
$qbtBody = @{
|
||||
hashes = $hash
|
||||
deleteFiles = 'true'
|
||||
}
|
||||
$qbtResponse = Invoke-WebRequest -Uri "https://$($qbtHost):$($qbtPort)/api/v2/torrents/delete" -WebSession $session -Method POST -Headers $qbtHeaders -Body $qbtBody
|
||||
|
||||
# Main script
|
||||
$session = Get-QBittorrentSession
|
||||
$torrents = Get-Torrents -session $session
|
||||
|
||||
foreach ($torrent in $torrents) {
|
||||
if ($torrent.state -eq 'uploading' -or $torrent.state -like "*UP") {
|
||||
# Check if any of the excluded trackers are in the torrent's tracker list
|
||||
if ($torrent.tracker -match "https?://([^/]+)") {
|
||||
$trackers = $matches[1]
|
||||
} else {
|
||||
$trackers = @()
|
||||
if ($notificationWebhookURL)
|
||||
{
|
||||
$headers = @{
|
||||
"Content-Type"="application/json"
|
||||
}
|
||||
if (-not ($trackers | Where-Object { $excludedTrackers -contains $_ })) {
|
||||
# Delete the torrent
|
||||
Write-Host "Would delete: $($torrent.name)"
|
||||
# Delete-Torrent -session $session -hash $torrent.hash
|
||||
$body = @{
|
||||
content="Removed torrent with hash $hash"
|
||||
}
|
||||
$json = $body | ConvertTo-Json
|
||||
Invoke-WebRequest -URI $notificationWebhookURL -Method post -Body $json -Headers $headers
|
||||
}
|
||||
}
|
||||
|
||||
# Logout (optional, but good practice)
|
||||
# $session.UploadString("$qbittorrentUrl/api/v2/auth/logout", "")
|
||||
while ($true)
|
||||
{
|
||||
# Main script
|
||||
$session = Get-QBittorrentSession
|
||||
$torrents = Get-Torrents -session $session
|
||||
|
||||
foreach ($torrent in $torrents) {
|
||||
if ($torrent.state -eq 'uploading' -or $torrent.state -like "*UP") {
|
||||
# Check if any of the excluded trackers are in the torrent's tracker list
|
||||
if ($torrent.tracker -match "https?://([^/]+)") {
|
||||
$trackers = $matches[1]
|
||||
} else {
|
||||
$trackers = @()
|
||||
}
|
||||
if (-not ($trackers | Where-Object { $excludedTrackers -contains $_ })) {
|
||||
# Delete the torrent
|
||||
Write-Host "Would delete: $($torrent.name)"
|
||||
Remove-Torrent -session $session -hash $torrent.hash
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Logout (optional, but good practice)
|
||||
# $session.UploadString("$qbittorrentUrl/api/v2/auth/logout", "")
|
||||
|
||||
Write-Host "Sleeping for $schedule minutes..."
|
||||
Start-Sleep ($schedule * 60)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user