Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make single and multi-file AD torrents known to SymlinkDownloader #1

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions server/RdtClient.Service/Helpers/DownloadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ public static class DownloadHelper

fileName = FileHelper.RemoveInvalidFileNameChars(fileName);

var torrentPath = downloadPath;
var torrentPath = Path.Combine(downloadPath, directory);

if (torrent.Files.Count > 1)
{
torrentPath = Path.Combine(downloadPath, directory);

var matchingTorrentFiles = torrent.Files.Where(m => m.Path.EndsWith(fileName)).Where(m => !String.IsNullOrWhiteSpace(m.Path)).ToList();

if (matchingTorrentFiles.Count > 0)
Expand All @@ -52,14 +50,6 @@ public static class DownloadHelper
}
else if (torrent.Files.Count == 1)
{
// Debrid servers such as RealDebrid store single file torrents in a subfolder, but AllDebrid doesn't.
// We should replicate this behavior so that both folder structures are equal.
// See issue: https://github.com/rogerfar/rdt-client/issues/648
if (torrent.ClientKind != Torrent.TorrentClientKind.AllDebrid)
{
torrentPath = Path.Combine(downloadPath, directory);
}

var torrentFile = torrent.Files[0];
var subPath = Path.GetDirectoryName(torrentFile.Path);

Expand All @@ -71,6 +61,14 @@ public static class DownloadHelper

torrentPath = Path.Combine(torrentPath, subPath);
}

// Debrid servers such as RealDebrid store single file torrents in a subfolder, but AllDebrid doesn't.
// We should replicate this behavior so that both folder structures are equal.
// See issue: https://github.com/rogerfar/rdt-client/issues/648
if (torrent.ClientKind == Torrent.TorrentClientKind.AllDebrid)
{
return torrentFile.Path;
}
}

if (!String.IsNullOrWhiteSpace(torrentPath) && !Directory.Exists(torrentPath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ public async Task<String> Download()

potentialFilePaths.Add(fileName);
potentialFilePaths.Add(fileNameWithoutExtension);

var pathDirectoryName = Path.GetDirectoryName(path);
if (pathDirectoryName != null)
{
potentialFilePaths.Add(pathDirectoryName);
}

// add an empty path so we can check for the new file in the base directory
potentialFilePaths.Add("");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static TorrentClientTorrent Map(Magnet torrent)
Added = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(torrent.UploadDate),
Files = torrent.Links.Select((m, i) => new TorrentClientFile
{
Path = GetFiles(m.Files),
Path = torrent.Links.Count == 1 ? torrent.Filename : GetFiles(m.Files),
Bytes = m.Size,
Id = i,
Selected = true,
Expand Down