Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2bc8e445ce | |||
| 058507ac39 | |||
| f0dc51f10b |
@@ -1,6 +1,6 @@
|
|||||||
name: Bug report
|
name: Bug report
|
||||||
description: File a bug report if something is not working right.
|
description: File a bug report if something is not working right.
|
||||||
title: "[BUG]: "
|
title: "[BUG] "
|
||||||
labels: ["bug"]
|
labels: ["bug"]
|
||||||
body:
|
body:
|
||||||
- type: markdown
|
- type: markdown
|
||||||
@@ -40,6 +40,7 @@ body:
|
|||||||
- Windows
|
- Windows
|
||||||
- Linux
|
- Linux
|
||||||
- MacOS
|
- MacOS
|
||||||
|
- Unraid
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: dropdown
|
- type: dropdown
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
name: Feature request
|
name: Feature request
|
||||||
description: File a feature request.
|
description: File a feature request.
|
||||||
title: "[FEATURE]: "
|
title: "[FEATURE] "
|
||||||
labels: ["enhancement"]
|
labels: ["enhancement"]
|
||||||
body:
|
body:
|
||||||
- type: markdown
|
- type: markdown
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
name: Help request
|
name: Help request
|
||||||
description: Ask a question to receive help.
|
description: Ask a question to receive help.
|
||||||
title: "[HELP]: "
|
title: "[HELP] "
|
||||||
labels: ["question"]
|
labels: ["question"]
|
||||||
body:
|
body:
|
||||||
- type: markdown
|
- type: markdown
|
||||||
|
|||||||
@@ -73,9 +73,10 @@ This tool is actively developed and still a work in progress. Join the Discord s
|
|||||||
|
|
||||||
1. Set `QUEUECLEANER__ENABLED` to `true`.
|
1. Set `QUEUECLEANER__ENABLED` to `true`.
|
||||||
2. Set `QUEUECLEANER__IMPORT_FAILED_MAX_STRIKES` to a desired value.
|
2. Set `QUEUECLEANER__IMPORT_FAILED_MAX_STRIKES` to a desired value.
|
||||||
3. Set `DOWNLOAD_CLIENT` to `none`.
|
3. Optionally set failed import message patterns to ignore using `QUEUECLEANER__IMPORT_FAILED_IGNORE_PATTERNS__<NUMBER>`.
|
||||||
|
4. Set `DOWNLOAD_CLIENT` to `none`.
|
||||||
|
|
||||||
**No other action involving a download client would work (e.g. content blocking, removing stalled downloads etc.).**
|
**No other action involving a download client would work (e.g. content blocking, removing stalled downloads, excluding private trackers).**
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@@ -99,9 +100,14 @@ services:
|
|||||||
- QUEUECLEANER__ENABLED=true
|
- QUEUECLEANER__ENABLED=true
|
||||||
- QUEUECLEANER__RUNSEQUENTIALLY=true
|
- QUEUECLEANER__RUNSEQUENTIALLY=true
|
||||||
- QUEUECLEANER__IMPORT_FAILED_MAX_STRIKES=5
|
- QUEUECLEANER__IMPORT_FAILED_MAX_STRIKES=5
|
||||||
|
- QUEUECLEANER__IMPORT_FAILED_IGNORE_PRIVATE=false
|
||||||
|
# - QUEUECLEANER__IMPORT_FAILED_IGNORE_PATTERNS__0=title mismatch
|
||||||
|
# - QUEUECLEANER__IMPORT_FAILED_IGNORE_PATTERNS__1=manual import required
|
||||||
- QUEUECLEANER__STALLED_MAX_STRIKES=5
|
- QUEUECLEANER__STALLED_MAX_STRIKES=5
|
||||||
|
- 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
|
||||||
@@ -155,9 +161,13 @@ services:
|
|||||||
| QUEUECLEANER__ENABLED | No | Enable or disable the queue cleaner | true |
|
| QUEUECLEANER__ENABLED | No | Enable or disable the queue cleaner | true |
|
||||||
| QUEUECLEANER__RUNSEQUENTIALLY | No | If set to true, the queue cleaner will run after the content blocker instead of running in parallel, streamlining the cleaning process | true |
|
| QUEUECLEANER__RUNSEQUENTIALLY | No | If set to true, the queue cleaner will run after the content blocker instead of running in parallel, streamlining the cleaning process | true |
|
||||||
| QUEUECLEANER__IMPORT_FAILED_MAX_STRIKES | No | After how many strikes should a failed import be removed<br>0 means never | 0 |
|
| QUEUECLEANER__IMPORT_FAILED_MAX_STRIKES | No | After how many strikes should a failed import be removed<br>0 means never | 0 |
|
||||||
|
| QUEUECLEANER__IMPORT_FAILED_IGNORE_PRIVATE | No | Whether to ignore failed imports from private trackers | false |
|
||||||
|
| QUEUECLEANER__IMPORT_FAILED_IGNORE_PATTERNS__0 | No | First pattern to look for when an import is failed<br>If the specified message pattern is found, the item is skipped | empty |
|
||||||
| QUEUECLEANER__STALLED_MAX_STRIKES | No | After how many strikes should a stalled download be removed<br>0 means never | 0 |
|
| QUEUECLEANER__STALLED_MAX_STRIKES | No | After how many strikes should a stalled download be removed<br>0 means never | 0 |
|
||||||
|
| 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 |
|
||||||
@@ -183,7 +193,9 @@ services:
|
|||||||
| RADARR__ENABLED | No | Enable or disable Radarr cleanup | false |
|
| RADARR__ENABLED | No | Enable or disable Radarr cleanup | false |
|
||||||
| RADARR__INSTANCES__0__URL | No | First Radarr instance url | http://localhost:8989 |
|
| RADARR__INSTANCES__0__URL | No | First Radarr instance url | http://localhost:8989 |
|
||||||
| RADARR__INSTANCES__0__APIKEY | No | First Radarr instance API key | empty |
|
| RADARR__INSTANCES__0__APIKEY | No | First Radarr instance API key | empty |
|
||||||
|
|||||
|
||||||
|
| HTTP_MAX_RETRIES | No | The number of times to retry a failed HTTP call (to *arrs, download clients etc.) | 0 |
|
||||||
|
| HTTP_TIMEOUT | No | The number of seconds to wait before failing an HTTP call (to *arrs, download clients etc.) | 100 |
|
||||||
#
|
#
|
||||||
### To be noted
|
### To be noted
|
||||||
|
|
||||||
@@ -203,6 +215,10 @@ regex:<ANY_REGEX> // regex that needs to be marked at the start of the line wi
|
|||||||
SONARR__INSTANCES__<NUMBER>__URL
|
SONARR__INSTANCES__<NUMBER>__URL
|
||||||
SONARR__INSTANCES__<NUMBER>__APIKEY
|
SONARR__INSTANCES__<NUMBER>__APIKEY
|
||||||
```
|
```
|
||||||
|
6. Multiple failed import patterns can be specified using this format, where `<NUMBER>` starts from 0:
|
||||||
|
```
|
||||||
|
QUEUECLEANER__IMPORT_FAILED_IGNORE_PATTERNS__<NUMBER>
|
||||||
|
```
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|||||||
@@ -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; }
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
namespace Common.Configuration.General;
|
||||||
|
|
||||||
|
public class HttpConfig : IConfig
|
||||||
|
{
|
||||||
|
[ConfigurationKeyName("HTTP_MAX_RETRIES")]
|
||||||
|
public ushort MaxRetries { get; init; }
|
||||||
|
|
||||||
|
[ConfigurationKeyName("HTTP_TIMEOUT")]
|
||||||
|
public ushort Timeout { get; init; } = 100;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Timeout is 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("HTTP_TIMEOUT must be greater than 0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace Common.Configuration;
|
namespace Common.Configuration.General;
|
||||||
|
|
||||||
public sealed class TriggersConfig
|
public sealed class TriggersConfig
|
||||||
{
|
{
|
||||||
@@ -13,9 +13,18 @@ public sealed record QueueCleanerConfig : IJobConfig
|
|||||||
[ConfigurationKeyName("IMPORT_FAILED_MAX_STRIKES")]
|
[ConfigurationKeyName("IMPORT_FAILED_MAX_STRIKES")]
|
||||||
public ushort ImportFailedMaxStrikes { get; init; }
|
public ushort ImportFailedMaxStrikes { get; init; }
|
||||||
|
|
||||||
|
[ConfigurationKeyName("IMPORT_FAILED_IGNORE_PRIVATE")]
|
||||||
|
public bool ImportFailedIgnorePrivate { get; init; }
|
||||||
|
|
||||||
|
[ConfigurationKeyName("IMPORT_FAILED_IGNORE_PATTERNS")]
|
||||||
|
public List<string>? ImportFailedIgnorePatterns { get; init; }
|
||||||
|
|
||||||
[ConfigurationKeyName("STALLED_MAX_STRIKES")]
|
[ConfigurationKeyName("STALLED_MAX_STRIKES")]
|
||||||
public ushort StalledMaxStrikes { get; init; }
|
public ushort StalledMaxStrikes { get; init; }
|
||||||
|
|
||||||
|
[ConfigurationKeyName("STALLED_IGNORE_PRIVATE")]
|
||||||
|
public bool StalledIgnorePrivate { get; init; }
|
||||||
|
|
||||||
public void Validate()
|
public void Validate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,4 +4,6 @@ public static class Constants
|
|||||||
{
|
{
|
||||||
public static readonly TimeSpan TriggerMaxLimit = TimeSpan.FromHours(6);
|
public static readonly TimeSpan TriggerMaxLimit = TimeSpan.FromHours(6);
|
||||||
public static readonly TimeSpan CacheLimitBuffer = TimeSpan.FromHours(2);
|
public static readonly TimeSpan CacheLimitBuffer = TimeSpan.FromHours(2);
|
||||||
|
|
||||||
|
public const string HttpClientWithRetryName = "retry";
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace Domain.Models.Arr.Queue;
|
namespace Domain.Models.Arr.Queue;
|
||||||
|
|
||||||
public record QueueRecord
|
public sealed record QueueRecord
|
||||||
{
|
{
|
||||||
public int SeriesId { get; init; }
|
public int SeriesId { get; init; }
|
||||||
public int EpisodeId { get; init; }
|
public int EpisodeId { get; init; }
|
||||||
@@ -10,6 +10,7 @@ public record QueueRecord
|
|||||||
public string Status { get; init; }
|
public string Status { get; init; }
|
||||||
public string TrackedDownloadStatus { get; init; }
|
public string TrackedDownloadStatus { get; init; }
|
||||||
public string TrackedDownloadState { get; init; }
|
public string TrackedDownloadState { get; init; }
|
||||||
|
public List<TrackedDownloadStatusMessage>? StatusMessages { get; init; }
|
||||||
public required string DownloadId { get; init; }
|
public required string DownloadId { get; init; }
|
||||||
public required string Protocol { get; init; }
|
public required string Protocol { get; init; }
|
||||||
public required int Id { get; init; }
|
public required int Id { get; init; }
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Domain.Models.Arr.Queue;
|
||||||
|
|
||||||
|
public sealed record TrackedDownloadStatusMessage
|
||||||
|
{
|
||||||
|
public string Title { get; set; }
|
||||||
|
|
||||||
|
public List<string>? Messages { get; set; }
|
||||||
|
}
|
||||||
@@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
public sealed record TorrentStatus
|
public sealed record TorrentStatus
|
||||||
{
|
{
|
||||||
public string? Hash { get; set; }
|
public string? Hash { get; init; }
|
||||||
|
|
||||||
public string? State { get; set; }
|
public string? State { get; init; }
|
||||||
|
|
||||||
public string? Name { get; set; }
|
public string? Name { get; init; }
|
||||||
|
|
||||||
public ulong Eta { get; set; }
|
public ulong Eta { get; init; }
|
||||||
|
|
||||||
|
public bool Private { get; init; }
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,9 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using Common.Configuration;
|
using Common.Configuration.General;
|
||||||
using Common.Configuration.ContentBlocker;
|
using Common.Helpers;
|
||||||
using Executable.Jobs;
|
|
||||||
using Infrastructure.Verticals.Arr;
|
|
||||||
using Infrastructure.Verticals.ContentBlocker;
|
|
||||||
using Infrastructure.Verticals.DownloadClient;
|
|
||||||
using Infrastructure.Verticals.DownloadClient.Deluge;
|
using Infrastructure.Verticals.DownloadClient.Deluge;
|
||||||
using Infrastructure.Verticals.DownloadClient.QBittorrent;
|
using Polly;
|
||||||
using Infrastructure.Verticals.DownloadClient.Transmission;
|
using Polly.Extensions.Http;
|
||||||
using Infrastructure.Verticals.QueueCleaner;
|
|
||||||
|
|
||||||
namespace Executable.DependencyInjection;
|
namespace Executable.DependencyInjection;
|
||||||
|
|
||||||
@@ -17,17 +12,28 @@ public static class MainDI
|
|||||||
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration) =>
|
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration) =>
|
||||||
services
|
services
|
||||||
.AddLogging(builder => builder.ClearProviders().AddConsole())
|
.AddLogging(builder => builder.ClearProviders().AddConsole())
|
||||||
.AddHttpClients()
|
.AddHttpClients(configuration)
|
||||||
.AddConfiguration(configuration)
|
.AddConfiguration(configuration)
|
||||||
.AddMemoryCache()
|
.AddMemoryCache()
|
||||||
.AddServices()
|
.AddServices()
|
||||||
.AddQuartzServices(configuration);
|
.AddQuartzServices(configuration);
|
||||||
|
|
||||||
private static IServiceCollection AddHttpClients(this IServiceCollection services)
|
private static IServiceCollection AddHttpClients(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
// add default HttpClient
|
// add default HttpClient
|
||||||
services.AddHttpClient();
|
services.AddHttpClient();
|
||||||
|
|
||||||
|
HttpConfig config = configuration.Get<HttpConfig>() ?? new();
|
||||||
|
config.Validate();
|
||||||
|
|
||||||
|
// add retry HttpClient
|
||||||
|
services
|
||||||
|
.AddHttpClient(Constants.HttpClientWithRetryName, x =>
|
||||||
|
{
|
||||||
|
x.Timeout = TimeSpan.FromSeconds(config.Timeout);
|
||||||
|
})
|
||||||
|
.AddRetryPolicyHandler(config);
|
||||||
|
|
||||||
// add Deluge HttpClient
|
// add Deluge HttpClient
|
||||||
services
|
services
|
||||||
.AddHttpClient(nameof(DelugeService), x =>
|
.AddHttpClient(nameof(DelugeService), x =>
|
||||||
@@ -44,8 +50,18 @@ public static class MainDI
|
|||||||
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
|
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
|
||||||
ServerCertificateCustomValidationCallback = (_, _, _, _) => true
|
ServerCertificateCustomValidationCallback = (_, _, _, _) => true
|
||||||
};
|
};
|
||||||
});
|
})
|
||||||
|
.AddRetryPolicyHandler(config);
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IHttpClientBuilder AddRetryPolicyHandler(this IHttpClientBuilder builder, HttpConfig config) =>
|
||||||
|
builder.AddPolicyHandler(
|
||||||
|
HttpPolicyExtensions
|
||||||
|
.HandleTransientHttpError()
|
||||||
|
// do not retry on Unauthorized
|
||||||
|
.OrResult(response => !response.IsSuccessStatusCode && response.StatusCode != HttpStatusCode.Unauthorized)
|
||||||
|
.WaitAndRetryAsync(config.MaxRetries, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Common.Configuration;
|
using Common.Configuration;
|
||||||
using Common.Configuration.ContentBlocker;
|
using Common.Configuration.ContentBlocker;
|
||||||
|
using Common.Configuration.General;
|
||||||
using Common.Configuration.QueueCleaner;
|
using Common.Configuration.QueueCleaner;
|
||||||
using Common.Helpers;
|
using Common.Helpers;
|
||||||
using Executable.Jobs;
|
using Executable.Jobs;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="9.0.0" />
|
||||||
<PackageReference Include="Quartz" Version="3.13.1" />
|
<PackageReference Include="Quartz" Version="3.13.1" />
|
||||||
<PackageReference Include="Quartz.Extensions.DependencyInjection" Version="3.13.1" />
|
<PackageReference Include="Quartz.Extensions.DependencyInjection" Version="3.13.1" />
|
||||||
<PackageReference Include="Quartz.Extensions.Hosting" Version="3.13.1" />
|
<PackageReference Include="Quartz.Extensions.Hosting" Version="3.13.1" />
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"HTTP_MAX_RETRIES": 0,
|
||||||
|
"HTTP_TIMEOUT": 10,
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": "Debug",
|
"LogLevel": "Debug",
|
||||||
"Enhanced": true,
|
"Enhanced": true,
|
||||||
@@ -13,6 +15,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"
|
||||||
@@ -26,7 +29,12 @@
|
|||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"RunSequentially": true,
|
"RunSequentially": true,
|
||||||
"IMPORT_FAILED_MAX_STRIKES": 5,
|
"IMPORT_FAILED_MAX_STRIKES": 5,
|
||||||
"STALLED_MAX_STRIKES": 5
|
"IMPORT_FAILED_IGNORE_PRIVATE": true,
|
||||||
|
"IMPORT_FAILED_IGNORE_PATTERNS": [
|
||||||
|
"file is a sample"
|
||||||
|
],
|
||||||
|
"STALLED_MAX_STRIKES": 5,
|
||||||
|
"STALLED_IGNORE_PRIVATE": true
|
||||||
},
|
},
|
||||||
"DOWNLOAD_CLIENT": "qbittorrent",
|
"DOWNLOAD_CLIENT": "qbittorrent",
|
||||||
"qBittorrent": {
|
"qBittorrent": {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"HTTP_MAX_RETRIES": 0,
|
||||||
|
"HTTP_TIMEOUT": 100,
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": "Information",
|
"LogLevel": "Information",
|
||||||
"Enhanced": true,
|
"Enhanced": true,
|
||||||
@@ -13,6 +15,7 @@
|
|||||||
},
|
},
|
||||||
"ContentBlocker": {
|
"ContentBlocker": {
|
||||||
"Enabled": false,
|
"Enabled": false,
|
||||||
|
"IGNORE_PRIVATE": false,
|
||||||
"Blacklist": {
|
"Blacklist": {
|
||||||
"Enabled": false,
|
"Enabled": false,
|
||||||
"Path": ""
|
"Path": ""
|
||||||
@@ -26,7 +29,10 @@
|
|||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"RunSequentially": true,
|
"RunSequentially": true,
|
||||||
"IMPORT_FAILED_MAX_STRIKES": 5,
|
"IMPORT_FAILED_MAX_STRIKES": 5,
|
||||||
"STALLED_MAX_STRIKES": 5
|
"IMPORT_FAILED_IGNORE_PRIVATE": false,
|
||||||
|
"IMPORT_FAILED_IGNORE_PATTERNS": [],
|
||||||
|
"STALLED_MAX_STRIKES": 5,
|
||||||
|
"STALLED_IGNORE_PRIVATE": false
|
||||||
},
|
},
|
||||||
"DOWNLOAD_CLIENT": "qbittorrent",
|
"DOWNLOAD_CLIENT": "qbittorrent",
|
||||||
"qBittorrent": {
|
"qBittorrent": {
|
||||||
|
|||||||
@@ -12,10 +12,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="FLM.Transmission" Version="1.0.0" />
|
<PackageReference Include="FLM.QBittorrent" Version="1.0.0" />
|
||||||
|
<PackageReference Include="FLM.Transmission" Version="1.0.2" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0" />
|
||||||
<PackageReference Include="QBittorrent.Client" Version="1.9.24285.1" />
|
|
||||||
<PackageReference Include="Quartz" Version="3.13.1" />
|
<PackageReference Include="Quartz" Version="3.13.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Common.Configuration.Arr;
|
using Common.Configuration.Arr;
|
||||||
using Common.Configuration.Logging;
|
using Common.Configuration.Logging;
|
||||||
using Common.Configuration.QueueCleaner;
|
using Common.Configuration.QueueCleaner;
|
||||||
|
using Common.Helpers;
|
||||||
using Domain.Enums;
|
using Domain.Enums;
|
||||||
using Domain.Models.Arr;
|
using Domain.Models.Arr;
|
||||||
using Domain.Models.Arr.Queue;
|
using Domain.Models.Arr.Queue;
|
||||||
@@ -29,7 +30,7 @@ public abstract class ArrClient
|
|||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_striker = striker;
|
_striker = striker;
|
||||||
_httpClient = httpClientFactory.CreateClient();
|
_httpClient = httpClientFactory.CreateClient(Constants.HttpClientWithRetryName);
|
||||||
_loggingConfig = loggingConfig.Value;
|
_loggingConfig = loggingConfig.Value;
|
||||||
_queueCleanerConfig = queueCleanerConfig.Value;
|
_queueCleanerConfig = queueCleanerConfig.Value;
|
||||||
_striker = striker;
|
_striker = striker;
|
||||||
@@ -65,8 +66,15 @@ public abstract class ArrClient
|
|||||||
return queueResponse;
|
return queueResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool ShouldRemoveFromQueue(QueueRecord record)
|
public virtual bool ShouldRemoveFromQueue(QueueRecord record, bool isPrivateDownload)
|
||||||
{
|
{
|
||||||
|
if (_queueCleanerConfig.ImportFailedIgnorePrivate && isPrivateDownload)
|
||||||
|
{
|
||||||
|
// ignore private trackers
|
||||||
|
_logger.LogDebug("skip failed import check | download is private | {name}", record.Title);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool hasWarn() => record.TrackedDownloadStatus
|
bool hasWarn() => record.TrackedDownloadStatus
|
||||||
.Equals("warning", StringComparison.InvariantCultureIgnoreCase);
|
.Equals("warning", StringComparison.InvariantCultureIgnoreCase);
|
||||||
bool isImportBlocked() => record.TrackedDownloadState
|
bool isImportBlocked() => record.TrackedDownloadState
|
||||||
@@ -76,6 +84,12 @@ public abstract class ArrClient
|
|||||||
|
|
||||||
if (hasWarn() && (isImportBlocked() || isImportPending()))
|
if (hasWarn() && (isImportBlocked() || isImportPending()))
|
||||||
{
|
{
|
||||||
|
if (HasIgnoredPatterns(record))
|
||||||
|
{
|
||||||
|
_logger.LogDebug("skip failed import check | contains ignored pattern | {name}", record.Title);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return _striker.StrikeAndCheckLimit(
|
return _striker.StrikeAndCheckLimit(
|
||||||
record.DownloadId,
|
record.DownloadId,
|
||||||
record.Title,
|
record.Title,
|
||||||
@@ -134,4 +148,32 @@ public abstract class ArrClient
|
|||||||
{
|
{
|
||||||
request.Headers.Add("x-api-key", apiKey);
|
request.Headers.Add("x-api-key", apiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool HasIgnoredPatterns(QueueRecord record)
|
||||||
|
{
|
||||||
|
if (_queueCleanerConfig.ImportFailedIgnorePatterns?.Count is null or 0)
|
||||||
|
{
|
||||||
|
// no patterns are configured
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (record.StatusMessages?.Count is null or 0)
|
||||||
|
{
|
||||||
|
// no status message found
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<string> messages = record.StatusMessages
|
||||||
|
.SelectMany(x => x.Messages ?? Enumerable.Empty<string>())
|
||||||
|
.ToHashSet();
|
||||||
|
record.StatusMessages.Select(x => x.Title)
|
||||||
|
.ToList()
|
||||||
|
.ForEach(x => messages.Add(x));
|
||||||
|
|
||||||
|
return messages.Any(
|
||||||
|
m => _queueCleanerConfig.ImportFailedIgnorePatterns.Any(
|
||||||
|
p => !string.IsNullOrWhiteSpace(p.Trim()) && m.Contains(p, StringComparison.InvariantCultureIgnoreCase)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Common.Configuration.ContentBlocker;
|
using Common.Configuration.ContentBlocker;
|
||||||
|
using Common.Helpers;
|
||||||
using Domain.Enums;
|
using Domain.Enums;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
@@ -27,7 +28,7 @@ public sealed class BlocklistProvider
|
|||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_config = config.Value;
|
_config = config.Value;
|
||||||
_httpClient = httpClientFactory.CreateClient();
|
_httpClient = httpClientFactory.CreateClient(Constants.HttpClientWithRetryName);
|
||||||
|
|
||||||
_config.Validate();
|
_config.Validate();
|
||||||
|
|
||||||
|
|||||||
@@ -30,18 +30,19 @@ public sealed class DelugeService : DownloadServiceBase
|
|||||||
await _client.LoginAsync();
|
await _client.LoginAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<bool> ShouldRemoveFromArrQueueAsync(string hash)
|
public override async Task<RemoveResult> ShouldRemoveFromArrQueueAsync(string hash)
|
||||||
{
|
{
|
||||||
hash = hash.ToLowerInvariant();
|
hash = hash.ToLowerInvariant();
|
||||||
|
|
||||||
DelugeContents? contents = null;
|
DelugeContents? contents = null;
|
||||||
|
RemoveResult result = new();
|
||||||
|
|
||||||
TorrentStatus? status = await GetTorrentStatus(hash);
|
TorrentStatus? status = await GetTorrentStatus(hash);
|
||||||
|
|
||||||
if (status?.Hash is null)
|
if (status?.Hash is null)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("failed to find torrent {hash} in the download client", hash);
|
_logger.LogDebug("failed to find torrent {hash} in the download client", hash);
|
||||||
return false;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -63,7 +64,10 @@ public sealed class DelugeService : DownloadServiceBase
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return shouldRemove || IsItemStuckAndShouldRemove(status);
|
result.ShouldRemove = shouldRemove || IsItemStuckAndShouldRemove(status);
|
||||||
|
result.IsPrivate = status.Private;
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task BlockUnwantedFilesAsync(string hash)
|
public override async Task BlockUnwantedFilesAsync(string hash)
|
||||||
@@ -78,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
|
||||||
@@ -128,6 +139,18 @@ public sealed class DelugeService : DownloadServiceBase
|
|||||||
|
|
||||||
private bool IsItemStuckAndShouldRemove(TorrentStatus status)
|
private bool IsItemStuckAndShouldRemove(TorrentStatus status)
|
||||||
{
|
{
|
||||||
|
if (_queueCleanerConfig.StalledMaxStrikes is 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_queueCleanerConfig.StalledIgnorePrivate && status.Private)
|
||||||
|
{
|
||||||
|
// ignore private trackers
|
||||||
|
_logger.LogDebug("skip stalled check | download is private | {name}", status.Name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (status.State is null || !status.State.Equals("Downloading", StringComparison.InvariantCultureIgnoreCase))
|
if (status.State is null || !status.State.Equals("Downloading", StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -146,7 +169,7 @@ public sealed class DelugeService : DownloadServiceBase
|
|||||||
return await _client.SendRequest<TorrentStatus?>(
|
return await _client.SendRequest<TorrentStatus?>(
|
||||||
"web.get_torrent_status",
|
"web.get_torrent_status",
|
||||||
hash,
|
hash,
|
||||||
new[] { "hash", "state", "name", "eta" }
|
new[] { "hash", "state", "name", "eta", "private" }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public abstract class DownloadServiceBase : IDownloadService
|
|||||||
|
|
||||||
public abstract Task LoginAsync();
|
public abstract Task LoginAsync();
|
||||||
|
|
||||||
public abstract Task<bool> ShouldRemoveFromArrQueueAsync(string hash);
|
public abstract Task<RemoveResult> ShouldRemoveFromArrQueueAsync(string hash);
|
||||||
|
|
||||||
public abstract Task BlockUnwantedFilesAsync(string hash);
|
public abstract Task BlockUnwantedFilesAsync(string hash);
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public sealed class DummyDownloadService : DownloadServiceBase
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<bool> ShouldRemoveFromArrQueueAsync(string hash)
|
public override Task<RemoveResult> ShouldRemoveFromArrQueueAsync(string hash)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ public interface IDownloadService : IDisposable
|
|||||||
{
|
{
|
||||||
public Task LoginAsync();
|
public Task LoginAsync();
|
||||||
|
|
||||||
public Task<bool> ShouldRemoveFromArrQueueAsync(string hash);
|
public Task<RemoveResult> ShouldRemoveFromArrQueueAsync(string hash);
|
||||||
|
|
||||||
public Task BlockUnwantedFilesAsync(string hash);
|
public Task BlockUnwantedFilesAsync(string hash);
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Common.Configuration.DownloadClient;
|
using Common.Configuration.DownloadClient;
|
||||||
using Common.Configuration.QueueCleaner;
|
using Common.Configuration.QueueCleaner;
|
||||||
|
using Common.Helpers;
|
||||||
using Infrastructure.Verticals.ContentBlocker;
|
using Infrastructure.Verticals.ContentBlocker;
|
||||||
using Infrastructure.Verticals.ItemStriker;
|
using Infrastructure.Verticals.ItemStriker;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@@ -15,6 +16,7 @@ public sealed class QBitService : DownloadServiceBase
|
|||||||
|
|
||||||
public QBitService(
|
public QBitService(
|
||||||
ILogger<QBitService> logger,
|
ILogger<QBitService> logger,
|
||||||
|
IHttpClientFactory httpClientFactory,
|
||||||
IOptions<QBitConfig> config,
|
IOptions<QBitConfig> config,
|
||||||
IOptions<QueueCleanerConfig> queueCleanerConfig,
|
IOptions<QueueCleanerConfig> queueCleanerConfig,
|
||||||
FilenameEvaluator filenameEvaluator,
|
FilenameEvaluator filenameEvaluator,
|
||||||
@@ -23,7 +25,7 @@ public sealed class QBitService : DownloadServiceBase
|
|||||||
{
|
{
|
||||||
_config = config.Value;
|
_config = config.Value;
|
||||||
_config.Validate();
|
_config.Validate();
|
||||||
_client = new(_config.Url);
|
_client = new(httpClientFactory.CreateClient(Constants.HttpClientWithRetryName), _config.Url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task LoginAsync()
|
public override async Task LoginAsync()
|
||||||
@@ -36,21 +38,35 @@ public sealed class QBitService : DownloadServiceBase
|
|||||||
await _client.LoginAsync(_config.Username, _config.Password);
|
await _client.LoginAsync(_config.Username, _config.Password);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<bool> ShouldRemoveFromArrQueueAsync(string hash)
|
public override async Task<RemoveResult> ShouldRemoveFromArrQueueAsync(string hash)
|
||||||
{
|
{
|
||||||
|
RemoveResult result = new();
|
||||||
TorrentInfo? torrent = (await _client.GetTorrentListAsync(new TorrentListQuery { Hashes = [hash] }))
|
TorrentInfo? torrent = (await _client.GetTorrentListAsync(new TorrentListQuery { Hashes = [hash] }))
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
if (torrent is null)
|
if (torrent is null)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("failed to find torrent {hash} in the download client", hash);
|
_logger.LogDebug("failed to find torrent {hash} in the download client", hash);
|
||||||
return false;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TorrentProperties? torrentProperties = await _client.GetTorrentPropertiesAsync(hash);
|
||||||
|
|
||||||
|
if (torrentProperties is null)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("failed to find torrent properties {hash} in the download client", hash);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.IsPrivate = torrentProperties.AdditionalData.TryGetValue("is_private", out var dictValue) &&
|
||||||
|
bool.TryParse(dictValue?.ToString(), out bool boolValue)
|
||||||
|
&& boolValue;
|
||||||
|
|
||||||
// if all files were blocked by qBittorrent
|
// if all files were blocked by qBittorrent
|
||||||
if (torrent is { CompletionOn: not null, Downloaded: null or 0 })
|
if (torrent is { CompletionOn: not null, Downloaded: null or 0 })
|
||||||
{
|
{
|
||||||
return true;
|
result.ShouldRemove = true;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
IReadOnlyList<TorrentContent>? files = await _client.GetTorrentContentsAsync(hash);
|
IReadOnlyList<TorrentContent>? files = await _client.GetTorrentContentsAsync(hash);
|
||||||
@@ -58,14 +74,45 @@ public sealed class QBitService : DownloadServiceBase
|
|||||||
// if all files are marked as skip
|
// if all files are marked as skip
|
||||||
if (files?.Count is > 0 && files.All(x => x.Priority is TorrentContentPriority.Skip))
|
if (files?.Count is > 0 && files.All(x => x.Priority is TorrentContentPriority.Skip))
|
||||||
{
|
{
|
||||||
return true;
|
result.ShouldRemove = true;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return IsItemStuckAndShouldRemove(torrent);
|
result.ShouldRemove = IsItemStuckAndShouldRemove(torrent, result.IsPrivate);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
@@ -95,8 +142,20 @@ public sealed class QBitService : DownloadServiceBase
|
|||||||
_client.Dispose();
|
_client.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsItemStuckAndShouldRemove(TorrentInfo torrent)
|
private bool IsItemStuckAndShouldRemove(TorrentInfo torrent, bool isPrivate)
|
||||||
{
|
{
|
||||||
|
if (_queueCleanerConfig.StalledMaxStrikes is 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_queueCleanerConfig.StalledIgnorePrivate && isPrivate)
|
||||||
|
{
|
||||||
|
// ignore private trackers
|
||||||
|
_logger.LogDebug("skip stalled check | download is private | {name}", torrent.Name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (torrent.State is not TorrentState.StalledDownload and not TorrentState.FetchingMetadata
|
if (torrent.State is not TorrentState.StalledDownload and not TorrentState.FetchingMetadata
|
||||||
and not TorrentState.ForcedFetchingMetadata)
|
and not TorrentState.ForcedFetchingMetadata)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
namespace Infrastructure.Verticals.DownloadClient;
|
||||||
|
|
||||||
|
public sealed record RemoveResult
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// True if the download should be removed; otherwise false.
|
||||||
|
/// </summary>
|
||||||
|
public bool ShouldRemove { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True if the download is private; otherwise false.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsPrivate { get; set; }
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Common.Configuration.DownloadClient;
|
using Common.Configuration.DownloadClient;
|
||||||
using Common.Configuration.QueueCleaner;
|
using Common.Configuration.QueueCleaner;
|
||||||
|
using Common.Helpers;
|
||||||
using Infrastructure.Verticals.ContentBlocker;
|
using Infrastructure.Verticals.ContentBlocker;
|
||||||
using Infrastructure.Verticals.ItemStriker;
|
using Infrastructure.Verticals.ItemStriker;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@@ -17,6 +18,7 @@ public sealed class TransmissionService : DownloadServiceBase
|
|||||||
private TorrentInfo[]? _torrentsCache;
|
private TorrentInfo[]? _torrentsCache;
|
||||||
|
|
||||||
public TransmissionService(
|
public TransmissionService(
|
||||||
|
IHttpClientFactory httpClientFactory,
|
||||||
ILogger<TransmissionService> logger,
|
ILogger<TransmissionService> logger,
|
||||||
IOptions<TransmissionConfig> config,
|
IOptions<TransmissionConfig> config,
|
||||||
IOptions<QueueCleanerConfig> queueCleanerConfig,
|
IOptions<QueueCleanerConfig> queueCleanerConfig,
|
||||||
@@ -27,6 +29,7 @@ public sealed class TransmissionService : DownloadServiceBase
|
|||||||
_config = config.Value;
|
_config = config.Value;
|
||||||
_config.Validate();
|
_config.Validate();
|
||||||
_client = new(
|
_client = new(
|
||||||
|
httpClientFactory.CreateClient(Constants.HttpClientWithRetryName),
|
||||||
new Uri(_config.Url, "/transmission/rpc").ToString(),
|
new Uri(_config.Url, "/transmission/rpc").ToString(),
|
||||||
login: _config.Username,
|
login: _config.Username,
|
||||||
password: _config.Password
|
password: _config.Password
|
||||||
@@ -38,17 +41,19 @@ public sealed class TransmissionService : DownloadServiceBase
|
|||||||
await _client.GetSessionInformationAsync();
|
await _client.GetSessionInformationAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<bool> ShouldRemoveFromArrQueueAsync(string hash)
|
public override async Task<RemoveResult> ShouldRemoveFromArrQueueAsync(string hash)
|
||||||
{
|
{
|
||||||
|
RemoveResult result = new();
|
||||||
TorrentInfo? torrent = await GetTorrentAsync(hash);
|
TorrentInfo? torrent = await GetTorrentAsync(hash);
|
||||||
|
|
||||||
if (torrent is null)
|
if (torrent is null)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("failed to find torrent {hash} in the download client", hash);
|
_logger.LogDebug("failed to find torrent {hash} in the download client", hash);
|
||||||
return false;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shouldRemove = torrent.FileStats?.Length > 0;
|
bool shouldRemove = torrent.FileStats?.Length > 0;
|
||||||
|
result.IsPrivate = torrent.IsPrivate ?? false;
|
||||||
|
|
||||||
foreach (TransmissionTorrentFileStats? stats in torrent.FileStats ?? [])
|
foreach (TransmissionTorrentFileStats? stats in torrent.FileStats ?? [])
|
||||||
{
|
{
|
||||||
@@ -65,8 +70,10 @@ public sealed class TransmissionService : DownloadServiceBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove if all files are unwanted
|
// remove if all files are unwanted or download is stuck
|
||||||
return shouldRemove || IsItemStuckAndShouldRemove(torrent);
|
result.ShouldRemove = shouldRemove || IsItemStuckAndShouldRemove(torrent);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task BlockUnwantedFilesAsync(string hash)
|
public override async Task BlockUnwantedFilesAsync(string hash)
|
||||||
@@ -78,6 +85,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++)
|
||||||
@@ -116,6 +130,18 @@ public sealed class TransmissionService : DownloadServiceBase
|
|||||||
|
|
||||||
private bool IsItemStuckAndShouldRemove(TorrentInfo torrent)
|
private bool IsItemStuckAndShouldRemove(TorrentInfo torrent)
|
||||||
{
|
{
|
||||||
|
if (_queueCleanerConfig.StalledMaxStrikes is 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_queueCleanerConfig.StalledIgnorePrivate && (torrent.IsPrivate ?? false))
|
||||||
|
{
|
||||||
|
// ignore private trackers
|
||||||
|
_logger.LogDebug("skip stalled check | download is private | {name}", torrent.Name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (torrent.Status is not 4)
|
if (torrent.Status is not 4)
|
||||||
{
|
{
|
||||||
// not in downloading state
|
// not in downloading state
|
||||||
@@ -144,7 +170,8 @@ public sealed class TransmissionService : DownloadServiceBase
|
|||||||
TorrentFields.ID,
|
TorrentFields.ID,
|
||||||
TorrentFields.ETA,
|
TorrentFields.ETA,
|
||||||
TorrentFields.NAME,
|
TorrentFields.NAME,
|
||||||
TorrentFields.STATUS
|
TorrentFields.STATUS,
|
||||||
|
TorrentFields.IS_PRIVATE
|
||||||
];
|
];
|
||||||
|
|
||||||
// refresh cache
|
// refresh cache
|
||||||
|
|||||||
@@ -57,11 +57,16 @@ public sealed class QueueCleaner : GenericHandler
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shouldRemoveFromArr = arrClient.ShouldRemoveFromQueue(record);
|
RemoveResult removeResult = new();
|
||||||
bool shouldRemoveFromDownloadClient = _downloadClientConfig.DownloadClient is not Common.Enums.DownloadClient.None &&
|
|
||||||
await _downloadService.ShouldRemoveFromArrQueueAsync(record.DownloadId);
|
|
||||||
|
|
||||||
if (!shouldRemoveFromArr && !shouldRemoveFromDownloadClient)
|
if (_downloadClientConfig.DownloadClient is not Common.Enums.DownloadClient.None)
|
||||||
|
{
|
||||||
|
removeResult = await _downloadService.ShouldRemoveFromArrQueueAsync(record.DownloadId);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool shouldRemoveFromArr = arrClient.ShouldRemoveFromQueue(record, removeResult.IsPrivate);
|
||||||
|
|
||||||
|
if (!shouldRemoveFromArr && !removeResult.ShouldRemove)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("skip | {title}", record.Title);
|
_logger.LogInformation("skip | {title}", record.Title);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -176,15 +176,22 @@ services:
|
|||||||
- LOGGING__FILE__PATH=/var/logs
|
- LOGGING__FILE__PATH=/var/logs
|
||||||
- LOGGING__ENHANCED=true
|
- LOGGING__ENHANCED=true
|
||||||
|
|
||||||
|
- HTTP_MAX_RETRIES=0
|
||||||
|
- HTTP_TIMEOUT=20
|
||||||
|
|
||||||
- TRIGGERS__QUEUECLEANER=0/30 * * * * ?
|
- TRIGGERS__QUEUECLEANER=0/30 * * * * ?
|
||||||
- TRIGGERS__CONTENTBLOCKER=0/30 * * * * ?
|
- TRIGGERS__CONTENTBLOCKER=0/30 * * * * ?
|
||||||
|
|
||||||
- QUEUECLEANER__ENABLED=true
|
- QUEUECLEANER__ENABLED=true
|
||||||
- QUEUECLEANER__RUNSEQUENTIALLY=true
|
- QUEUECLEANER__RUNSEQUENTIALLY=true
|
||||||
- QUEUECLEANER__IMPORT_FAILED_MAX_STRIKES=5
|
- QUEUECLEANER__IMPORT_FAILED_MAX_STRIKES=5
|
||||||
|
- QUEUECLEANER__IMPORT_FAILED_IGNORE_PRIVATE=true
|
||||||
|
- QUEUECLEANER__IMPORT_FAILED_IGNORE_PATTERNS__0=file is a sample
|
||||||
- QUEUECLEANER__STALLED_MAX_STRIKES=5
|
- QUEUECLEANER__STALLED_MAX_STRIKES=5
|
||||||
|
- 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