From 395f83847e0badaa7e1d3e34e5d458f07a7ec29f Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Tue, 27 Aug 2024 19:11:24 +1000 Subject: [PATCH] Add Getting DL link, tracking via hash --- .../TorrentClients/TorBoxTorrentClient.cs | 64 ++++--------------- 1 file changed, 13 insertions(+), 51 deletions(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index 81935a7..fb65098 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -127,14 +127,14 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien { var result = await GetClient().Torrents.AddMagnetAsync(magnetLink); - return result.Data?.Torrent_ID.ToString()!; + return result.Data?.Hash?.ToString()!; } public async Task AddFile(Byte[] bytes) { var result = await GetClient().Torrents.AddFileAsync(bytes); - return result.Data?.Torrent_ID.ToString()!; + return result.Data?.Hash?.ToString()!; } public Task> GetAvailableFiles(String hash) @@ -157,12 +157,12 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien { var result = await GetClient().Unrestrict.LinkAsync(link); - if (result.Download == null) + if (result.Error != null) { throw new($"Unrestrict returned an invalid download"); } - return result.Download; + return result.Data!; } public async Task UpdateData(Data.Models.Data.Torrent torrent, TorrentClientTorrent? torrentClientTorrent) @@ -250,63 +250,25 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien public async Task?> GetDownloadLinks(Data.Models.Data.Torrent torrent) { - if (torrent.RdId == null) + if (torrent.Hash == null) { return null; } - var rdTorrent = await GetInfo(torrent.RdId); + var rdTorrent = await GetInfo(torrent.Hash); - if (rdTorrent.Links == null) + var files = new List(); + + if (rdTorrent.Files?.Count != 0) { - return null; - } - - var downloadLinks = rdTorrent.Links.Where(m => !String.IsNullOrWhiteSpace(m)).ToList(); - - Log($"Found {downloadLinks.Count} links", torrent); - - foreach (var link in downloadLinks) - { - Log($"{link}", torrent); - } - - Log($"Torrent has {torrent.Files.Count(m => m.Selected)} selected files out of {torrent.Files.Count} files, found {downloadLinks.Count} links, torrent ended: {torrent.RdEnded}", torrent); - - // Check if all the links are set that have been selected - if (torrent.Files.Count(m => m.Selected) == downloadLinks.Count) - { - Log($"Matched {torrent.Files.Count(m => m.Selected)} selected files expected files to {downloadLinks.Count} found files", torrent); - - return downloadLinks; - } - - // Check if all all the links are set for manual selection - if (torrent.ManualFiles.Count == downloadLinks.Count) - { - Log($"Matched {torrent.ManualFiles.Count} manual files expected files to {downloadLinks.Count} found files", torrent); - - return downloadLinks; - } - - // If there is only 1 link, delay for 1 minute to see if more links pop up. - if (downloadLinks.Count == 1 && torrent.RdEnded.HasValue) - { - var expired = DateTime.UtcNow - torrent.RdEnded.Value.ToUniversalTime(); - - Log($"Waiting to see if more links appear, checked for {expired.TotalSeconds} seconds", torrent); - - if (expired.TotalSeconds > 60.0) + foreach (var file in rdTorrent.Files!) { - Log($"Waited long enough", torrent); - - return downloadLinks; + var newFile = new List { rdTorrent.Id, file.Id.ToString() }; + files.Add(newFile.ToString()!); } } - Log($"Did not find any suiteable download links", torrent); - - return null; + return files; } private DateTimeOffset? ChangeTimeZone(DateTimeOffset? dateTimeOffset)