Add Docker support and environment variable configuration for qBittorrent script
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
|||||||
|
FROM mcr.microsoft.com/powershell
|
||||||
|
|
||||||
|
ENV SCHEDULE=60
|
||||||
|
|
||||||
|
VOLUME /tmp
|
||||||
|
|
||||||
|
WORKDIR /data
|
||||||
|
ADD ["Invoke-QBTCleanarr.ps1", "/data/"]
|
||||||
|
|
||||||
|
ENTRYPOINT ["pwsh", "-Command", "/data/Invoke-QBTCleanarr.ps1"]
|
||||||
+41
-19
@@ -1,13 +1,10 @@
|
|||||||
# Configuration
|
# Configuration
|
||||||
$qbtHost = 'ktr.h4ck.me'
|
[int] $schedule = $ENV:SCHEDULE
|
||||||
$qbtPort = '7878'
|
[string] $qbtHost = $ENV:QBTHOST
|
||||||
$qbtUser = 'kelly'
|
[string] $qbtPort = $ENV:QBTPORT
|
||||||
$qbtPassword = 'KjBWnJC;cabA^gFxcN]5'
|
[string] $qbtUser = $ENV:QBTUSER
|
||||||
$excludedTrackers = @(
|
[string] $qbtPassword = $ENV:QBTPASSWORD
|
||||||
'digitalcore.club',
|
[string] $notificationWebhookURL = $ENV:NOTIFICATIONWEBHOOKURL
|
||||||
'please.passthepopcorn.me:2710',
|
|
||||||
'please.passthepopcorn.me'
|
|
||||||
)
|
|
||||||
|
|
||||||
# Function to authenticate and get a session
|
# Function to authenticate and get a session
|
||||||
function Get-QBittorrentSession {
|
function Get-QBittorrentSession {
|
||||||
@@ -34,19 +31,40 @@ function Get-Torrents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to delete a torrent
|
# Function to delete a torrent
|
||||||
function Delete-Torrent {
|
function Remove-Torrent {
|
||||||
param (
|
param (
|
||||||
[Microsoft.PowerShell.Commands.WebRequestSession]$session,
|
[Microsoft.PowerShell.Commands.WebRequestSession]$session,
|
||||||
[string]$hash
|
[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
|
||||||
|
|
||||||
|
if ($notificationWebhookURL)
|
||||||
|
{
|
||||||
|
$headers = @{
|
||||||
|
"Content-Type"="application/json"
|
||||||
|
}
|
||||||
|
$body = @{
|
||||||
|
content="Removed torrent with hash $hash"
|
||||||
|
}
|
||||||
|
$json = $body | ConvertTo-Json
|
||||||
|
Invoke-WebRequest -URI $notificationWebhookURL -Method post -Body $json -Headers $headers
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main script
|
while ($true)
|
||||||
$session = Get-QBittorrentSession
|
{
|
||||||
$torrents = Get-Torrents -session $session
|
# Main script
|
||||||
|
$session = Get-QBittorrentSession
|
||||||
|
$torrents = Get-Torrents -session $session
|
||||||
|
|
||||||
foreach ($torrent in $torrents) {
|
foreach ($torrent in $torrents) {
|
||||||
if ($torrent.state -eq 'uploading' -or $torrent.state -like "*UP") {
|
if ($torrent.state -eq 'uploading' -or $torrent.state -like "*UP") {
|
||||||
# Check if any of the excluded trackers are in the torrent's tracker list
|
# Check if any of the excluded trackers are in the torrent's tracker list
|
||||||
if ($torrent.tracker -match "https?://([^/]+)") {
|
if ($torrent.tracker -match "https?://([^/]+)") {
|
||||||
@@ -57,10 +75,14 @@ foreach ($torrent in $torrents) {
|
|||||||
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 "Would delete: $($torrent.name)"
|
||||||
# Delete-Torrent -session $session -hash $torrent.hash
|
Remove-Torrent -session $session -hash $torrent.hash
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
# Logout (optional, but good practice)
|
# Logout (optional, but good practice)
|
||||||
# $session.UploadString("$qbittorrentUrl/api/v2/auth/logout", "")
|
# $session.UploadString("$qbittorrentUrl/api/v2/auth/logout", "")
|
||||||
|
|
||||||
|
Write-Host "Sleeping for $schedule minutes..."
|
||||||
|
Start-Sleep ($schedule * 60)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# SAMPLE DOCKER COMPOSE
|
||||||
|
services:
|
||||||
|
qbt-cleanarr:
|
||||||
|
container_name: qbt-cleanarr
|
||||||
|
image: docker.io/blinkfink182/qbt-cleanarr
|
||||||
|
environment:
|
||||||
|
- SCHEDULE=15 # OPTIONAL: time in minutes to wait between check, 60 is default
|
||||||
|
# BELOW ARE ALL REQUIRED
|
||||||
|
- QBTHOST=host.docker.internal # qbittorrent host
|
||||||
|
- 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
|
||||||
Reference in New Issue
Block a user