[TB] Refactor GetFileName in Torrent Clients
This commit is contained in:
parent
a1599ee716
commit
350185b702
5 changed files with 16 additions and 16 deletions
|
|
@ -263,14 +263,14 @@ public class AllDebridTorrentClient(ILogger<AllDebridTorrentClient> logger, IHtt
|
|||
|
||||
return links.Select(m => m.LinkUrl.ToString()).ToList();
|
||||
}
|
||||
public Task<String?> GetFileName(Data.Models.Data.Download download)
|
||||
public Task<String?> GetFileName(String downloadUrl)
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(download.Link))
|
||||
if (String.IsNullOrWhiteSpace(downloadUrl))
|
||||
{
|
||||
return Task.FromResult<String?>(null);
|
||||
}
|
||||
|
||||
var uri = new Uri(download.Link);
|
||||
var uri = new Uri(downloadUrl);
|
||||
|
||||
return Task.FromResult<String?>(HttpUtility.UrlDecode(uri.Segments.Last()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,5 +15,5 @@ public interface ITorrentClient
|
|||
Task<String> Unrestrict(String link);
|
||||
Task<Torrent> UpdateData(Torrent torrent, TorrentClientTorrent? torrentClientTorrent);
|
||||
Task<IList<String>?> GetDownloadLinks(Torrent torrent);
|
||||
Task<String?> GetFileName(Download download);
|
||||
Task<String?> GetFileName(String downloadUrl);
|
||||
}
|
||||
|
|
@ -242,14 +242,14 @@ public class PremiumizeTorrentClient(ILogger<PremiumizeTorrentClient> logger, IH
|
|||
return downloadLinks;
|
||||
}
|
||||
|
||||
public Task<String?> GetFileName(Data.Models.Data.Download download)
|
||||
public Task<String?> GetFileName(String downloadUrl)
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(download.Link))
|
||||
if (String.IsNullOrWhiteSpace(downloadUrl))
|
||||
{
|
||||
return Task.FromResult<String?>(null);
|
||||
}
|
||||
|
||||
var uri = new Uri(download.Link);
|
||||
var uri = new Uri(downloadUrl);
|
||||
|
||||
return Task.FromResult<String?>(HttpUtility.UrlDecode(uri.Segments.Last()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -396,14 +396,14 @@ public class RealDebridTorrentClient(ILogger<RealDebridTorrentClient> logger, IH
|
|||
return null;
|
||||
}
|
||||
|
||||
public Task<String?> GetFileName(Data.Models.Data.Download download)
|
||||
public Task<String?> GetFileName(String downloadUrl)
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(download.Link))
|
||||
if (String.IsNullOrWhiteSpace(downloadUrl))
|
||||
{
|
||||
return Task.FromResult<String?>(null);
|
||||
}
|
||||
|
||||
var uri = new Uri(download.Link);
|
||||
var uri = new Uri(downloadUrl);
|
||||
|
||||
return Task.FromResult<String?>(HttpUtility.UrlDecode(uri.Segments.Last()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> 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<TorBoxTorrentClient> logger, IHttpClien
|
|||
return files;
|
||||
}
|
||||
|
||||
public async Task<String?> GetFileName(Data.Models.Data.Download download)
|
||||
public async Task<String?> 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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue