|
|
|
@ -31,6 +31,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
|
|
|
|
private string LoginUrl => Settings.BaseUrl + "api/login";
|
|
|
|
|
public override Encoding Encoding => Encoding.UTF8;
|
|
|
|
|
public override DownloadProtocol Protocol => DownloadProtocol.Torrent;
|
|
|
|
|
public override int PageSize => 100;
|
|
|
|
|
public override IndexerCapabilities Capabilities => SetCapabilities();
|
|
|
|
|
protected virtual int MinimumSeedTime => 172800; // 48 hours
|
|
|
|
|
private IIndexerRepository _indexerRepository;
|
|
|
|
@ -43,7 +44,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
|
|
|
|
|
|
|
|
|
public override IIndexerRequestGenerator GetRequestGenerator()
|
|
|
|
|
{
|
|
|
|
|
return new SpeedAppRequestGenerator(Capabilities, Settings);
|
|
|
|
|
return new SpeedAppRequestGenerator(Capabilities, Settings, PageSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IParseIndexerResponse GetParser()
|
|
|
|
@ -168,26 +169,25 @@ namespace NzbDrone.Core.Indexers.Definitions
|
|
|
|
|
|
|
|
|
|
protected virtual IndexerCapabilities SetCapabilities()
|
|
|
|
|
{
|
|
|
|
|
var caps = new IndexerCapabilities();
|
|
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
|
return new IndexerCapabilities();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class SpeedAppRequestGenerator : IIndexerRequestGenerator
|
|
|
|
|
{
|
|
|
|
|
private readonly IndexerCapabilities _capabilities;
|
|
|
|
|
private readonly SpeedAppSettings _settings;
|
|
|
|
|
private readonly int _pageSize;
|
|
|
|
|
|
|
|
|
|
public Func<IDictionary<string, string>> GetCookies { get; set; }
|
|
|
|
|
|
|
|
|
|
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
|
|
|
|
|
|
|
|
|
|
private IndexerCapabilities Capabilities { get; }
|
|
|
|
|
|
|
|
|
|
private SpeedAppSettings Settings { get; }
|
|
|
|
|
|
|
|
|
|
public SpeedAppRequestGenerator(IndexerCapabilities capabilities, SpeedAppSettings settings)
|
|
|
|
|
public SpeedAppRequestGenerator(IndexerCapabilities capabilities, SpeedAppSettings settings, int pageSize)
|
|
|
|
|
{
|
|
|
|
|
Capabilities = capabilities;
|
|
|
|
|
Settings = settings;
|
|
|
|
|
_capabilities = capabilities;
|
|
|
|
|
_settings = settings;
|
|
|
|
|
_pageSize = pageSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchCriteria)
|
|
|
|
@ -219,54 +219,62 @@ namespace NzbDrone.Core.Indexers.Definitions
|
|
|
|
|
{
|
|
|
|
|
var pageableRequests = new IndexerPageableRequestChain();
|
|
|
|
|
|
|
|
|
|
pageableRequests.Add(GetPagedRequests($"{searchCriteria.SanitizedSearchTerm}", searchCriteria.Categories, imdbId, season, episode));
|
|
|
|
|
pageableRequests.Add(GetPagedRequests($"{searchCriteria.SanitizedSearchTerm}", searchCriteria.Categories, searchCriteria.Limit ?? _pageSize, searchCriteria.Offset ?? 0, imdbId, season, episode));
|
|
|
|
|
|
|
|
|
|
return pageableRequests;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<IndexerRequest> GetPagedRequests(string term, int[] categories, string imdbId = null, int? season = null, string episode = null)
|
|
|
|
|
private IEnumerable<IndexerRequest> GetPagedRequests(string term, int[] categories, int limit, int offset, string imdbId = null, int? season = null, string episode = null)
|
|
|
|
|
{
|
|
|
|
|
var qc = new NameValueCollection()
|
|
|
|
|
limit = Math.Min(_pageSize, limit);
|
|
|
|
|
offset = Math.Max(0, offset);
|
|
|
|
|
|
|
|
|
|
var parameters = new NameValueCollection
|
|
|
|
|
{
|
|
|
|
|
{ "itemsPerPage", "100" },
|
|
|
|
|
{ "itemsPerPage", limit.ToString() },
|
|
|
|
|
{ "sort", "torrent.createdAt" },
|
|
|
|
|
{ "direction", "desc" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (limit > 0 && offset > 0)
|
|
|
|
|
{
|
|
|
|
|
var page = (offset / limit) + 1;
|
|
|
|
|
parameters.Set("page", page.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (imdbId.IsNotNullOrWhiteSpace())
|
|
|
|
|
{
|
|
|
|
|
qc.Add("imdbId", imdbId);
|
|
|
|
|
parameters.Set("imdbId", imdbId);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qc.Add("search", term);
|
|
|
|
|
parameters.Set("search", term);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (season != null)
|
|
|
|
|
{
|
|
|
|
|
qc.Add("season", season.Value.ToString());
|
|
|
|
|
parameters.Set("season", season.Value.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (episode != null)
|
|
|
|
|
{
|
|
|
|
|
qc.Add("episode", episode);
|
|
|
|
|
parameters.Set("episode", episode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var cats = Capabilities.Categories.MapTorznabCapsToTrackers(categories);
|
|
|
|
|
|
|
|
|
|
var cats = _capabilities.Categories.MapTorznabCapsToTrackers(categories);
|
|
|
|
|
if (cats.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var cat in cats)
|
|
|
|
|
{
|
|
|
|
|
qc.Add("categories[]", cat);
|
|
|
|
|
parameters.Add("categories[]", cat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var searchUrl = Settings.BaseUrl + "api/torrent?" + qc.GetQueryString(duplicateKeysIfMulti: true);
|
|
|
|
|
var searchUrl = _settings.BaseUrl + "api/torrent?" + parameters.GetQueryString(duplicateKeysIfMulti: true);
|
|
|
|
|
|
|
|
|
|
var request = new IndexerRequest(searchUrl, HttpAccept.Json);
|
|
|
|
|
|
|
|
|
|
request.HttpRequest.Headers.Set("Authorization", $"Bearer {Settings.ApiKey}");
|
|
|
|
|
request.HttpRequest.Headers.Set("Authorization", $"Bearer {_settings.ApiKey}");
|
|
|
|
|
|
|
|
|
|
yield return request;
|
|
|
|
|
}
|
|
|
|
|