mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
nebulance-api: improve searching by release names
This commit is contained in:
@@ -5,7 +5,6 @@ using System.Globalization;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jackett.Common.Extensions;
|
using Jackett.Common.Extensions;
|
||||||
using Jackett.Common.Models;
|
using Jackett.Common.Models;
|
||||||
@@ -46,7 +45,6 @@ namespace Jackett.Common.Indexers.Definitions
|
|||||||
public override TorznabCapabilities TorznabCaps => SetCapabilities();
|
public override TorznabCapabilities TorznabCaps => SetCapabilities();
|
||||||
|
|
||||||
// Docs at https://nebulance.io/articles.php?topic=api_key
|
// Docs at https://nebulance.io/articles.php?topic=api_key
|
||||||
protected virtual string ApiUrl => SiteLink + "api.php";
|
|
||||||
protected virtual int KeyLength => 32;
|
protected virtual int KeyLength => 32;
|
||||||
|
|
||||||
// TODO: remove ConfigurationDataAPIKey class and use ConfigurationDataPasskey instead
|
// TODO: remove ConfigurationDataAPIKey class and use ConfigurationDataPasskey instead
|
||||||
@@ -97,7 +95,7 @@ namespace Jackett.Common.Indexers.Definitions
|
|||||||
|
|
||||||
public override IIndexerRequestGenerator GetRequestGenerator()
|
public override IIndexerRequestGenerator GetRequestGenerator()
|
||||||
{
|
{
|
||||||
return new NebulanceAPIRequestGenerator(TorznabCaps, configData, ApiUrl);
|
return new NebulanceAPIRequestGenerator(TorznabCaps, configData, SiteLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IParseIndexerResponse GetParser()
|
public override IParseIndexerResponse GetParser()
|
||||||
@@ -119,6 +117,7 @@ namespace Jackett.Common.Indexers.Definitions
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var results = await PerformQuery(new TorznabQuery());
|
var results = await PerformQuery(new TorznabQuery());
|
||||||
|
|
||||||
if (!results.Any())
|
if (!results.Any())
|
||||||
{
|
{
|
||||||
throw new Exception("Testing returned no results!");
|
throw new Exception("Testing returned no results!");
|
||||||
@@ -140,15 +139,13 @@ namespace Jackett.Common.Indexers.Definitions
|
|||||||
{
|
{
|
||||||
private readonly TorznabCapabilities _torznabCaps;
|
private readonly TorznabCapabilities _torznabCaps;
|
||||||
private readonly ConfigurationDataAPIKey _configData;
|
private readonly ConfigurationDataAPIKey _configData;
|
||||||
private readonly string _apiUrl;
|
private readonly string _siteLink;
|
||||||
|
|
||||||
private readonly string[] _moveToTags = { "720p", "1080p", "2160p", "4k" };
|
public NebulanceAPIRequestGenerator(TorznabCapabilities torznabCaps, ConfigurationDataAPIKey configData, string siteLink)
|
||||||
|
|
||||||
public NebulanceAPIRequestGenerator(TorznabCapabilities torznabCaps, ConfigurationDataAPIKey configData, string apiUrl)
|
|
||||||
{
|
{
|
||||||
_torznabCaps = torznabCaps;
|
_torznabCaps = torznabCaps;
|
||||||
_configData = configData;
|
_configData = configData;
|
||||||
_apiUrl = apiUrl;
|
_siteLink = siteLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndexerPageableRequestChain GetSearchRequests(TorznabQuery query)
|
public IndexerPageableRequestChain GetSearchRequests(TorznabQuery query)
|
||||||
@@ -176,22 +173,12 @@ namespace Jackett.Common.Indexers.Definitions
|
|||||||
|
|
||||||
if (searchQuery.IsNotNullOrWhiteSpace())
|
if (searchQuery.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
var searchTerms = Regex.Split(searchQuery, "\\s+").ToList();
|
queryParams.Release = searchQuery;
|
||||||
var movingToTags = searchTerms.Intersect(_moveToTags, StringComparer.OrdinalIgnoreCase).ToList();
|
|
||||||
movingToTags.ForEach(tag => searchTerms.RemoveAll(searchTerm => searchTerm.Equals(tag, StringComparison.OrdinalIgnoreCase)));
|
|
||||||
|
|
||||||
if (!searchTerms.Any())
|
|
||||||
{
|
|
||||||
// NBL API does not support tag calls without name, series, id, imdb, tvmaze, or time keys.
|
|
||||||
return new IndexerPageableRequestChain();
|
|
||||||
}
|
|
||||||
|
|
||||||
queryParams.Tags = movingToTags.ToArray();
|
|
||||||
queryParams.Name = searchTerms.Join(" ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DateTime.TryParseExact($"{query.Season} {query.Episode}", "yyyy MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var showDate))
|
if (DateTime.TryParseExact($"{query.Season} {query.Episode}", "yyyy MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var showDate))
|
||||||
{
|
{
|
||||||
|
queryParams.Name = searchQuery;
|
||||||
queryParams.Release = showDate.ToString("yyyy.MM.dd", CultureInfo.InvariantCulture);
|
queryParams.Release = showDate.ToString("yyyy.MM.dd", CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -216,7 +203,7 @@ namespace Jackett.Common.Indexers.Definitions
|
|||||||
{
|
{
|
||||||
var webRequest = new WebRequest
|
var webRequest = new WebRequest
|
||||||
{
|
{
|
||||||
Url = _apiUrl,
|
Url = _siteLink + "api.php",
|
||||||
Type = RequestType.POST,
|
Type = RequestType.POST,
|
||||||
Headers = new Dictionary<string, string>
|
Headers = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user