Compare commits

...

2 Commits

Author SHA1 Message Date
Flaminel
479ca7884e Fix crashing when tracker url is malformed (#121) 2025-04-28 16:48:54 +03:00
Flaminel
00d8910118 Update README.md 2025-04-12 23:43:44 +03:00
8 changed files with 62 additions and 11 deletions

View File

@@ -131,10 +131,14 @@ I've seen a few discussions on this type of naming and I've decided that I didn'
1. Set `QUEUECLEANER__ENABLED` to `true`.
2. Set `QUEUECLEANER__IMPORT_FAILED_MAX_STRIKES` to a desired value.
3. Optionally set failed import message patterns to ignore using `QUEUECLEANER__IMPORT_FAILED_IGNORE_PATTERNS__<NUMBER>`.
4. Set `DOWNLOAD_CLIENT` to `none`.
4. Set `DOWNLOAD_CLIENT` to `none`(works only for usenet) or `disabled` (works for both usenet and torrent).
> [!WARNING]
> When `DOWNLOAD_CLIENT=none`, no other action involving a download client would work (e.g. content blocking, removing stalled downloads, excluding private trackers).
> [!IMPORTANT]
> When `DOWNLOAD_CLIENT=disabled`, no other action involving a download client would work (e.g. content blocking, removing stalled downloads, excluding private trackers).
>
> When the download client is set to `disabled`, the queue cleaner will be able to remove items that are failed to be imported even if there is no download client configured. This means that all downloads, including private ones, will be completely removed.
>
> Setting `DOWNLOAD_CLIENT=disabled` means you don't care about seeding, ratio, H&R and potentially losing your private tracker account.
## Usage

View File

@@ -35,5 +35,5 @@ public sealed record DownloadStatus
public sealed record Tracker
{
public required Uri Url { get; init; }
public required string Url { get; init; }
}

View File

@@ -1,4 +1,5 @@
using Domain.Models.Deluge.Response;
using Infrastructure.Helpers;
namespace Infrastructure.Extensions;
@@ -18,7 +19,7 @@ public static class DelugeExtensions
return true;
}
if (download.Trackers.Any(x => x.Url.Host.EndsWith(value, StringComparison.InvariantCultureIgnoreCase)))
if (download.Trackers.Any(x => UriService.GetDomain(x.Url)?.EndsWith(value, StringComparison.InvariantCultureIgnoreCase) ?? false))
{
return true;
}

View File

@@ -1,4 +1,5 @@
using QBittorrent.Client;
using Infrastructure.Helpers;
using QBittorrent.Client;
namespace Infrastructure.Extensions;
@@ -29,9 +30,16 @@ public static class QBitExtensions
public static bool ShouldIgnore(this TorrentTracker tracker, IReadOnlyList<string> ignoredDownloads)
{
string? trackerUrl = UriService.GetDomain(tracker.Url);
if (trackerUrl is null)
{
return false;
}
foreach (string value in ignoredDownloads)
{
if (tracker.Url.Host.EndsWith(value, StringComparison.InvariantCultureIgnoreCase))
if (trackerUrl.EndsWith(value, StringComparison.InvariantCultureIgnoreCase))
{
return true;
}

View File

@@ -1,4 +1,5 @@
using Transmission.API.RPC.Entity;
using Infrastructure.Helpers;
using Transmission.API.RPC.Entity;
namespace Infrastructure.Extensions;
@@ -19,7 +20,7 @@ public static class TransmissionExtensions
}
bool? hasIgnoredTracker = download.Trackers?
.Any(x => new Uri(x.Announce!).Host.EndsWith(value, StringComparison.InvariantCultureIgnoreCase));
.Any(x => UriService.GetDomain(x.Announce)?.EndsWith(value, StringComparison.InvariantCultureIgnoreCase) ?? false);
if (hasIgnoredTracker is true)
{

View File

@@ -0,0 +1,37 @@
using System.Text.RegularExpressions;
namespace Infrastructure.Helpers;
public static class UriService
{
public static string? GetDomain(string? input)
{
if (string.IsNullOrWhiteSpace(input))
{
return null;
}
// add "http://" if scheme is missing to help Uri.TryCreate
if (!input.StartsWith("http", StringComparison.OrdinalIgnoreCase))
{
input = "http://" + input;
}
if (Uri.TryCreate(input, UriKind.Absolute, out var uri))
{
return uri.Host;
}
// url might be malformed
var regex = new Regex(@"^(?:https?:\/\/)?([^\/\?:]+)", RegexOptions.IgnoreCase);
var match = regex.Match(input);
if (match.Success)
{
return match.Groups[1].Value;
}
// could not extract
return null;
}
}

View File

@@ -12,7 +12,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="FLM.QBittorrent" Version="1.0.0" />
<PackageReference Include="FLM.QBittorrent" Version="1.0.1" />
<PackageReference Include="FLM.Transmission" Version="1.0.3" />
<PackageReference Include="Mapster" Version="7.4.0" />
<PackageReference Include="MassTransit" Version="8.3.6" />

View File

@@ -428,7 +428,7 @@ public class QBitService : DownloadService, IQBitService
private async Task<IReadOnlyList<TorrentTracker>> GetTrackersAsync(string hash)
{
return (await _client.GetTorrentTrackersAsync(hash))
.Where(x => !x.Url.ToString().Contains("**"))
.Where(x => x.Url.Contains("**"))
.ToList();
}
}