Skip to content

Commit

Permalink
Optimise filter logic
Browse files Browse the repository at this point in the history
  • Loading branch information
PCJones committed Nov 11, 2024
1 parent 16d3ca9 commit d0978b3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions MediathekArr/Services/MediathekSearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public async Task<string> FetchSearchResultsFromApiById(TvdbData tvdbData, strin
}

var initialResults = responseObject.Result.Results;
var resultsByAiredDate = FilterByAiredDate(initialResults, episode.Aired!.Value);
var resultsByTitleDate = FilterByTitleDate(initialResults, episode.Aired.Value);
var resultsByDescriptionDate = FilterByDescriptionDate(initialResults, episode.Aired.Value);
var resultsByEpisodeTitleMatch = FilterByEpisodeTitleMatch(initialResults, episode.Name);
var resultsByAiredDate = FilterByAiredDate(initialResults, episode.Aired!.Value).Where(item => !ShouldSkipItem(item)).ToList();
var resultsByTitleDate = FilterByTitleDate(initialResults, episode.Aired.Value).Where(item => !ShouldSkipItem(item)).ToList();
var resultsByDescriptionDate = FilterByDescriptionDate(initialResults, episode.Aired.Value).Where(item => !ShouldSkipItem(item)).ToList();
var resultsByEpisodeTitleMatch = FilterByEpisodeTitleMatch(initialResults, episode.Name).Where(item => !ShouldSkipItem(item)).ToList();
List<ApiResultItem> resultsBySeasonEpisodeMatch = [];
// if more than 3 results we assume episode title match wasn't correct
if (resultsByEpisodeTitleMatch.Count > 3)
Expand All @@ -114,7 +114,9 @@ public async Task<string> FetchSearchResultsFromApiById(TvdbData tvdbData, strin
if (resultsByAiredDate.Count == 0 && resultsByTitleDate.Count == 0 && resultsByDescriptionDate.Count == 0 && resultsByEpisodeTitleMatch.Count == 0)
{
// Only trust Mediathek season/episode if no other match:
resultsBySeasonEpisodeMatch = FilterBySeasonEpisodeMatch(initialResults, episode.SeasonNumber.ToString(), episode.EpisodeNumber.ToString());
resultsBySeasonEpisodeMatch =
FilterBySeasonEpisodeMatch(initialResults, episode.SeasonNumber.ToString(), episode.EpisodeNumber.ToString())
.Where(item => !ShouldSkipItem(item)).ToList(); ;
}

// HashSet to remove duplicates
Expand Down Expand Up @@ -268,7 +270,7 @@ private string ConvertIdSearchApiResponseToRss(MediathekApiResponse? filteredRes
Total = filteredResponse.Result.QueryInfo.ResultCount
},
Items = filteredResponse.Result.Results
.Where(item => !ShouldSkipItem(item))
// .Where(item => !ShouldSkipItem(item)) we already do this earlier for id searches in ApplyFilters
.SelectMany(item => GenerateRssItems(item, season, episode, tvdbData)) // Generate RSS items for each link
.ToList()
}
Expand Down

0 comments on commit d0978b3

Please sign in to comment.