From 350185b702607d4f59430a8ab62face65c2ef9b1 Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Tue, 10 Dec 2024 23:45:13 +1000 Subject: [PATCH] [TB] Refactor GetFileName in Torrent Clients --- .../TorrentClients/AllDebridTorrentClient.cs | 6 +++--- .../Services/TorrentClients/ITorrentClient.cs | 2 +- .../TorrentClients/PremiumizeTorrentClient.cs | 6 +++--- .../TorrentClients/RealDebridTorrentClient.cs | 6 +++--- .../Services/TorrentClients/TorBoxTorrentClient.cs | 12 ++++++------ 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/AllDebridTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/AllDebridTorrentClient.cs index 540b3d3..3c7c789 100644 --- a/server/RdtClient.Service/Services/TorrentClients/AllDebridTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/AllDebridTorrentClient.cs @@ -263,14 +263,14 @@ public class AllDebridTorrentClient(ILogger logger, IHtt return links.Select(m => m.LinkUrl.ToString()).ToList(); } - public Task GetFileName(Data.Models.Data.Download download) + public Task GetFileName(String downloadUrl) { - if (String.IsNullOrWhiteSpace(download.Link)) + if (String.IsNullOrWhiteSpace(downloadUrl)) { return Task.FromResult(null); } - var uri = new Uri(download.Link); + var uri = new Uri(downloadUrl); return Task.FromResult(HttpUtility.UrlDecode(uri.Segments.Last())); } diff --git a/server/RdtClient.Service/Services/TorrentClients/ITorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/ITorrentClient.cs index 95fb597..2813da8 100644 --- a/server/RdtClient.Service/Services/TorrentClients/ITorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/ITorrentClient.cs @@ -15,5 +15,5 @@ public interface ITorrentClient Task Unrestrict(String link); Task UpdateData(Torrent torrent, TorrentClientTorrent? torrentClientTorrent); Task?> GetDownloadLinks(Torrent torrent); - Task GetFileName(Download download); + Task GetFileName(String downloadUrl); } \ No newline at end of file diff --git a/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs index ab33428..b91790b 100644 --- a/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs @@ -242,14 +242,14 @@ public class PremiumizeTorrentClient(ILogger logger, IH return downloadLinks; } - public Task GetFileName(Data.Models.Data.Download download) + public Task GetFileName(String downloadUrl) { - if (String.IsNullOrWhiteSpace(download.Link)) + if (String.IsNullOrWhiteSpace(downloadUrl)) { return Task.FromResult(null); } - var uri = new Uri(download.Link); + var uri = new Uri(downloadUrl); return Task.FromResult(HttpUtility.UrlDecode(uri.Segments.Last())); } diff --git a/server/RdtClient.Service/Services/TorrentClients/RealDebridTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/RealDebridTorrentClient.cs index ecf4337..459cb7a 100644 --- a/server/RdtClient.Service/Services/TorrentClients/RealDebridTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/RealDebridTorrentClient.cs @@ -396,14 +396,14 @@ public class RealDebridTorrentClient(ILogger logger, IH return null; } - public Task GetFileName(Data.Models.Data.Download download) + public Task GetFileName(String downloadUrl) { - if (String.IsNullOrWhiteSpace(download.Link)) + if (String.IsNullOrWhiteSpace(downloadUrl)) { return Task.FromResult(null); } - var uri = new Uri(download.Link); + var uri = new Uri(downloadUrl); return Task.FromResult(HttpUtility.UrlDecode(uri.Segments.Last())); } diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index 07402ab..6ebe877 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -161,7 +161,7 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien { var availability = await GetClient().Torrents.GetAvailabilityAsync(hash, listFiles: true); - if (availability.Data != null) + if (availability.Data != null || availability.Data?.Count < 0) { return (availability.Data[0]?.Files ?? []).Select(file => new TorrentClientAvailableFile { @@ -302,18 +302,18 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien return files; } - public async Task GetFileName(Data.Models.Data.Download download) + public async Task GetFileName(String downloadUrl) { - if (String.IsNullOrWhiteSpace(download.Link)) + if (String.IsNullOrWhiteSpace(downloadUrl)) { return null; } - var uri = new Uri(download.Link); + var uri = new Uri(downloadUrl); - using (HttpClient client = new HttpClient()) + using (HttpClient client = new()) { - HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Head, uri); + HttpRequestMessage request = new(HttpMethod.Head, uri); HttpResponseMessage response = await client.SendAsync(request); if (response.Content.Headers.ContentDisposition != null) {