Prevent spamming Real-Debrid when a torrent is completed, do more efficient periodic updates. Fetch more torrents in 1 go to prevent too many endpoint requests.
This commit is contained in:
parent
86eaccd439
commit
2ec3a3b5ca
1 changed files with 29 additions and 26 deletions
|
|
@ -92,12 +92,12 @@ public class RealDebridTorrentClient(ILogger<RealDebridTorrentClient> logger, IH
|
||||||
|
|
||||||
public async Task<IList<TorrentClientTorrent>> GetTorrents()
|
public async Task<IList<TorrentClientTorrent>> GetTorrents()
|
||||||
{
|
{
|
||||||
var page = 0;
|
var offset = 0;
|
||||||
var results = new List<Torrent>();
|
var results = new List<Torrent>();
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var pagedResults = await GetClient().Torrents.GetAsync(page, 100);
|
var pagedResults = await GetClient().Torrents.GetAsync(offset, 5000);
|
||||||
|
|
||||||
results.AddRange(pagedResults);
|
results.AddRange(pagedResults);
|
||||||
|
|
||||||
|
|
@ -106,7 +106,7 @@ public class RealDebridTorrentClient(ILogger<RealDebridTorrentClient> logger, IH
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
page += 100;
|
offset += 5000;
|
||||||
}
|
}
|
||||||
|
|
||||||
return results.Select(Map).ToList();
|
return results.Select(Map).ToList();
|
||||||
|
|
@ -287,42 +287,45 @@ public class RealDebridTorrentClient(ILogger<RealDebridTorrentClient> logger, IH
|
||||||
return torrent;
|
return torrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
var rdTorrent = await GetInfo(torrent.RdId) ?? throw new($"Resource not found");
|
if (torrentClientTorrent == null || torrentClientTorrent.Ended == null)
|
||||||
|
|
||||||
if (!String.IsNullOrWhiteSpace(rdTorrent.Filename))
|
|
||||||
{
|
{
|
||||||
torrent.RdName = rdTorrent.Filename;
|
torrentClientTorrent = await GetInfo(torrent.RdId) ?? throw new($"Resource not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!String.IsNullOrWhiteSpace(rdTorrent.OriginalFilename))
|
if (!String.IsNullOrWhiteSpace(torrentClientTorrent.Filename))
|
||||||
{
|
{
|
||||||
torrent.RdName = rdTorrent.OriginalFilename;
|
torrent.RdName = torrentClientTorrent.Filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rdTorrent.Bytes > 0)
|
if (!String.IsNullOrWhiteSpace(torrentClientTorrent.OriginalFilename))
|
||||||
{
|
{
|
||||||
torrent.RdSize = rdTorrent.Bytes;
|
torrent.RdName = torrentClientTorrent.OriginalFilename;
|
||||||
}
|
|
||||||
else if (rdTorrent.OriginalBytes > 0)
|
|
||||||
{
|
|
||||||
torrent.RdSize = rdTorrent.OriginalBytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rdTorrent.Files != null)
|
if (torrentClientTorrent.Bytes > 0)
|
||||||
{
|
{
|
||||||
torrent.RdFiles = JsonConvert.SerializeObject(rdTorrent.Files);
|
torrent.RdSize = torrentClientTorrent.Bytes;
|
||||||
|
}
|
||||||
|
else if (torrentClientTorrent.OriginalBytes > 0)
|
||||||
|
{
|
||||||
|
torrent.RdSize = torrentClientTorrent.OriginalBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent.RdHost = rdTorrent.Host;
|
if (torrentClientTorrent.Files != null && torrentClientTorrent.Files.Count > 0)
|
||||||
torrent.RdSplit = rdTorrent.Split;
|
{
|
||||||
torrent.RdProgress = rdTorrent.Progress;
|
torrent.RdFiles = JsonConvert.SerializeObject(torrentClientTorrent.Files);
|
||||||
torrent.RdAdded = rdTorrent.Added;
|
}
|
||||||
torrent.RdEnded = rdTorrent.Ended;
|
|
||||||
torrent.RdSpeed = rdTorrent.Speed;
|
|
||||||
torrent.RdSeeders = rdTorrent.Seeders;
|
|
||||||
torrent.RdStatusRaw = rdTorrent.Status;
|
|
||||||
|
|
||||||
torrent.RdStatus = rdTorrent.Status switch
|
torrent.RdHost = torrentClientTorrent.Host;
|
||||||
|
torrent.RdSplit = torrentClientTorrent.Split;
|
||||||
|
torrent.RdProgress = torrentClientTorrent.Progress;
|
||||||
|
torrent.RdAdded = torrentClientTorrent.Added;
|
||||||
|
torrent.RdEnded = torrentClientTorrent.Ended;
|
||||||
|
torrent.RdSpeed = torrentClientTorrent.Speed;
|
||||||
|
torrent.RdSeeders = torrentClientTorrent.Seeders;
|
||||||
|
torrent.RdStatusRaw = torrentClientTorrent.Status;
|
||||||
|
|
||||||
|
torrent.RdStatus = torrentClientTorrent.Status switch
|
||||||
{
|
{
|
||||||
"magnet_error" => TorrentStatus.Error,
|
"magnet_error" => TorrentStatus.Error,
|
||||||
"magnet_conversion" => TorrentStatus.Processing,
|
"magnet_conversion" => TorrentStatus.Processing,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue