Build download requests from indexer implementation

(cherry picked from commit a0b08f6c6f106d92cdb12fbb959dd2605c22fe6a)
This commit is contained in:
Bogdan
2023-04-30 07:09:11 +03:00
parent 1978a726bb
commit 7a7039b1f7
26 changed files with 132 additions and 91 deletions
@@ -41,7 +41,7 @@ namespace NzbDrone.Core.Download
protected abstract string AddFromMagnetLink(RemoteBook remoteBook, string hash, string magnetLink);
protected abstract string AddFromTorrentFile(RemoteBook remoteBook, string hash, string filename, byte[] fileContent);
public override string Download(RemoteBook remoteBook)
public override string Download(RemoteBook remoteBook, IIndexer indexer)
{
var torrentInfo = remoteBook.Release as TorrentInfo;
@@ -68,7 +68,7 @@ namespace NzbDrone.Core.Download
{
try
{
return DownloadFromWebUrl(remoteBook, torrentUrl);
return DownloadFromWebUrl(remoteBook, indexer, torrentUrl);
}
catch (Exception ex)
{
@@ -114,20 +114,20 @@ namespace NzbDrone.Core.Download
if (torrentUrl.IsNotNullOrWhiteSpace())
{
return DownloadFromWebUrl(remoteBook, torrentUrl);
return DownloadFromWebUrl(remoteBook, indexer, torrentUrl);
}
}
return null;
}
private string DownloadFromWebUrl(RemoteBook remoteBook, string torrentUrl)
private string DownloadFromWebUrl(RemoteBook remoteBook, IIndexer indexer, string torrentUrl)
{
byte[] torrentFile = null;
try
{
var request = new HttpRequest(torrentUrl);
var request = indexer.GetDownloadRequest(torrentUrl);
request.RateLimitKey = remoteBook?.Release?.IndexerId.ToString();
request.Headers.Accept = "application/x-bittorrent";
request.AllowAutoRedirect = false;
@@ -149,7 +149,9 @@ namespace NzbDrone.Core.Download
return DownloadFromMagnetUrl(remoteBook, locationHeader);
}
return DownloadFromWebUrl(remoteBook, locationHeader);
request.Url += new HttpUri(locationHeader);
return DownloadFromWebUrl(remoteBook, indexer, request.Url.ToString());
}
throw new WebException("Remote website tried to redirect without providing a location.");