Skip to content

Commit

Permalink
Add option to ignore private downloads when blocking files (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaminel authored Jan 13, 2025
1 parent f0dc51f commit 058507a
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ services:
- QUEUECLEANER__STALLED_IGNORE_PRIVATE=false
- CONTENTBLOCKER__ENABLED=true
- CONTENTBLOCKER__IGNORE_PRIVATE=true
- CONTENTBLOCKER__BLACKLIST__ENABLED=true
- CONTENTBLOCKER__BLACKLIST__PATH=https://raw.githubusercontent.com/flmorg/cleanuperr/refs/heads/main/blacklist
# OR
Expand Down Expand Up @@ -166,6 +167,7 @@ services:
| 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__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__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 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
namespace Common.Configuration.ContentBlocker;
using Microsoft.Extensions.Configuration;

namespace Common.Configuration.ContentBlocker;

public sealed record ContentBlockerConfig : IJobConfig
{
public const string SectionName = "ContentBlocker";

public required bool Enabled { get; init; }

[ConfigurationKeyName("IGNORE_PRIVATE")]
public bool IgnorePrivate { get; init; }

public PatternConfig? Blacklist { get; init; }

public PatternConfig? Whitelist { get; init; }
Expand Down
1 change: 1 addition & 0 deletions code/Executable/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"ContentBlocker": {
"Enabled": true,
"IGNORE_PRIVATE": true,
"Blacklist": {
"Enabled": false,
"Path": "https://raw.githubusercontent.com/flmorg/cleanuperr/refs/heads/main/blacklist"
Expand Down
1 change: 1 addition & 0 deletions code/Executable/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"ContentBlocker": {
"Enabled": false,
"IGNORE_PRIVATE": false,
"Blacklist": {
"Enabled": false,
"Path": ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ public override async Task BlockUnwantedFilesAsync(string hash)
return;
}

if (_queueCleanerConfig.StalledIgnorePrivate && status.Private)
{
// ignore private trackers
_logger.LogDebug("skip files check | download is private | {name}", status.Name);
return;
}

DelugeContents? contents = null;

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,34 @@ public override async Task<RemoveResult> ShouldRemoveFromArrQueueAsync(string ha

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);

if (files is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public override async Task BlockUnwantedFilesAsync(string hash)
{
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 = [];

Expand Down
1 change: 1 addition & 0 deletions code/test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ services:
- QUEUECLEANER__STALLED_IGNORE_PRIVATE=true

- CONTENTBLOCKER__ENABLED=true
- CONTENTBLOCKER__IGNORE_PRIVATE=true
- CONTENTBLOCKER__BLACKLIST__ENABLED=true
- CONTENTBLOCKER__BLACKLIST__PATH=https://raw.githubusercontent.com/flmorg/cleanuperr/refs/heads/main/blacklist
# OR
Expand Down

0 comments on commit 058507a

Please sign in to comment.