mirror of https://github.com/Jackett/Jackett
apisearch: parse season/episode only if it's at the end of the query (#14007)
This commit is contained in:
parent
d7437f2a0f
commit
eb63aecf8b
|
@ -247,7 +247,6 @@ namespace Jackett.Common.Indexers
|
||||||
|
|
||||||
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
||||||
{
|
{
|
||||||
var searchString = query.GetQueryString();
|
|
||||||
var prevCook = CookieHeader + "";
|
var prevCook = CookieHeader + "";
|
||||||
|
|
||||||
var categoryMapping = MapTorznabCapsToTrackers(query);
|
var categoryMapping = MapTorznabCapsToTrackers(query);
|
||||||
|
@ -261,12 +260,14 @@ namespace Jackett.Common.Indexers
|
||||||
{ "order", GetOrder }
|
{ "order", GetOrder }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var searchString = Regex.Replace(query.GetQueryString(), @"[ -._]+", " ").Trim();
|
||||||
|
|
||||||
if (query.IsImdbQuery)
|
if (query.IsImdbQuery)
|
||||||
{
|
{
|
||||||
searchParams.Add("keywords", query.ImdbID);
|
searchParams.Add("keywords", query.ImdbID);
|
||||||
searchParams.Add("search_type", "t_both");
|
searchParams.Add("search_type", "t_both");
|
||||||
}
|
}
|
||||||
else
|
else if (!string.IsNullOrWhiteSpace(searchString))
|
||||||
{
|
{
|
||||||
searchParams.Add("keywords", searchString);
|
searchParams.Add("keywords", searchString);
|
||||||
searchParams.Add("search_type", "t_name");
|
searchParams.Add("search_type", "t_name");
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Jackett.Common.Utils;
|
using Jackett.Common.Utils;
|
||||||
|
|
||||||
|
@ -16,48 +17,53 @@ namespace Jackett.Common.Models.DTO
|
||||||
QueryType = "search"
|
QueryType = "search"
|
||||||
};
|
};
|
||||||
|
|
||||||
var queryStr = request.Query;
|
var queryStr = $"{request.Query}".Trim();
|
||||||
if (queryStr != null)
|
|
||||||
{
|
|
||||||
var seasonMatch = Regex.Match(queryStr, @"S(\d{2,4})");
|
|
||||||
if (seasonMatch.Success)
|
|
||||||
{
|
|
||||||
stringQuery.Season = int.Parse(seasonMatch.Groups[1].Value);
|
|
||||||
queryStr = queryStr.Remove(seasonMatch.Index, seasonMatch.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
var episodeMatch = Regex.Match(queryStr, @"E(\d{2,4}[A-Za-z]?)");
|
if (!string.IsNullOrWhiteSpace(queryStr))
|
||||||
if (episodeMatch.Success)
|
|
||||||
{
|
{
|
||||||
stringQuery.Episode = episodeMatch.Groups[1].Value.TrimStart(new char[] { '0' });
|
var seasonEpisodeMatch = Regex.Match(queryStr, @"\bS(\d{2,4})E(\d{2,4}[A-Za-z]?)$");
|
||||||
queryStr = queryStr.Remove(episodeMatch.Index, episodeMatch.Length);
|
if (seasonEpisodeMatch.Success)
|
||||||
}
|
{
|
||||||
queryStr = queryStr.Trim();
|
stringQuery.Season = int.Parse(seasonEpisodeMatch.Groups[1].Value);
|
||||||
|
stringQuery.Episode = seasonEpisodeMatch.Groups[2].Value.TrimStart('0');
|
||||||
|
queryStr = queryStr.Remove(seasonEpisodeMatch.Index, seasonEpisodeMatch.Length).Trim();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
queryStr = ""; // empty string search is interpreted as null
|
var episodeMatch = Regex.Match(queryStr, @"\bE(\d{2,4}[A-Za-z]?)$");
|
||||||
|
if (episodeMatch.Success)
|
||||||
|
{
|
||||||
|
stringQuery.Episode = episodeMatch.Groups[1].Value.TrimStart('0');
|
||||||
|
queryStr = queryStr.Remove(episodeMatch.Index, episodeMatch.Length).Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
var seasonMatch = Regex.Match(queryStr, @"\bS(\d{2,4})$");
|
||||||
|
if (seasonMatch.Success)
|
||||||
|
{
|
||||||
|
stringQuery.Season = int.Parse(seasonMatch.Groups[1].Value);
|
||||||
|
queryStr = queryStr.Remove(seasonMatch.Index, seasonMatch.Length).Trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
queryStr = queryStr.Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
stringQuery.SearchTerm = queryStr;
|
stringQuery.SearchTerm = queryStr;
|
||||||
stringQuery.Categories = request.Category ?? new int[0];
|
stringQuery.Categories = request.Category ?? Array.Empty<int>();
|
||||||
|
|
||||||
// try to build an IMDB Query (tt plus 6 to 8 digits)
|
// try to build an IMDB Query (tt plus 6 to 8 digits)
|
||||||
if (stringQuery.SanitizedSearchTerm.StartsWith("tt") && stringQuery.SanitizedSearchTerm.Length <= 10)
|
if (stringQuery.SanitizedSearchTerm.StartsWith("tt") && stringQuery.SanitizedSearchTerm.Length <= 10)
|
||||||
{
|
{
|
||||||
var imdbID = ParseUtil.GetFullImdbID(stringQuery.SanitizedSearchTerm);
|
var imdbId = ParseUtil.GetFullImdbID(stringQuery.SanitizedSearchTerm);
|
||||||
TorznabQuery imdbQuery = null;
|
if (imdbId != null)
|
||||||
if (imdbID != null)
|
|
||||||
{
|
{
|
||||||
imdbQuery = new TorznabQuery()
|
return new TorznabQuery
|
||||||
{
|
{
|
||||||
ImdbID = imdbID,
|
ImdbID = imdbId,
|
||||||
Categories = stringQuery.Categories,
|
Categories = stringQuery.Categories,
|
||||||
Season = stringQuery.Season,
|
Season = stringQuery.Season,
|
||||||
Episode = stringQuery.Episode,
|
Episode = stringQuery.Episode,
|
||||||
};
|
};
|
||||||
|
|
||||||
return imdbQuery;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
using Jackett.Common.Models.DTO;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
namespace Jackett.Test.Common.Models.DTO
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class ApiSearchTests
|
||||||
|
{
|
||||||
|
[TestCase("The.Good.Lord.S01E05.720p.WEB.H264-CAKES", "The.Good.Lord.S01E05.720p.WEB.H264-CAKES", 0, null)]
|
||||||
|
[TestCase("The.Good.Lord.S01E05.", "The.Good.Lord.S01E05.", 0, null)]
|
||||||
|
[TestCase("The.Good.Lord.S01E05", "The.Good.Lord. S01E05", 1, "5")]
|
||||||
|
[TestCase("The Good Lord S01E05", "The Good Lord S01E05", 1, "5")]
|
||||||
|
[TestCase("The Good Lord S01 E05", "The Good Lord S01E05", 1, "5")]
|
||||||
|
[TestCase("The Good Lord S01", "The Good Lord S01", 1, null)]
|
||||||
|
[TestCase("The Good Lord E05", "The Good Lord", 0, "5")]
|
||||||
|
[TestCase("The.Good.Lord.s01e05", "The.Good.Lord.s01e05", 0, null)]
|
||||||
|
[TestCase("The.Good.Lord.S01e05", "The.Good.Lord.S01e05", 0, null)]
|
||||||
|
[TestCase("The.Good.Lord.s01E05", "The.Good.Lord.s01E05", 0, null)]
|
||||||
|
[TestCase("The.Good.Lord.S1E5", "The.Good.Lord.S1E5", 0, null)]
|
||||||
|
[TestCase("The.Good.Lord.S11E5", "The.Good.Lord.S11E5", 0, null)]
|
||||||
|
[TestCase("The.Good.Lord.S1E15", "The.Good.Lord.S1E15", 0, null)]
|
||||||
|
public void TestToTorznabQuery(string query, string expected, int season, string episode)
|
||||||
|
{
|
||||||
|
var request = new ApiSearch { Query = query };
|
||||||
|
var currentQuery = ApiSearch.ToTorznabQuery(request);
|
||||||
|
|
||||||
|
Assert.AreEqual(expected, currentQuery.GetQueryString());
|
||||||
|
Assert.AreEqual(season, currentQuery.Season);
|
||||||
|
Assert.AreEqual(episode, currentQuery.Episode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue