[TB] GetDownloadLinks -> GetDownloadInfos

This commit is contained in:
Cucumberrbob 2025-03-11 12:14:15 +00:00
parent 0cc15d26c3
commit c50afe9e64
No known key found for this signature in database
GPG key ID: 2B935C47401C3614

View file

@ -1,9 +1,9 @@
using System.Diagnostics;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using TorBoxNET; using TorBoxNET;
using RdtClient.Data.Enums; using RdtClient.Data.Enums;
using RdtClient.Data.Models.TorrentClient; using RdtClient.Data.Models.TorrentClient;
using System.Web;
using RdtClient.Data.Models.Data; using RdtClient.Data.Models.Data;
using RdtClient.Service.Helpers; using RdtClient.Service.Helpers;
@ -284,39 +284,21 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
return torrent; return torrent;
} }
public async Task<IList<String>?> GetDownloadLinks(Torrent torrent) public async Task<IList<DownloadInfo>?> GetDownloadInfos(Torrent torrent)
{ {
var torrentId = await GetClient().Torrents.GetHashInfoAsync(torrent.Hash, skipCache: true); var torrentId = await GetClient().Torrents.GetHashInfoAsync(torrent.Hash, skipCache: true);
return torrent.Files.Where(file => fileFilter.IsDownloadable(torrent, file.Path, file.Bytes)) return torrent.Files.Where(file => fileFilter.IsDownloadable(torrent, file.Path, file.Bytes))
.Select(file => $"https://torbox.app/fakedl/{torrentId?.Id}/{file.Id}") .Select(file => new DownloadInfo { RestrictedLink = $"https://torbox.app/fakedl/{torrentId?.Id}/{file.Id}", FileName = Path.GetFileName(file.Path)})
.ToList(); .ToList();
} }
public async Task<String> GetFileName(String downloadUrl) public Task<String> GetFileName(Download download)
{ {
if (String.IsNullOrWhiteSpace(downloadUrl)) // FileName is set in GetDownlaadInfos
{ Debug.Assert(download.FileName != null);
return "";
}
var uri = new Uri(downloadUrl); return Task.FromResult(download.FileName);
using (HttpClient client = new())
{
var request = new HttpRequestMessage(HttpMethod.Head, uri);
var response = await client.SendAsync(request);
if (response.Content.Headers.ContentDisposition != null)
{
var fileName = response.Content.Headers.ContentDisposition.FileName;
if (!String.IsNullOrWhiteSpace(fileName))
{
return fileName.Trim('"');
}
}
}
return HttpUtility.UrlDecode(uri.Segments.Last());
} }
private DateTimeOffset? ChangeTimeZone(DateTimeOffset? dateTimeOffset) private DateTimeOffset? ChangeTimeZone(DateTimeOffset? dateTimeOffset)