Add Getting DL link, tracking via hash
This commit is contained in:
parent
fc9ea4c29a
commit
395f83847e
1 changed files with 13 additions and 51 deletions
|
|
@ -127,14 +127,14 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
|
|||
{
|
||||
var result = await GetClient().Torrents.AddMagnetAsync(magnetLink);
|
||||
|
||||
return result.Data?.Torrent_ID.ToString()!;
|
||||
return result.Data?.Hash?.ToString()!;
|
||||
}
|
||||
|
||||
public async Task<String> AddFile(Byte[] bytes)
|
||||
{
|
||||
var result = await GetClient().Torrents.AddFileAsync(bytes);
|
||||
|
||||
return result.Data?.Torrent_ID.ToString()!;
|
||||
return result.Data?.Hash?.ToString()!;
|
||||
}
|
||||
|
||||
public Task<IList<TorrentClientAvailableFile>> GetAvailableFiles(String hash)
|
||||
|
|
@ -157,12 +157,12 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> 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<Data.Models.Data.Torrent> UpdateData(Data.Models.Data.Torrent torrent, TorrentClientTorrent? torrentClientTorrent)
|
||||
|
|
@ -250,63 +250,25 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
|
|||
|
||||
public async Task<IList<String>?> 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<String>();
|
||||
|
||||
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<String> { 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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue