Skip to content

Commit

Permalink
Fixed: (Search) Ensure TvMazeId is parsed correctly on a repeat search
Browse files Browse the repository at this point in the history
  • Loading branch information
mynameisbogdan committed Jul 16, 2023
1 parent 5e52627 commit 3fab8fb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
30 changes: 23 additions & 7 deletions src/NzbDrone.Core/IndexerSearch/Definitions/TvSearchCriteria.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,20 @@ public override string SearchQuery
{
get
{
var searchQueryTerm = $"Term: []";
var searchQueryTerm = "Term: []";
var searchEpisodeTerm = $" for Season / Episode:[{EpisodeSearchString}]";
if (SearchTerm.IsNotNullOrWhiteSpace())
{
searchQueryTerm = $"Term: [{SearchTerm}]";
}

if (!ImdbId.IsNotNullOrWhiteSpace() && !TvdbId.HasValue && !RId.HasValue && !TraktId.HasValue)
if (!ImdbId.IsNotNullOrWhiteSpace() &&
!TvdbId.HasValue &&
!RId.HasValue &&
!TraktId.HasValue &&
!TvMazeId.HasValue &&
!TmdbId.HasValue &&
!DoubanId.HasValue)
{
return $"{searchQueryTerm}{searchEpisodeTerm}";
}
Expand Down Expand Up @@ -80,41 +86,51 @@ public override string SearchQuery
builder.Append($" TraktId:[{TraktId}]");
}

if (TvMazeId.HasValue)
{
builder.Append($" TvMazeId:[{TvMazeId}]");
}

if (TmdbId.HasValue)
{
builder.Append($" TmdbId:[{TmdbId}]");
}

if (DoubanId.HasValue)
{
builder.Append($" DoubanId:[{DoubanId}]");
}

builder = builder.Append(searchEpisodeTerm);
return builder.ToString().Trim();
}
}

private string GetEpisodeSearchString()
{
if (Season == null || Season == 0)
if (Season is null or 0)
{
return string.Empty;
}

string episodeString;
if (DateTime.TryParseExact(string.Format("{0} {1}", Season, Episode), "yyyy MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var showDate))
if (DateTime.TryParseExact($"{Season} {Episode}", "yyyy MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var showDate))
{
episodeString = showDate.ToString("yyyy.MM.dd");
}
else if (Episode.IsNullOrWhiteSpace())
{
episodeString = string.Format("S{0:00}", Season);
episodeString = $"S{Season:00}";
}
else
{
try
{
episodeString = string.Format("S{0:00}E{1:00}", Season, ParseUtil.CoerceInt(Episode));
episodeString = $"S{Season:00}E{ParseUtil.CoerceInt(Episode):00}";
}
catch (FormatException)
{
episodeString = string.Format("S{0:00}E{1}", Season, Episode);
episodeString = $"S{Season:00}E{Episode}";
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/NzbDrone.Core/IndexerSearch/NewznabRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace NzbDrone.Core.IndexerSearch
{
public class NewznabRequest
{
private static readonly Regex TvRegex = new (@"\{((?:imdbid\:)(?<imdbid>[^{]+)|(?:rid\:)(?<rid>[^{]+)|(?:tvdbid\:)(?<tvdbid>[^{]+)|(?:tmdbid\:)(?<tmdbid>[^{]+)|(?:doubanid\:)(?<doubanid>[^{]+)|(?:season\:)(?<season>[^{]+)|(?:episode\:)(?<episode>[^{]+)|(?:year\:)(?<year>[^{]+)|(?:genre\:)(?<genre>[^{]+))\}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex TvRegex = new (@"\{((?:imdbid\:)(?<imdbid>[^{]+)|(?:rid\:)(?<rid>[^{]+)|(?:tvdbid\:)(?<tvdbid>[^{]+)|(?:tmdbid\:)(?<tmdbid>[^{]+)|(?:tvmazeid\:)(?<tvmazeid>[^{]+)|(?:doubanid\:)(?<doubanid>[^{]+)|(?:season\:)(?<season>[^{]+)|(?:episode\:)(?<episode>[^{]+)|(?:year\:)(?<year>[^{]+)|(?:genre\:)(?<genre>[^{]+))\}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex MovieRegex = new (@"\{((?:imdbid\:)(?<imdbid>[^{]+)|(?:doubanid\:)(?<doubanid>[^{]+)|(?:tmdbid\:)(?<tmdbid>[^{]+)|(?:traktid\:)(?<traktid>[^{]+)|(?:year\:)(?<year>[^{]+)|(?:genre\:)(?<genre>[^{]+))\}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex MusicRegex = new (@"\{((?:artist\:)(?<artist>[^{]+)|(?:album\:)(?<album>[^{]+)|(?:track\:)(?<track>[^{]+)|(?:label\:)(?<label>[^{]+)|(?:year\:)(?<year>[^{]+)|(?:genre\:)(?<genre>[^{]+))\}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex BookRegex = new (@"\{((?:author\:)(?<author>[^{]+)|(?:publisher\:)(?<publisher>[^{]+)|(?:title\:)(?<title>[^{]+)|(?:year\:)(?<year>[^{]+)|(?:genre\:)(?<genre>[^{]+))\}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
Expand Down Expand Up @@ -62,6 +62,11 @@ public void QueryToParams()
tmdbid = int.TryParse(match.Groups["tmdbid"].Value, out var tmdb) ? tmdb : null;
}

if (match.Groups["tvmazeid"].Success)
{
tvmazeid = int.TryParse(match.Groups["tvmazeid"].Value, out var tvmaze) ? tvmaze : null;
}

if (match.Groups["doubanid"].Success)
{
doubanid = int.TryParse(match.Groups["doubanid"].Value, out var tmdb) ? tmdb : null;
Expand All @@ -74,7 +79,7 @@ public void QueryToParams()

if (match.Groups["season"].Success)
{
season = int.TryParse(match.Groups["season"].Value, out var seasonParsed) ? seasonParsed : null;
season = int.TryParse(match.Groups["season"].Value, out var parsedSeason) ? parsedSeason : null;
}

if (match.Groups["imdbid"].Success)
Expand Down

0 comments on commit 3fab8fb

Please sign in to comment.