diff --git a/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNetRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNetRequestGenerator.cs index c36a90712..a0e3ec1b2 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNetRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNetRequestGenerator.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Text.RegularExpressions; +using System.Globalization; using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.IndexerSearch.Definitions; @@ -50,50 +50,61 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet var parameters = new BroadcastheNetTorrentQuery(); - var searchString = searchCriteria.SearchTerm != null ? searchCriteria.SearchTerm : ""; + var searchString = searchCriteria.SearchTerm ?? ""; var btnResults = searchCriteria.Limit.GetValueOrDefault(); if (btnResults == 0) { - btnResults = (int)Capabilities.LimitsDefault; + btnResults = Capabilities.LimitsDefault.GetValueOrDefault(PageSize); } - var btnOffset = searchCriteria.Offset.GetValueOrDefault(); + var btnOffset = searchCriteria.Offset.GetValueOrDefault(0); if (searchCriteria.TvdbId > 0) { - parameters.Tvdb = string.Format("{0}", searchCriteria.TvdbId); + parameters.Tvdb = $"{searchCriteria.TvdbId}"; } if (searchCriteria.RId > 0) { - parameters.Tvrage = string.Format("{0}", searchCriteria.RId); + parameters.Tvrage = $"{searchCriteria.RId}"; } // If only the season/episode is searched for then change format to match expected format if (searchCriteria.Season > 0 && searchCriteria.Episode.IsNullOrWhiteSpace()) { - // Season Only - parameters.Name = string.Format("Season {0}%", searchCriteria.Season.Value); + // Search Season parameters.Category = "Season"; + parameters.Name = $"Season {searchCriteria.Season}%"; + pageableRequests.Add(GetPagedRequests(parameters, btnResults, btnOffset)); + + parameters = parameters.Clone(); + + // Search Episode + parameters.Category = "Episode"; + parameters.Name = $"S{searchCriteria.Season:00}E%"; + pageableRequests.Add(GetPagedRequests(parameters, btnResults, btnOffset)); } - else if (searchCriteria.Season > 0 && Regex.IsMatch(searchCriteria.EpisodeSearchString, "(\\d{4}\\.\\d{2}\\.\\d{2})")) + else if (DateTime.TryParseExact($"{searchCriteria.Season} {searchCriteria.Episode}", "yyyy MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var showDate)) { // Daily Episode - parameters.Name = searchCriteria.EpisodeSearchString; + parameters.Name = showDate.ToString("yyyy.MM.dd"); parameters.Category = "Episode"; + pageableRequests.Add(GetPagedRequests(parameters, btnResults, btnOffset)); } - else if (searchCriteria.Season > 0 && int.Parse(searchCriteria.Episode) > 0) + else if (searchCriteria.Season > 0 && int.TryParse(searchCriteria.Episode, out var episode) && episode > 0) { // Standard (S/E) Episode - parameters.Name = string.Format("S{0:00}E{1:00}", searchCriteria.Season.Value, int.Parse(searchCriteria.Episode)); + parameters.Name = $"S{searchCriteria.Season:00}E{episode:00}"; parameters.Category = "Episode"; + pageableRequests.Add(GetPagedRequests(parameters, btnResults, btnOffset)); + } + else + { + // Neither a season only search nor daily nor standard, fall back to query + parameters.Search = searchString.Replace(" ", "%"); + pageableRequests.Add(GetPagedRequests(parameters, btnResults, btnOffset)); } - - // Neither a season only search nor daily nor standard, fall back to query - parameters.Search = searchString.Replace(" ", "%"); - - pageableRequests.Add(GetPagedRequests(parameters, btnResults, btnOffset)); return pageableRequests; } @@ -109,17 +120,17 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet var parameters = new BroadcastheNetTorrentQuery(); - var searchString = searchCriteria.SearchTerm != null ? searchCriteria.SearchTerm : ""; + var searchString = searchCriteria.SearchTerm ?? ""; var btnResults = searchCriteria.Limit.GetValueOrDefault(); if (btnResults == 0) { - btnResults = (int)Capabilities.LimitsDefault; + btnResults = Capabilities.LimitsDefault.GetValueOrDefault(PageSize); } - parameters.Search = searchString.Replace(" ", "%"); + var btnOffset = searchCriteria.Offset.GetValueOrDefault(0); - var btnOffset = searchCriteria.Offset.GetValueOrDefault(); + parameters.Search = searchString.Replace(" ", "%"); pageableRequests.Add(GetPagedRequests(parameters, btnResults, btnOffset));