Add option to ignore private downloads when blocking files (#39)
This commit is contained in:
@@ -107,6 +107,7 @@ services:
|
|||||||
- QUEUECLEANER__STALLED_IGNORE_PRIVATE=false
|
- QUEUECLEANER__STALLED_IGNORE_PRIVATE=false
|
||||||
|
|
||||||
- CONTENTBLOCKER__ENABLED=true
|
- CONTENTBLOCKER__ENABLED=true
|
||||||
|
- CONTENTBLOCKER__IGNORE_PRIVATE=true
|
||||||
- CONTENTBLOCKER__BLACKLIST__ENABLED=true
|
- CONTENTBLOCKER__BLACKLIST__ENABLED=true
|
||||||
- CONTENTBLOCKER__BLACKLIST__PATH=https://raw.githubusercontent.com/flmorg/cleanuperr/refs/heads/main/blacklist
|
- CONTENTBLOCKER__BLACKLIST__PATH=https://raw.githubusercontent.com/flmorg/cleanuperr/refs/heads/main/blacklist
|
||||||
# OR
|
# OR
|
||||||
@@ -166,6 +167,7 @@ services:
|
|||||||
| QUEUECLEANER__STALLED_IGNORE_PRIVATE | No | Whether to ignore stalled downloads from private trackers | false |
|
| QUEUECLEANER__STALLED_IGNORE_PRIVATE | No | Whether to ignore stalled downloads from private trackers | false |
|
||||||
|||||
|
|||||
|
||||||
| CONTENTBLOCKER__ENABLED | No | Enable or disable the content blocker | false |
|
| CONTENTBLOCKER__ENABLED | No | Enable or disable the content blocker | false |
|
||||||
|
| CONTENTBLOCKER__IGNORE_PRIVATE | No | Whether to ignore downloads from private trackers | false |
|
||||||
| CONTENTBLOCKER__BLACKLIST__ENABLED | Yes if content blocker is enabled and whitelist is not enabled | Enable or disable the blacklist | false |
|
| CONTENTBLOCKER__BLACKLIST__ENABLED | Yes if content blocker is enabled and whitelist is not enabled | Enable or disable the blacklist | false |
|
||||||
| CONTENTBLOCKER__BLACKLIST__PATH | Yes if blacklist is enabled | Path to the blacklist (local file or url)<br>Needs to be json compatible | empty |
|
| CONTENTBLOCKER__BLACKLIST__PATH | Yes if blacklist is enabled | Path to the blacklist (local file or url)<br>Needs to be json compatible | empty |
|
||||||
| CONTENTBLOCKER__WHITELIST__ENABLED | Yes if content blocker is enabled and blacklist is not enabled | Enable or disable the whitelist | false |
|
| CONTENTBLOCKER__WHITELIST__ENABLED | Yes if content blocker is enabled and blacklist is not enabled | Enable or disable the whitelist | false |
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace Common.Configuration.ContentBlocker;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
namespace Common.Configuration.ContentBlocker;
|
||||||
|
|
||||||
public sealed record ContentBlockerConfig : IJobConfig
|
public sealed record ContentBlockerConfig : IJobConfig
|
||||||
{
|
{
|
||||||
@@ -6,6 +8,9 @@ public sealed record ContentBlockerConfig : IJobConfig
|
|||||||
|
|
||||||
public required bool Enabled { get; init; }
|
public required bool Enabled { get; init; }
|
||||||
|
|
||||||
|
[ConfigurationKeyName("IGNORE_PRIVATE")]
|
||||||
|
public bool IgnorePrivate { get; init; }
|
||||||
|
|
||||||
public PatternConfig? Blacklist { get; init; }
|
public PatternConfig? Blacklist { get; init; }
|
||||||
|
|
||||||
public PatternConfig? Whitelist { get; init; }
|
public PatternConfig? Whitelist { get; init; }
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
},
|
},
|
||||||
"ContentBlocker": {
|
"ContentBlocker": {
|
||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
|
"IGNORE_PRIVATE": true,
|
||||||
"Blacklist": {
|
"Blacklist": {
|
||||||
"Enabled": false,
|
"Enabled": false,
|
||||||
"Path": "https://raw.githubusercontent.com/flmorg/cleanuperr/refs/heads/main/blacklist"
|
"Path": "https://raw.githubusercontent.com/flmorg/cleanuperr/refs/heads/main/blacklist"
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
},
|
},
|
||||||
"ContentBlocker": {
|
"ContentBlocker": {
|
||||||
"Enabled": false,
|
"Enabled": false,
|
||||||
|
"IGNORE_PRIVATE": false,
|
||||||
"Blacklist": {
|
"Blacklist": {
|
||||||
"Enabled": false,
|
"Enabled": false,
|
||||||
"Path": ""
|
"Path": ""
|
||||||
|
|||||||
@@ -82,6 +82,13 @@ public sealed class DelugeService : DownloadServiceBase
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_queueCleanerConfig.StalledIgnorePrivate && status.Private)
|
||||||
|
{
|
||||||
|
// ignore private trackers
|
||||||
|
_logger.LogDebug("skip files check | download is private | {name}", status.Name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DelugeContents? contents = null;
|
DelugeContents? contents = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -83,6 +83,34 @@ public sealed class QBitService : DownloadServiceBase
|
|||||||
|
|
||||||
public override async Task BlockUnwantedFilesAsync(string hash)
|
public override async Task BlockUnwantedFilesAsync(string hash)
|
||||||
{
|
{
|
||||||
|
TorrentInfo? torrent = (await _client.GetTorrentListAsync(new TorrentListQuery { Hashes = [hash] }))
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
if (torrent is null)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("failed to find torrent {hash} in the download client", hash);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TorrentProperties? torrentProperties = await _client.GetTorrentPropertiesAsync(hash);
|
||||||
|
|
||||||
|
if (torrentProperties is null)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("failed to find torrent properties {hash} in the download client", hash);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isPrivate = torrentProperties.AdditionalData.TryGetValue("is_private", out var dictValue) &&
|
||||||
|
bool.TryParse(dictValue?.ToString(), out bool boolValue)
|
||||||
|
&& boolValue;
|
||||||
|
|
||||||
|
if (_queueCleanerConfig.StalledIgnorePrivate && isPrivate)
|
||||||
|
{
|
||||||
|
// ignore private trackers
|
||||||
|
_logger.LogDebug("skip files check | download is private | {name}", torrent.Name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
IReadOnlyList<TorrentContent>? files = await _client.GetTorrentContentsAsync(hash);
|
IReadOnlyList<TorrentContent>? files = await _client.GetTorrentContentsAsync(hash);
|
||||||
|
|
||||||
if (files is null)
|
if (files is null)
|
||||||
|
|||||||
@@ -82,6 +82,13 @@ public sealed class TransmissionService : DownloadServiceBase
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_queueCleanerConfig.StalledIgnorePrivate && (torrent.IsPrivate ?? false))
|
||||||
|
{
|
||||||
|
// ignore private trackers
|
||||||
|
_logger.LogDebug("skip files check | download is private | {name}", torrent.Name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
List<long> unwantedFiles = [];
|
List<long> unwantedFiles = [];
|
||||||
|
|
||||||
for (int i = 0; i < torrent.Files.Length; i++)
|
for (int i = 0; i < torrent.Files.Length; i++)
|
||||||
|
|||||||
@@ -188,6 +188,7 @@ services:
|
|||||||
- QUEUECLEANER__STALLED_IGNORE_PRIVATE=true
|
- QUEUECLEANER__STALLED_IGNORE_PRIVATE=true
|
||||||
|
|
||||||
- CONTENTBLOCKER__ENABLED=true
|
- CONTENTBLOCKER__ENABLED=true
|
||||||
|
- CONTENTBLOCKER__IGNORE_PRIVATE=true
|
||||||
- CONTENTBLOCKER__BLACKLIST__ENABLED=true
|
- CONTENTBLOCKER__BLACKLIST__ENABLED=true
|
||||||
- CONTENTBLOCKER__BLACKLIST__PATH=https://raw.githubusercontent.com/flmorg/cleanuperr/refs/heads/main/blacklist
|
- CONTENTBLOCKER__BLACKLIST__PATH=https://raw.githubusercontent.com/flmorg/cleanuperr/refs/heads/main/blacklist
|
||||||
# OR
|
# OR
|
||||||
|
|||||||
Reference in New Issue
Block a user