mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
broadcasthenet: improve searching by season/episode
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
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;
|
||||||
@@ -110,8 +110,8 @@ 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 searchTerm = query.SearchTerm ?? string.Empty;
|
||||||
searchString = Regex.Replace(searchString, @"(?i)\bS0*(\d+)\b", "Season $1");
|
|
||||||
var btnResults = query.Limit;
|
var btnResults = query.Limit;
|
||||||
if (btnResults == 0)
|
if (btnResults == 0)
|
||||||
{
|
{
|
||||||
@@ -120,22 +120,47 @@ namespace Jackett.Common.Indexers
|
|||||||
|
|
||||||
var btnOffset = query.Offset;
|
var btnOffset = query.Offset;
|
||||||
var releases = new List<ReleaseInfo>();
|
var releases = new List<ReleaseInfo>();
|
||||||
var searchParam = new Dictionary<string, string>();
|
|
||||||
|
var parameters = new Dictionary<string, object>();
|
||||||
|
|
||||||
if (query.IsTvdbQuery)
|
if (query.IsTvdbQuery)
|
||||||
{
|
{
|
||||||
searchParam["tvdb"] = $"{query.TvdbID}";
|
parameters["tvdb"] = query.TvdbID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (searchString.IsNotNullOrWhiteSpace())
|
if (searchTerm.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
searchParam["search"] = searchString.Replace(" ", "%");
|
parameters["search"] = searchTerm.Replace(" ", "%");
|
||||||
}
|
}
|
||||||
|
|
||||||
var parameters = new JArray
|
// If only the season/episode is searched for then change format to match expected format
|
||||||
|
if (query.Season > 0 && query.Episode.IsNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
parameters["category"] = "Episode";
|
||||||
|
parameters["name"] = $"S{query.Season:00}E%";
|
||||||
|
}
|
||||||
|
else if (DateTime.TryParseExact($"{query.Season} {query.Episode}", "yyyy MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var showDate))
|
||||||
|
{
|
||||||
|
// Daily Episode
|
||||||
|
parameters["name"] = showDate.ToString("yyyy.MM.dd");
|
||||||
|
parameters["category"] = "Episode";
|
||||||
|
}
|
||||||
|
else if (query.Season > 0 && int.TryParse(query.Episode, out var episode) && episode > 0)
|
||||||
|
{
|
||||||
|
// Standard (S/E) Episode
|
||||||
|
parameters["name"] = $"S{query.Season:00}E{episode:00}%";
|
||||||
|
parameters["category"] = "Episode";
|
||||||
|
}
|
||||||
|
else if (searchTerm.IsNotNullOrWhiteSpace() && int.TryParse(searchTerm, out _) && query.TvdbID > 0)
|
||||||
|
{
|
||||||
|
// Disable ID-based searches for episodes with absolute episode number
|
||||||
|
return releases;
|
||||||
|
}
|
||||||
|
|
||||||
|
var requestPayload = new JArray
|
||||||
{
|
{
|
||||||
new JValue(configData.Key.Value),
|
new JValue(configData.Key.Value),
|
||||||
JObject.FromObject(searchParam),
|
JObject.FromObject(parameters),
|
||||||
new JValue(btnResults),
|
new JValue(btnResults),
|
||||||
new JValue(btnOffset)
|
new JValue(btnOffset)
|
||||||
};
|
};
|
||||||
@@ -146,14 +171,17 @@ namespace Jackett.Common.Indexers
|
|||||||
{
|
{
|
||||||
{"Accept", "application/json-rpc, application/json"},
|
{"Accept", "application/json-rpc, application/json"},
|
||||||
{"Content-Type", "application/json-rpc"}
|
{"Content-Type", "application/json-rpc"}
|
||||||
}, rawbody: JsonRPCRequest("getTorrents", parameters), emulateBrowser: false);
|
}, rawbody: JsonRPCRequest("getTorrents", requestPayload), emulateBrowser: false);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var btnResponse = JsonConvert.DeserializeObject<BTNRPCResponse>(response.ContentString);
|
var btnResponse = JsonConvert.DeserializeObject<BTNRPCResponse>(response.ContentString);
|
||||||
|
|
||||||
if (btnResponse?.Result?.Torrents != null)
|
if (btnResponse?.Result?.Torrents == null)
|
||||||
{
|
{
|
||||||
|
return releases;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var itemKey in btnResponse.Result.Torrents)
|
foreach (var itemKey in btnResponse.Result.Torrents)
|
||||||
{
|
{
|
||||||
var btnResult = itemKey.Value;
|
var btnResult = itemKey.Value;
|
||||||
@@ -196,7 +224,9 @@ namespace Jackett.Common.Indexers
|
|||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(btnResult.YoutubeTrailer))
|
if (!string.IsNullOrWhiteSpace(btnResult.YoutubeTrailer))
|
||||||
{
|
{
|
||||||
descriptions.Add("Youtube Trailer: <a href=\"" + btnResult.YoutubeTrailer + "\">" + btnResult.YoutubeTrailer + "</a>");
|
descriptions.Add(
|
||||||
|
"Youtube Trailer: <a href=\"" + btnResult.YoutubeTrailer + "\">" + btnResult.YoutubeTrailer +
|
||||||
|
"</a>");
|
||||||
}
|
}
|
||||||
|
|
||||||
var imdb = ParseUtil.GetImdbId(btnResult.ImdbID);
|
var imdb = ParseUtil.GetImdbId(btnResult.ImdbID);
|
||||||
@@ -240,7 +270,6 @@ namespace Jackett.Common.Indexers
|
|||||||
releases.Add(release);
|
releases.Add(release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
OnParseError(response.ContentString, ex);
|
OnParseError(response.ContentString, ex);
|
||||||
|
Reference in New Issue
Block a user