diff --git a/server/RdtClient.Data/Data/DownloadData.cs b/server/RdtClient.Data/Data/DownloadData.cs index 9d141f9..3b9e303 100644 --- a/server/RdtClient.Data/Data/DownloadData.cs +++ b/server/RdtClient.Data/Data/DownloadData.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using RdtClient.Data.Models.Data; using Download = RdtClient.Data.Models.Data.Download; namespace RdtClient.Data.Data; @@ -29,13 +30,14 @@ public class DownloadData(DataContext dataContext) .FirstOrDefaultAsync(m => m.TorrentId == torrentId && m.Path == path); } - public async Task Add(Guid torrentId, String path) + public async Task Add(Guid torrentId, DownloadInfo downloadInfo) { var download = new Download { DownloadId = Guid.NewGuid(), TorrentId = torrentId, - Path = path, + FileName = downloadInfo.FileName, + Path = downloadInfo.RestrictedLink, Added = DateTimeOffset.UtcNow, DownloadQueued = DateTimeOffset.UtcNow, RetryCount = 0 diff --git a/server/RdtClient.Data/Models/Data/Download.cs b/server/RdtClient.Data/Models/Data/Download.cs index d078356..6720415 100644 --- a/server/RdtClient.Data/Models/Data/Download.cs +++ b/server/RdtClient.Data/Models/Data/Download.cs @@ -26,7 +26,7 @@ public class Download public DateTimeOffset? Completed { get; set; } public Int32 RetryCount { get; set; } - + public String? Error { get; set; } public String? RemoteId { get; set; } @@ -41,4 +41,20 @@ public class Download [NotMapped] public Int64 Speed { get; set; } +} + +/// +/// Used to create s +/// +public class DownloadInfo +{ + /// + /// The name of the file. Should not include directory. + /// If the filename is not known, set tn null and `GetFileName` will be called with the unrestricted link. + /// + public required String? FileName; + /// + /// The restricted link to download this download. If the debrid serice in question does not have restricted links, use either a fake or the unrestricted link + /// + public required String RestrictedLink; } \ No newline at end of file diff --git a/server/RdtClient.Service/Services/Downloads.cs b/server/RdtClient.Service/Services/Downloads.cs index 925c8e0..76677c9 100644 --- a/server/RdtClient.Service/Services/Downloads.cs +++ b/server/RdtClient.Service/Services/Downloads.cs @@ -1,4 +1,5 @@ using RdtClient.Data.Data; +using RdtClient.Data.Models.Data; using Download = RdtClient.Data.Models.Data.Download; namespace RdtClient.Service.Services; @@ -20,9 +21,9 @@ public class Downloads(DownloadData downloadData) : IDownloads return await downloadData.Get(torrentId, path); } - public async Task Add(Guid torrentId, String path) + public async Task Add(Guid torrentId, DownloadInfo downloadInfo) { - return await downloadData.Add(torrentId, path); + return await downloadData.Add(torrentId, downloadInfo); } public async Task UpdateUnrestrictedLink(Guid downloadId, String unrestrictedLink) diff --git a/server/RdtClient.Service/Services/IDownloads.cs b/server/RdtClient.Service/Services/IDownloads.cs index d0550b9..b79f59a 100644 --- a/server/RdtClient.Service/Services/IDownloads.cs +++ b/server/RdtClient.Service/Services/IDownloads.cs @@ -7,7 +7,7 @@ public interface IDownloads Task> GetForTorrent(Guid torrentId); Task GetById(Guid downloadId); Task Get(Guid torrentId, String path); - Task Add(Guid torrentId, String path); + Task Add(Guid torrentId, DownloadInfo downloadInfo); Task UpdateUnrestrictedLink(Guid downloadId, String unrestrictedLink); Task UpdateFileName(Guid downloadId, String fileName); Task UpdateDownloadStarted(Guid downloadId, DateTimeOffset? dateTime); diff --git a/server/RdtClient.Service/Services/TorrentClients/ITorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/ITorrentClient.cs index 38121ae..e0ca2c3 100644 --- a/server/RdtClient.Service/Services/TorrentClients/ITorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/ITorrentClient.cs @@ -14,6 +14,12 @@ public interface ITorrentClient Task Delete(String torrentId); Task Unrestrict(String link); Task UpdateData(Torrent torrent, TorrentClientTorrent? torrentClientTorrent); - Task?> GetDownloadLinks(Torrent torrent); - Task GetFileName(String downloadUrl); + Task?> GetDownloadInfos(Torrent torrent); + /// + /// To be called only when . is not set by + /// + /// + /// The download to get the filename of + /// The filename of the download + Task GetFileName(Download download); } \ No newline at end of file diff --git a/server/RdtClient.Service/Services/TorrentRunner.cs b/server/RdtClient.Service/Services/TorrentRunner.cs index 6151100..102b9b6 100644 --- a/server/RdtClient.Service/Services/TorrentRunner.cs +++ b/server/RdtClient.Service/Services/TorrentRunner.cs @@ -363,8 +363,11 @@ public class TorrentRunner(ILogger logger, Torrents torrents, Dow var downloadLink = await torrents.UnrestrictLink(download.DownloadId); download.Link = downloadLink; - var fileName = await torrents.RetrieveFileName(download.DownloadId); - download.FileName = fileName; + if (download.FileName == null) + { + var fileName = await torrents.RetrieveFileName(download.DownloadId); + download.FileName = fileName; + } } } catch (Exception ex) diff --git a/server/RdtClient.Service/Services/Torrents.cs b/server/RdtClient.Service/Services/Torrents.cs index a88087a..9fe1cb6 100644 --- a/server/RdtClient.Service/Services/Torrents.cs +++ b/server/RdtClient.Service/Services/Torrents.cs @@ -235,14 +235,14 @@ public class Torrents( return; } - var downloadLinks = await TorrentClient.GetDownloadLinks(torrent); + var downloadInfos = await TorrentClient.GetDownloadInfos(torrent); - if (downloadLinks == null) + if (downloadInfos == null) { return; } - if (downloadLinks.Count == 0) + if (downloadInfos.Count == 0) { logger.LogInformation("All files excluded by filters (IncludeRegex: {includeRegex}, ExcludeRegex: {excludeRegex}, DownloadMinSize: {downloadMinSize} {torrentInfo}", torrent.IncludeRegex, @@ -256,14 +256,14 @@ public class Torrents( return; } - foreach (var downloadLink in downloadLinks) + foreach (var downloadInfo in downloadInfos) { // Make sure downloads don't get added multiple times - var downloadExists = await downloads.Get(torrent.TorrentId, downloadLink); + var downloadExists = await downloads.Get(torrent.TorrentId, downloadInfo.RestrictedLink); - if (downloadExists == null && !String.IsNullOrWhiteSpace(downloadLink)) + if (downloadExists == null && !String.IsNullOrWhiteSpace(downloadInfo.RestrictedLink)) { - await downloads.Add(torrent.TorrentId, downloadLink); + await downloads.Add(torrent.TorrentId, downloadInfo); } } } @@ -396,7 +396,7 @@ public class Torrents( Log($"Retrieving filename for", download, download.Torrent); - var fileName = await TorrentClient.GetFileName(download.Link!); + var fileName = await TorrentClient.GetFileName(download!); await downloads.UpdateFileName(downloadId, fileName);