mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
Fixed: Improve elapsed time collecting for grabs
This commit is contained in:
@@ -39,9 +39,9 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
|
|||||||
|
|
||||||
_logger.Debug("Downloading NZB from: {0} to: {1}", url, nzbFile);
|
_logger.Debug("Downloading NZB from: {0} to: {1}", url, nzbFile);
|
||||||
|
|
||||||
var nzbData = await indexer.Download(url);
|
var downloadResponse = await indexer.Download(url);
|
||||||
|
|
||||||
File.WriteAllBytes(nzbFile, nzbData);
|
await File.WriteAllBytesAsync(nzbFile, downloadResponse.Data);
|
||||||
|
|
||||||
_logger.Debug("NZB Download succeeded, saved to: {0}", nzbFile);
|
_logger.Debug("NZB Download succeeded, saved to: {0}", nzbFile);
|
||||||
|
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Http;
|
using NzbDrone.Common.Http;
|
||||||
@@ -74,9 +73,6 @@ namespace NzbDrone.Core.Download
|
|||||||
GrabTrigger = source == "Prowlarr" ? GrabTrigger.Manual : GrabTrigger.Api
|
GrabTrigger = source == "Prowlarr" ? GrabTrigger.Manual : GrabTrigger.Api
|
||||||
};
|
};
|
||||||
|
|
||||||
var sw = new Stopwatch();
|
|
||||||
sw.Start();
|
|
||||||
|
|
||||||
string downloadClientId;
|
string downloadClientId;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -115,11 +111,6 @@ namespace NzbDrone.Core.Download
|
|||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
sw.Stop();
|
|
||||||
grabEvent.ElapsedTime = sw.ElapsedMilliseconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.ProgressInfo("Report sent to {0}. {1}", downloadClient.Definition.Name, downloadTitle);
|
_logger.ProgressInfo("Report sent to {0}. {1}", downloadClient.Definition.Name, downloadTitle);
|
||||||
|
|
||||||
@@ -153,16 +144,15 @@ namespace NzbDrone.Core.Download
|
|||||||
GrabTrigger = source == "Prowlarr" ? GrabTrigger.Manual : GrabTrigger.Api
|
GrabTrigger = source == "Prowlarr" ? GrabTrigger.Manual : GrabTrigger.Api
|
||||||
};
|
};
|
||||||
|
|
||||||
var sw = new Stopwatch();
|
|
||||||
sw.Start();
|
|
||||||
|
|
||||||
byte[] downloadedBytes;
|
byte[] downloadedBytes;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
downloadedBytes = await indexer.Download(url);
|
var downloadResponse = await indexer.Download(url);
|
||||||
|
downloadedBytes = downloadResponse.Data;
|
||||||
_indexerStatusService.RecordSuccess(indexerId);
|
_indexerStatusService.RecordSuccess(indexerId);
|
||||||
grabEvent.Successful = true;
|
grabEvent.Successful = true;
|
||||||
|
grabEvent.ElapsedTime = downloadResponse.ElapsedTime;
|
||||||
}
|
}
|
||||||
catch (ReleaseUnavailableException)
|
catch (ReleaseUnavailableException)
|
||||||
{
|
{
|
||||||
@@ -184,11 +174,6 @@ namespace NzbDrone.Core.Download
|
|||||||
_eventAggregator.PublishEvent(grabEvent);
|
_eventAggregator.PublishEvent(grabEvent);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
sw.Stop();
|
|
||||||
grabEvent.ElapsedTime = sw.ElapsedMilliseconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Trace("Downloaded {0} bytes from {1}", downloadedBytes.Length, link);
|
_logger.Trace("Downloaded {0} bytes from {1}", downloadedBytes.Length, link);
|
||||||
_eventAggregator.PublishEvent(grabEvent);
|
_eventAggregator.PublishEvent(grabEvent);
|
||||||
|
@@ -127,9 +127,8 @@ namespace NzbDrone.Core.Download
|
|||||||
|
|
||||||
private async Task<string> DownloadFromWebUrl(TorrentInfo release, IIndexer indexer, string torrentUrl)
|
private async Task<string> DownloadFromWebUrl(TorrentInfo release, IIndexer indexer, string torrentUrl)
|
||||||
{
|
{
|
||||||
byte[] torrentFile = null;
|
var downloadResponse = await indexer.Download(new Uri(torrentUrl));
|
||||||
|
var torrentFile = downloadResponse.Data;
|
||||||
torrentFile = await indexer.Download(new Uri(torrentUrl));
|
|
||||||
|
|
||||||
// handle magnet URLs
|
// handle magnet URLs
|
||||||
if (torrentFile.Length >= 7
|
if (torrentFile.Length >= 7
|
||||||
|
@@ -41,12 +41,10 @@ namespace NzbDrone.Core.Download
|
|||||||
|
|
||||||
var filename = StringUtil.CleanFileName(release.Title) + ".nzb";
|
var filename = StringUtil.CleanFileName(release.Title) + ".nzb";
|
||||||
|
|
||||||
byte[] nzbData;
|
var downloadResponse = await indexer.Download(url);
|
||||||
|
|
||||||
nzbData = await indexer.Download(url);
|
|
||||||
|
|
||||||
_logger.Info("Adding report [{0}] to the queue.", release.Title);
|
_logger.Info("Adding report [{0}] to the queue.", release.Title);
|
||||||
return AddFromNzbFile(release, filename, nzbData);
|
return AddFromNzbFile(release, filename, downloadResponse.Data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -205,7 +205,11 @@ namespace NzbDrone.Core.History
|
|||||||
history.Data.Add("GrabMethod", message.Redirect ? "Redirect" : "Proxy");
|
history.Data.Add("GrabMethod", message.Redirect ? "Redirect" : "Proxy");
|
||||||
history.Data.Add("GrabTitle", message.Title);
|
history.Data.Add("GrabTitle", message.Title);
|
||||||
history.Data.Add("Url", message.Url ?? string.Empty);
|
history.Data.Add("Url", message.Url ?? string.Empty);
|
||||||
history.Data.Add("ElapsedTime", message.ElapsedTime.ToString());
|
|
||||||
|
if (message.ElapsedTime > 0)
|
||||||
|
{
|
||||||
|
history.Data.Add("ElapsedTime", message.ElapsedTime.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
if (message.Release.InfoUrl.IsNotNullOrWhiteSpace())
|
if (message.Release.InfoUrl.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
|
@@ -46,7 +46,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
|||||||
return new BakaBTParser(Settings, Capabilities.Categories);
|
return new BakaBTParser(Settings, Capabilities.Categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<byte[]> Download(Uri link)
|
public override async Task<IndexerDownloadResponse> Download(Uri link)
|
||||||
{
|
{
|
||||||
var request = new HttpRequestBuilder(link.ToString())
|
var request = new HttpRequestBuilder(link.ToString())
|
||||||
.SetCookies(GetCookies() ?? new Dictionary<string, string>())
|
.SetCookies(GetCookies() ?? new Dictionary<string, string>())
|
||||||
|
@@ -82,9 +82,10 @@ public abstract class GazelleBase<TSettings> : TorrentIndexerBase<TSettings>
|
|||||||
|
|
||||||
protected virtual bool CheckForLoginError(HttpResponse response) => true;
|
protected virtual bool CheckForLoginError(HttpResponse response) => true;
|
||||||
|
|
||||||
public override async Task<byte[]> Download(Uri link)
|
public override async Task<IndexerDownloadResponse> Download(Uri link)
|
||||||
{
|
{
|
||||||
var response = await base.Download(link);
|
var downloadResponse = await base.Download(link);
|
||||||
|
var response = downloadResponse.Data;
|
||||||
|
|
||||||
if (response.Length >= 1
|
if (response.Length >= 1
|
||||||
&& response[0] != 'd' // simple test for torrent vs HTML content
|
&& response[0] != 'd' // simple test for torrent vs HTML content
|
||||||
@@ -99,11 +100,11 @@ public abstract class GazelleBase<TSettings> : TorrentIndexerBase<TSettings>
|
|||||||
// download again without usetoken=1
|
// download again without usetoken=1
|
||||||
var requestLinkNew = link.ToString().Replace("&usetoken=1", "");
|
var requestLinkNew = link.ToString().Replace("&usetoken=1", "");
|
||||||
|
|
||||||
response = await base.Download(new Uri(requestLinkNew));
|
downloadResponse = await base.Download(new Uri(requestLinkNew));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return downloadResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IDictionary<string, string> GetCookies()
|
protected override IDictionary<string, string> GetCookies()
|
||||||
|
@@ -50,28 +50,33 @@ namespace NzbDrone.Core.Indexers.Headphones
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<byte[]> Download(Uri link)
|
public override async Task<IndexerDownloadResponse> Download(Uri link)
|
||||||
{
|
{
|
||||||
var requestBuilder = new HttpRequestBuilder(link.AbsoluteUri);
|
var requestBuilder = new HttpRequestBuilder(link.AbsoluteUri);
|
||||||
|
|
||||||
var downloadBytes = Array.Empty<byte>();
|
|
||||||
|
|
||||||
var request = requestBuilder.Build();
|
var request = requestBuilder.Build();
|
||||||
|
|
||||||
request.Credentials = new BasicNetworkCredential(Settings.Username, Settings.Password);
|
request.Credentials = new BasicNetworkCredential(Settings.Username, Settings.Password);
|
||||||
|
|
||||||
|
byte[] downloadBytes;
|
||||||
|
long elapsedTime;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var response = await _httpClient.ExecuteProxiedAsync(request, Definition);
|
var response = await _httpClient.ExecuteProxiedAsync(request, Definition);
|
||||||
downloadBytes = response.ResponseData;
|
downloadBytes = response.ResponseData;
|
||||||
|
elapsedTime = response.ElapsedTime;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
_indexerStatusService.RecordFailure(Definition.Id);
|
_indexerStatusService.RecordFailure(Definition.Id);
|
||||||
_logger.Error("Download failed");
|
_logger.Error("Download failed");
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
return downloadBytes;
|
ValidateDownloadData(downloadBytes);
|
||||||
|
|
||||||
|
return new IndexerDownloadResponse(downloadBytes, elapsedTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IndexerCapabilities SetCapabilities()
|
private IndexerCapabilities SetCapabilities()
|
||||||
|
@@ -59,7 +59,7 @@ public class MTeamTp : TorrentIndexerBase<MTeamTpSettings>
|
|||||||
return new MTeamTpParser(Settings, Capabilities.Categories, BuildApiUrl(Settings));
|
return new MTeamTpParser(Settings, Capabilities.Categories, BuildApiUrl(Settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<byte[]> Download(Uri link)
|
public override async Task<IndexerDownloadResponse> Download(Uri link)
|
||||||
{
|
{
|
||||||
var request = new HttpRequestBuilder(link.ToString())
|
var request = new HttpRequestBuilder(link.ToString())
|
||||||
.SetHeader("x-api-key", Settings.ApiKey)
|
.SetHeader("x-api-key", Settings.ApiKey)
|
||||||
|
@@ -53,7 +53,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
|||||||
return new MyAnonamouseParser(Settings, Capabilities.Categories, _httpClient, _cacheManager, _logger);
|
return new MyAnonamouseParser(Settings, Capabilities.Categories, _httpClient, _cacheManager, _logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<byte[]> Download(Uri link)
|
public override async Task<IndexerDownloadResponse> Download(Uri link)
|
||||||
{
|
{
|
||||||
if (Settings.Freeleech)
|
if (Settings.Freeleech)
|
||||||
{
|
{
|
||||||
|
@@ -89,18 +89,20 @@ namespace NzbDrone.Core.Indexers.Definitions
|
|||||||
return caps;
|
return caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<byte[]> Download(Uri link)
|
public override async Task<IndexerDownloadResponse> Download(Uri link)
|
||||||
{
|
{
|
||||||
var request = new HttpRequestBuilder(link.AbsoluteUri)
|
var request = new HttpRequestBuilder(link.AbsoluteUri)
|
||||||
.SetHeader("Authorization", $"token {Settings.Apikey}")
|
.SetHeader("Authorization", $"token {Settings.Apikey}")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var downloadBytes = Array.Empty<byte>();
|
byte[] downloadBytes;
|
||||||
|
long elapsedTime;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var response = await _httpClient.ExecuteProxiedAsync(request, Definition);
|
var response = await _httpClient.ExecuteProxiedAsync(request, Definition);
|
||||||
downloadBytes = response.ResponseData;
|
downloadBytes = response.ResponseData;
|
||||||
|
elapsedTime = response.ElapsedTime;
|
||||||
|
|
||||||
if (downloadBytes.Length >= 1
|
if (downloadBytes.Length >= 1
|
||||||
&& downloadBytes[0] != 'd' // simple test for torrent vs HTML content
|
&& downloadBytes[0] != 'd' // simple test for torrent vs HTML content
|
||||||
@@ -124,11 +126,12 @@ namespace NzbDrone.Core.Indexers.Definitions
|
|||||||
{
|
{
|
||||||
_indexerStatusService.RecordFailure(Definition.Id);
|
_indexerStatusService.RecordFailure(Definition.Id);
|
||||||
_logger.Error("Download failed");
|
_logger.Error("Download failed");
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
ValidateDownloadData(downloadBytes);
|
ValidateDownloadData(downloadBytes);
|
||||||
|
|
||||||
return downloadBytes;
|
return new IndexerDownloadResponse(downloadBytes, elapsedTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -51,7 +51,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
|||||||
return new RuTrackerParser(Settings, Capabilities.Categories);
|
return new RuTrackerParser(Settings, Capabilities.Categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<byte[]> Download(Uri link)
|
public override async Task<IndexerDownloadResponse> Download(Uri link)
|
||||||
{
|
{
|
||||||
if (Settings.UseMagnetLinks && link.PathAndQuery.Contains("viewtopic.php?t="))
|
if (Settings.UseMagnetLinks && link.PathAndQuery.Contains("viewtopic.php?t="))
|
||||||
{
|
{
|
||||||
|
@@ -82,7 +82,7 @@ public class Uniotaku : TorrentIndexerBase<UniotakuSettings>
|
|||||||
return !httpResponse.GetCookies().ContainsKey("uid") || !httpResponse.GetCookies().ContainsKey("pass");
|
return !httpResponse.GetCookies().ContainsKey("uid") || !httpResponse.GetCookies().ContainsKey("pass");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<byte[]> Download(Uri link)
|
public override async Task<IndexerDownloadResponse> Download(Uri link)
|
||||||
{
|
{
|
||||||
var request = new HttpRequestBuilder(link.ToString())
|
var request = new HttpRequestBuilder(link.ToString())
|
||||||
.SetCookies(GetCookies() ?? new Dictionary<string, string>())
|
.SetCookies(GetCookies() ?? new Dictionary<string, string>())
|
||||||
|
@@ -224,7 +224,7 @@ namespace NzbDrone.Core.Indexers
|
|||||||
return FetchReleases(g => SetCookieFunctions(g).GetSearchRequests(searchCriteria), searchCriteria);
|
return FetchReleases(g => SetCookieFunctions(g).GetSearchRequests(searchCriteria), searchCriteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<byte[]> Download(Uri link)
|
public override async Task<IndexerDownloadResponse> Download(Uri link)
|
||||||
{
|
{
|
||||||
Cookies = GetCookies();
|
Cookies = GetCookies();
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ namespace NzbDrone.Core.Indexers
|
|||||||
if (request.Url.Scheme == "magnet")
|
if (request.Url.Scheme == "magnet")
|
||||||
{
|
{
|
||||||
ValidateMagnet(request.Url.FullUri);
|
ValidateMagnet(request.Url.FullUri);
|
||||||
return Encoding.UTF8.GetBytes(request.Url.FullUri);
|
return new IndexerDownloadResponse(Encoding.UTF8.GetBytes(request.Url.FullUri));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.RateLimit < RateLimit)
|
if (request.RateLimit < RateLimit)
|
||||||
@@ -244,6 +244,7 @@ namespace NzbDrone.Core.Indexers
|
|||||||
request.AllowAutoRedirect = false;
|
request.AllowAutoRedirect = false;
|
||||||
|
|
||||||
byte[] fileData;
|
byte[] fileData;
|
||||||
|
long elapsedTime;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -283,6 +284,7 @@ namespace NzbDrone.Core.Indexers
|
|||||||
}
|
}
|
||||||
|
|
||||||
fileData = response.ResponseData;
|
fileData = response.ResponseData;
|
||||||
|
elapsedTime = response.ElapsedTime;
|
||||||
|
|
||||||
_logger.Debug("Downloaded for release finished ({0} bytes from {1})", fileData.Length, link.AbsoluteUri);
|
_logger.Debug("Downloaded for release finished ({0} bytes from {1})", fileData.Length, link.AbsoluteUri);
|
||||||
}
|
}
|
||||||
@@ -320,7 +322,7 @@ namespace NzbDrone.Core.Indexers
|
|||||||
|
|
||||||
ValidateDownloadData(fileData);
|
ValidateDownloadData(fileData);
|
||||||
|
|
||||||
return fileData;
|
return new IndexerDownloadResponse(fileData, elapsedTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual Task<HttpRequest> GetDownloadRequest(Uri link)
|
protected virtual Task<HttpRequest> GetDownloadRequest(Uri link)
|
||||||
|
@@ -28,7 +28,7 @@ namespace NzbDrone.Core.Indexers
|
|||||||
Task<IndexerPageableQueryResult> Fetch(BookSearchCriteria searchCriteria);
|
Task<IndexerPageableQueryResult> Fetch(BookSearchCriteria searchCriteria);
|
||||||
Task<IndexerPageableQueryResult> Fetch(BasicSearchCriteria searchCriteria);
|
Task<IndexerPageableQueryResult> Fetch(BasicSearchCriteria searchCriteria);
|
||||||
|
|
||||||
Task<byte[]> Download(Uri link);
|
Task<IndexerDownloadResponse> Download(Uri link);
|
||||||
bool IsObsolete();
|
bool IsObsolete();
|
||||||
|
|
||||||
IndexerCapabilities GetCapabilities();
|
IndexerCapabilities GetCapabilities();
|
||||||
|
@@ -97,7 +97,7 @@ namespace NzbDrone.Core.Indexers
|
|||||||
public abstract Task<IndexerPageableQueryResult> Fetch(TvSearchCriteria searchCriteria);
|
public abstract Task<IndexerPageableQueryResult> Fetch(TvSearchCriteria searchCriteria);
|
||||||
public abstract Task<IndexerPageableQueryResult> Fetch(BookSearchCriteria searchCriteria);
|
public abstract Task<IndexerPageableQueryResult> Fetch(BookSearchCriteria searchCriteria);
|
||||||
public abstract Task<IndexerPageableQueryResult> Fetch(BasicSearchCriteria searchCriteria);
|
public abstract Task<IndexerPageableQueryResult> Fetch(BasicSearchCriteria searchCriteria);
|
||||||
public abstract Task<byte[]> Download(Uri link);
|
public abstract Task<IndexerDownloadResponse> Download(Uri link);
|
||||||
|
|
||||||
public abstract IndexerCapabilities GetCapabilities();
|
public abstract IndexerCapabilities GetCapabilities();
|
||||||
|
|
||||||
|
13
src/NzbDrone.Core/Indexers/IndexerDownloadResponse.cs
Normal file
13
src/NzbDrone.Core/Indexers/IndexerDownloadResponse.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace NzbDrone.Core.Indexers;
|
||||||
|
|
||||||
|
public class IndexerDownloadResponse
|
||||||
|
{
|
||||||
|
public byte[] Data { get; private set; }
|
||||||
|
public long ElapsedTime { get; private set; }
|
||||||
|
|
||||||
|
public IndexerDownloadResponse(byte[] data, long elapsedTime = 0)
|
||||||
|
{
|
||||||
|
Data = data;
|
||||||
|
ElapsedTime = elapsedTime;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user