Handle zipped DL only w/ file count > 100

This commit is contained in:
Sam Heinz 2024-09-04 17:14:36 +10:00
parent 70584d1acb
commit 320c52c4be
3 changed files with 31 additions and 22 deletions

View file

@ -177,6 +177,14 @@ or
[DisplayName("Auto Import Defaults")] [DisplayName("Auto Import Defaults")]
public DbSettingsDefaultsWithCategory Default { get; set; } = new(); public DbSettingsDefaultsWithCategory Default { get; set; } = new();
[DisplayName("Seeding")]
[Description("Set the priority of a torrent, 1 = Auto, 2 = Seed, 3 = disabled. [TorBox Only]")]
public Int32 Seeding { get; set; } = 3;
[DisplayName("Download as Zip")]
[Description("Whether to download the files individually or zipped. [TorBox Only]")]
public bool Zipped { get; set; } = true;
} }
public class DbSettingsIntegrations public class DbSettingsIntegrations
@ -263,12 +271,4 @@ public class DbSettingsDefaults
[DisplayName("Priority")] [DisplayName("Priority")]
[Description("Set the priority of a torrent, 1 = highest, 0 = disabled.")] [Description("Set the priority of a torrent, 1 = highest, 0 = disabled.")]
public Int32 Priority { get; set; } = 0; public Int32 Priority { get; set; } = 0;
[DisplayName("Seeding")]
[Description("Set the priority of a torrent, 1 = Auto, 2 = Seed, 3 = disabled. [TorBox Only]")]
public Int32 Seeding { get; set; } = 3;
[DisplayName("Download as Zip")]
[Description("Whether to download the files individually or zipped. [TorBox Only]")]
public bool Zipped { get; set; } = true;
} }

View file

@ -22,7 +22,7 @@
<PackageReference Include="Serilog" Version="4.0.0" /> <PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" /> <PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="SharpCompress" Version="0.37.2" /> <PackageReference Include="SharpCompress" Version="0.37.2" />
<PackageReference Include="TorBox.NET" Version="1.0.0.39" /> <PackageReference Include="TorBox.NET" Version="1.0.0.40" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -4,14 +4,12 @@ using TorBoxNET;
using RdtClient.Data.Enums; using RdtClient.Data.Enums;
using RdtClient.Data.Models.TorrentClient; using RdtClient.Data.Models.TorrentClient;
using RdtClient.Service.Helpers; using RdtClient.Service.Helpers;
using RdtClient.Data.Models.Internal;
namespace RdtClient.Service.Services.TorrentClients; namespace RdtClient.Service.Services.TorrentClients;
public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClientFactory httpClientFactory) : ITorrentClient public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClientFactory httpClientFactory) : ITorrentClient
{ {
private TimeSpan? _offset; private TimeSpan? _offset;
private DbSettingsDefaults _dbSettings = new DbSettingsDefaults();
private TorBoxNetClient GetClient() private TorBoxNetClient GetClient()
{ {
try try
@ -122,8 +120,9 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
public async Task<String> AddMagnet(String magnetLink) public async Task<String> AddMagnet(String magnetLink)
{ {
var seeding = Settings.Get.Provider.Seeding;
var result = await GetClient().Torrents.AddMagnetAsync(magnetLink, _dbSettings.Seeding, _dbSettings.Zipped); var zipped = Settings.Get.Provider.Zipped;
var result = await GetClient().Torrents.AddMagnetAsync(magnetLink, seeding, zipped);
if (result.Error == "ACTIVE_LIMIT") if (result.Error == "ACTIVE_LIMIT")
{ {
@ -138,7 +137,9 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
public async Task<String> AddFile(Byte[] bytes) public async Task<String> AddFile(Byte[] bytes)
{ {
var result = await GetClient().Torrents.AddFileAsync(bytes, _dbSettings.Seeding, _dbSettings.Zipped); var seeding = Settings.Get.Provider.Seeding;
var zipped = Settings.Get.Provider.Zipped;
var result = await GetClient().Torrents.AddFileAsync(bytes, seeding, zipped);
if (result.Error == "ACTIVE_LIMIT") if (result.Error == "ACTIVE_LIMIT")
{ {
using (var stream = new MemoryStream(bytes)) using (var stream = new MemoryStream(bytes))
@ -189,17 +190,21 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
await GetClient().Torrents.ControlAsync(torrentId, "delete"); await GetClient().Torrents.ControlAsync(torrentId, "delete");
} }
public async Task<String> Unrestrict(String link) public async Task<string> Unrestrict(string link)
{ {
var torrentFile = new List<string>(link.Split('/')); var segments = link.Split('/');
var result = await GetClient().Unrestrict.LinkAsync(torrentID: torrentFile[4], fileID: torrentFile[5]);
if (result.Error != null) bool zipped = segments[5] == "zip";
string fileId = zipped ? "0" : segments[5];
var result = await GetClient().Unrestrict.LinkAsync(torrentID: segments[4], fileID: fileId, zipped: zipped);
if (result?.Error != null)
{ {
throw new($"Unrestrict returned an invalid download"); throw new("Unrestrict returned an invalid download");
} }
return result.Data!; return result!.Data!;
} }
public async Task<Data.Models.Data.Torrent> UpdateData(Data.Models.Data.Torrent torrent, TorrentClientTorrent? torrentClientTorrent) public async Task<Data.Models.Data.Torrent> UpdateData(Data.Models.Data.Torrent torrent, TorrentClientTorrent? torrentClientTorrent)
@ -297,8 +302,12 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
var files = new List<String>(); var files = new List<String>();
var torrentId = await GetClient().Torrents.GetInfoAsync(torrent.Hash, skipCache: true); var torrentId = await GetClient().Torrents.GetInfoAsync(torrent.Hash, skipCache: true);
if (Settings.Get.Provider.Zipped == true && rdTorrent.Files!.Count() > 100 && torrentId!.AllowZipped == true)
if (rdTorrent.Files?.Count != 0) {
var newFile = $"https://torbox.app/fakedl/{torrentId?.Id}/zip";
files.Add(newFile);
}
else if (rdTorrent.Files?.Count != 0)
{ {
foreach (var file in rdTorrent.Files!) foreach (var file in rdTorrent.Files!)
{ {