revert changes to DownloadHelper.cs
This commit is contained in:
parent
db1760b36e
commit
beb0299a0b
1 changed files with 44 additions and 34 deletions
|
|
@ -17,6 +17,7 @@ public static class DownloadHelper
|
||||||
var directory = RemoveInvalidPathChars(torrent.RdName);
|
var directory = RemoveInvalidPathChars(torrent.RdName);
|
||||||
|
|
||||||
var uri = new Uri(fileUrl);
|
var uri = new Uri(fileUrl);
|
||||||
|
var torrentPath = Path.Combine(downloadPath, directory);
|
||||||
|
|
||||||
var fileName = download.FileName;
|
var fileName = download.FileName;
|
||||||
|
|
||||||
|
|
@ -29,42 +30,14 @@ public static class DownloadHelper
|
||||||
|
|
||||||
fileName = FileHelper.RemoveInvalidFileNameChars(fileName);
|
fileName = FileHelper.RemoveInvalidFileNameChars(fileName);
|
||||||
|
|
||||||
var torrentPath = downloadPath;
|
var matchingTorrentFiles = torrent.Files.Where(m => m.Path.EndsWith(fileName)).Where(m => !String.IsNullOrWhiteSpace(m.Path)).ToList();
|
||||||
|
|
||||||
if (torrent.Files.Count > 1)
|
if (matchingTorrentFiles.Count > 0)
|
||||||
{
|
{
|
||||||
torrentPath = Path.Combine(downloadPath, directory);
|
var matchingTorrentFile = matchingTorrentFiles[0];
|
||||||
|
|
||||||
var matchingTorrentFiles = torrent.Files.Where(m => m.Path.EndsWith(fileName)).Where(m => !String.IsNullOrWhiteSpace(m.Path)).ToList();
|
var subPath = Path.GetDirectoryName(matchingTorrentFile.Path);
|
||||||
|
|
||||||
if (matchingTorrentFiles.Count > 0)
|
|
||||||
{
|
|
||||||
var matchingTorrentFile = matchingTorrentFiles[0];
|
|
||||||
var subPath = Path.GetDirectoryName(matchingTorrentFile.Path);
|
|
||||||
|
|
||||||
if (!String.IsNullOrWhiteSpace(subPath))
|
|
||||||
{
|
|
||||||
subPath = subPath.Trim('/').Trim('\\');
|
|
||||||
|
|
||||||
torrentPath = Path.Combine(torrentPath, subPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
|
|
||||||
// What we think is a single file torrent may also be a folder with a single file in it.
|
|
||||||
// So make sure we handle that here. If this is not the case, torrentPath will be empty below.
|
|
||||||
if (!String.IsNullOrWhiteSpace(subPath))
|
if (!String.IsNullOrWhiteSpace(subPath))
|
||||||
{
|
{
|
||||||
subPath = subPath.Trim('/').Trim('\\');
|
subPath = subPath.Trim('/').Trim('\\');
|
||||||
|
|
@ -73,7 +46,7 @@ public static class DownloadHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!String.IsNullOrWhiteSpace(torrentPath) && !Directory.Exists(torrentPath))
|
if (!Directory.Exists(torrentPath))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(torrentPath);
|
Directory.CreateDirectory(torrentPath);
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +58,44 @@ public static class DownloadHelper
|
||||||
|
|
||||||
public static String? GetDownloadPath(Torrent torrent, Download download)
|
public static String? GetDownloadPath(Torrent torrent, Download download)
|
||||||
{
|
{
|
||||||
return GetDownloadPath("", torrent, download);
|
var fileUrl = download.Link;
|
||||||
|
|
||||||
|
if (String.IsNullOrWhiteSpace(fileUrl) || torrent.RdName == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var uri = new Uri(fileUrl);
|
||||||
|
var torrentPath = RemoveInvalidPathChars(torrent.RdName);
|
||||||
|
|
||||||
|
var fileName = download.FileName;
|
||||||
|
|
||||||
|
if (String.IsNullOrWhiteSpace(fileName))
|
||||||
|
{
|
||||||
|
fileName = uri.Segments.Last();
|
||||||
|
|
||||||
|
fileName = HttpUtility.UrlDecode(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
var matchingTorrentFiles = torrent.Files.Where(m => m.Path.EndsWith(fileName)).Where(m => !String.IsNullOrWhiteSpace(m.Path)).ToList();
|
||||||
|
|
||||||
|
if (matchingTorrentFiles.Count > 0)
|
||||||
|
{
|
||||||
|
var matchingTorrentFile = matchingTorrentFiles[0];
|
||||||
|
|
||||||
|
var subPath = Path.GetDirectoryName(matchingTorrentFile.Path);
|
||||||
|
|
||||||
|
if (!String.IsNullOrWhiteSpace(subPath))
|
||||||
|
{
|
||||||
|
subPath = subPath.Trim('/').Trim('\\');
|
||||||
|
|
||||||
|
torrentPath = Path.Combine(torrentPath, subPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var filePath = Path.Combine(torrentPath, fileName);
|
||||||
|
|
||||||
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String RemoveInvalidPathChars(String path)
|
private static String RemoveInvalidPathChars(String path)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue