Return number of selected files from SelectFiles so we can handle all files being excluded
This commit is contained in:
parent
3f4fb6d20a
commit
aa3f24ff50
7 changed files with 55 additions and 19 deletions
|
|
@ -155,9 +155,10 @@ public class AllDebridTorrentClient(ILogger<AllDebridTorrentClient> logger, IAll
|
|||
return Task.FromResult<IList<TorrentClientAvailableFile>>([]);
|
||||
}
|
||||
|
||||
public Task SelectFiles(Torrent torrent)
|
||||
/// <inheritdoc />
|
||||
public Task<Int32?> SelectFiles(Torrent torrent)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
return Task.FromResult<Int32?>(torrent.Files.Count);
|
||||
}
|
||||
|
||||
public async Task Delete(String torrentId)
|
||||
|
|
|
|||
|
|
@ -136,9 +136,10 @@ public class DebridLinkClient(ILogger<DebridLinkClient> logger, IHttpClientFacto
|
|||
return Task.FromResult<IList<TorrentClientAvailableFile>>([]);
|
||||
}
|
||||
|
||||
public Task SelectFiles(Data.Models.Data.Torrent torrent)
|
||||
/// <inheritdoc />
|
||||
public Task<Int32?> SelectFiles(Data.Models.Data.Torrent torrent)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
return Task.FromResult<Int32?>(torrent.Files.Count);
|
||||
}
|
||||
|
||||
public async Task Delete(String torrentId)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,15 @@ public interface ITorrentClient
|
|||
Task<String> AddMagnet(String magnetLink);
|
||||
Task<String> AddFile(Byte[] bytes);
|
||||
Task<IList<TorrentClientAvailableFile>> GetAvailableFiles(String hash);
|
||||
Task SelectFiles(Torrent torrent);
|
||||
/// <summary>
|
||||
/// Tell the debrid provider which files to download.
|
||||
/// </summary>
|
||||
/// <remark>
|
||||
/// Not all providers support this feature.
|
||||
/// </remark>
|
||||
/// <param name="torrent">The torrent to select files for</param>
|
||||
/// <returns>Number of files selected</returns>
|
||||
Task<Int32?> SelectFiles(Torrent torrent);
|
||||
Task Delete(String torrentId);
|
||||
Task<String> Unrestrict(String link);
|
||||
Task<Torrent> UpdateData(Torrent torrent, TorrentClientTorrent? torrentClientTorrent);
|
||||
|
|
|
|||
|
|
@ -121,9 +121,12 @@ public class PremiumizeTorrentClient(ILogger<PremiumizeTorrentClient> logger, IH
|
|||
return Task.FromResult<IList<TorrentClientAvailableFile>>([]);
|
||||
}
|
||||
|
||||
public Task SelectFiles(Torrent torrent)
|
||||
/// <inheritdoc />
|
||||
public Task<Int32?> SelectFiles(Torrent torrent)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
// torrent.Files is not populated when this function is called
|
||||
// by returning 1, we ensure no logic for "all files excluded" is followed
|
||||
return Task.FromResult<Int32?>(1);
|
||||
}
|
||||
|
||||
public async Task Delete(String id)
|
||||
|
|
|
|||
|
|
@ -142,7 +142,8 @@ public class RealDebridTorrentClient(ILogger<RealDebridTorrentClient> logger, IH
|
|||
return Task.FromResult<IList<TorrentClientAvailableFile>>([]);
|
||||
}
|
||||
|
||||
public async Task SelectFiles(Data.Models.Data.Torrent torrent)
|
||||
/// <inheritdoc />
|
||||
public async Task<Int32?> SelectFiles(Data.Models.Data.Torrent torrent)
|
||||
{
|
||||
List<TorrentClientFile> files;
|
||||
|
||||
|
|
@ -166,7 +167,14 @@ public class RealDebridTorrentClient(ILogger<RealDebridTorrentClient> logger, IH
|
|||
|
||||
var fileIds = files.Select(m => m.Id.ToString()).ToArray();
|
||||
|
||||
if (fileIds.Length == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
await GetClient().Torrents.SelectFilesAsync(torrent.RdId!, [.. fileIds]);
|
||||
|
||||
return fileIds.Length;
|
||||
}
|
||||
|
||||
public async Task Delete(String torrentId)
|
||||
|
|
|
|||
|
|
@ -171,9 +171,10 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
|
|||
return [];
|
||||
}
|
||||
|
||||
public Task SelectFiles(Torrent torrent)
|
||||
/// <inheritdoc />
|
||||
public Task<Int32?> SelectFiles(Torrent torrent)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
return Task.FromResult<Int32?>(torrent.Files.Count);
|
||||
}
|
||||
|
||||
public async Task Delete(String torrentId)
|
||||
|
|
|
|||
|
|
@ -223,7 +223,12 @@ public class Torrents(
|
|||
return;
|
||||
}
|
||||
|
||||
await TorrentClient.SelectFiles(torrent);
|
||||
var selected = await TorrentClient.SelectFiles(torrent);
|
||||
|
||||
if (selected == 0)
|
||||
{
|
||||
await MarkAllFilesExcluded(torrent);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateDownloads(Guid torrentId)
|
||||
|
|
@ -244,14 +249,7 @@ public class Torrents(
|
|||
|
||||
if (downloadLinks.Count == 0)
|
||||
{
|
||||
logger.LogInformation("All files excluded by filters (IncludeRegex: {includeRegex}, ExcludeRegex: {excludeRegex}, DownloadMinSize: {downloadMinSize} {torrentInfo}",
|
||||
torrent.IncludeRegex,
|
||||
torrent.ExcludeRegex,
|
||||
torrent.DownloadMinSize,
|
||||
torrent.ToLog());
|
||||
|
||||
await torrentData.UpdateRetry(torrentId, null, torrent.TorrentRetryAttempts);
|
||||
await torrentData.UpdateComplete(torrentId, "All files excluded", DateTimeOffset.Now, false);
|
||||
await MarkAllFilesExcluded(torrent);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -268,6 +266,22 @@ public class Torrents(
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs a message to the console, sets the error on the torrent and ensures it is not retried.
|
||||
/// </summary>
|
||||
/// <param name="torrent">The torrent to mark as "All files excluded"</param>
|
||||
private async Task MarkAllFilesExcluded(Torrent torrent)
|
||||
{
|
||||
logger.LogInformation("All files excluded by filters (IncludeRegex: {includeRegex}, ExcludeRegex: {excludeRegex}, DownloadMinSize: {downloadMinSize}) {torrentInfo}",
|
||||
torrent.IncludeRegex,
|
||||
torrent.ExcludeRegex,
|
||||
torrent.DownloadMinSize,
|
||||
torrent.ToLog());
|
||||
|
||||
await torrentData.UpdateRetry(torrent.TorrentId, null, torrent.TorrentRetryAttempts);
|
||||
await torrentData.UpdateComplete(torrent.TorrentId, "All files excluded", DateTimeOffset.Now, false);
|
||||
}
|
||||
|
||||
public async Task Delete(Guid torrentId, Boolean deleteData, Boolean deleteRdTorrent, Boolean deleteLocalFiles)
|
||||
{
|
||||
var torrent = await GetById(torrentId);
|
||||
|
|
|
|||
Loading…
Reference in a new issue