|
|
|
@ -68,7 +68,7 @@ namespace NzbDrone.Core.IndexerSearch
|
|
|
|
|
throw new SearchFailedException("Air date is missing");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SearchDaily(series, episode, userInvokedSearch, interactiveSearch);
|
|
|
|
|
return SearchDaily(series, episode, false, userInvokedSearch, interactiveSearch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (series.SeriesType == SeriesTypes.Anime)
|
|
|
|
@ -78,19 +78,19 @@ namespace NzbDrone.Core.IndexerSearch
|
|
|
|
|
episode.AbsoluteEpisodeNumber == null)
|
|
|
|
|
{
|
|
|
|
|
// Search for special episodes in season 0 that don't have absolute episode numbers
|
|
|
|
|
return SearchSpecial(series, new List<Episode> { episode }, userInvokedSearch, interactiveSearch);
|
|
|
|
|
return SearchSpecial(series, new List<Episode> { episode }, false, userInvokedSearch, interactiveSearch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SearchAnime(series, episode, userInvokedSearch, interactiveSearch);
|
|
|
|
|
return SearchAnime(series, episode, false, userInvokedSearch, interactiveSearch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (episode.SeasonNumber == 0)
|
|
|
|
|
{
|
|
|
|
|
// Search for special episodes in season 0
|
|
|
|
|
return SearchSpecial(series, new List<Episode> { episode }, userInvokedSearch, interactiveSearch);
|
|
|
|
|
return SearchSpecial(series, new List<Episode> { episode }, false, userInvokedSearch, interactiveSearch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SearchSingle(series, episode, userInvokedSearch, interactiveSearch);
|
|
|
|
|
return SearchSingle(series, episode, false, userInvokedSearch, interactiveSearch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<DownloadDecision> SeasonSearch(int seriesId, int seasonNumber, bool missingOnly, bool monitoredOnly, bool userInvokedSearch, bool interactiveSearch)
|
|
|
|
@ -104,115 +104,215 @@ namespace NzbDrone.Core.IndexerSearch
|
|
|
|
|
|
|
|
|
|
return SeasonSearch(seriesId, seasonNumber, episodes, monitoredOnly, userInvokedSearch, interactiveSearch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<DownloadDecision> SeasonSearch(int seriesId, int seasonNumber, List<Episode> episodes, bool monitoredOnly, bool userInvokedSearch, bool interactiveSearch)
|
|
|
|
|
{
|
|
|
|
|
var series = _seriesService.GetSeries(seriesId);
|
|
|
|
|
|
|
|
|
|
if (series.SeriesType == SeriesTypes.Anime)
|
|
|
|
|
{
|
|
|
|
|
return SearchAnimeSeason(series, episodes, userInvokedSearch, interactiveSearch);
|
|
|
|
|
return SearchAnimeSeason(series, episodes, monitoredOnly, userInvokedSearch, interactiveSearch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (series.SeriesType == SeriesTypes.Daily)
|
|
|
|
|
{
|
|
|
|
|
return SearchDailySeason(series, episodes, userInvokedSearch, interactiveSearch);
|
|
|
|
|
return SearchDailySeason(series, episodes, monitoredOnly, userInvokedSearch, interactiveSearch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (seasonNumber == 0)
|
|
|
|
|
{
|
|
|
|
|
// search for special episodes in season 0
|
|
|
|
|
return SearchSpecial(series, episodes, userInvokedSearch, interactiveSearch);
|
|
|
|
|
}
|
|
|
|
|
var mappings = GetSceneSeasonMappings(series, episodes);
|
|
|
|
|
|
|
|
|
|
var downloadDecisions = new List<DownloadDecision>();
|
|
|
|
|
|
|
|
|
|
if (series.UseSceneNumbering)
|
|
|
|
|
foreach (var mapping in mappings)
|
|
|
|
|
{
|
|
|
|
|
var sceneSeasonGroups = episodes.GroupBy(v =>
|
|
|
|
|
if (mapping.SeasonNumber == 0)
|
|
|
|
|
{
|
|
|
|
|
if (v.SceneSeasonNumber.HasValue && v.SceneEpisodeNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return v.SceneSeasonNumber.Value;
|
|
|
|
|
}
|
|
|
|
|
return v.SeasonNumber;
|
|
|
|
|
}).Distinct();
|
|
|
|
|
// search for special episodes in season 0
|
|
|
|
|
downloadDecisions.AddRange(SearchSpecial(series, mapping.Episodes, monitoredOnly, userInvokedSearch, interactiveSearch));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var sceneSeasonEpisodes in sceneSeasonGroups)
|
|
|
|
|
if (mapping.Episodes.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
if (sceneSeasonEpisodes.Count() == 1)
|
|
|
|
|
{
|
|
|
|
|
var episode = sceneSeasonEpisodes.First();
|
|
|
|
|
var searchSpec = Get<SingleEpisodeSearchCriteria>(series, sceneSeasonEpisodes.ToList(), userInvokedSearch, interactiveSearch);
|
|
|
|
|
var searchSpec = Get<SingleEpisodeSearchCriteria>(series, mapping, monitoredOnly, userInvokedSearch, interactiveSearch);
|
|
|
|
|
searchSpec.SeasonNumber = mapping.SeasonNumber;
|
|
|
|
|
searchSpec.EpisodeNumber = mapping.EpisodeMapping.EpisodeNumber;
|
|
|
|
|
|
|
|
|
|
searchSpec.SeasonNumber = sceneSeasonEpisodes.Key;
|
|
|
|
|
searchSpec.MonitoredEpisodesOnly = monitoredOnly;
|
|
|
|
|
var decisions = Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
|
|
|
|
|
downloadDecisions.AddRange(decisions);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var searchSpec = Get<SeasonSearchCriteria>(series, mapping, monitoredOnly, userInvokedSearch, interactiveSearch);
|
|
|
|
|
searchSpec.SeasonNumber = mapping.SeasonNumber;
|
|
|
|
|
|
|
|
|
|
if (episode.SceneSeasonNumber.HasValue && episode.SceneEpisodeNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
searchSpec.EpisodeNumber = episode.SceneEpisodeNumber.Value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
searchSpec.EpisodeNumber = episode.EpisodeNumber;
|
|
|
|
|
}
|
|
|
|
|
var decisions = Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
|
|
|
|
|
downloadDecisions.AddRange(decisions);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return downloadDecisions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<SceneSeasonMapping> GetSceneSeasonMappings(Series series, List<Episode> episodes)
|
|
|
|
|
{
|
|
|
|
|
var dict = new Dictionary<SceneSeasonMapping, SceneSeasonMapping>();
|
|
|
|
|
|
|
|
|
|
var decisions = Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
|
|
|
|
|
downloadDecisions.AddRange(decisions);
|
|
|
|
|
var sceneMappings = _sceneMapping.FindByTvdbId(series.TvdbId);
|
|
|
|
|
|
|
|
|
|
// Group the episode by SceneSeasonNumber/SeasonNumber, in 99% of cases this will result in 1 groupedEpisode
|
|
|
|
|
var groupedEpisodes = episodes.ToLookup(v => (v.SceneSeasonNumber ?? v.SeasonNumber) * 100000 + v.SeasonNumber);
|
|
|
|
|
|
|
|
|
|
foreach (var groupedEpisode in groupedEpisodes)
|
|
|
|
|
{
|
|
|
|
|
var episodeMappings = GetSceneEpisodeMappings(series, groupedEpisode.First(), sceneMappings);
|
|
|
|
|
|
|
|
|
|
foreach (var episodeMapping in episodeMappings)
|
|
|
|
|
{
|
|
|
|
|
var seasonMapping = new SceneSeasonMapping
|
|
|
|
|
{
|
|
|
|
|
Episodes = groupedEpisode.ToList(),
|
|
|
|
|
EpisodeMapping = episodeMapping,
|
|
|
|
|
SceneTitles = episodeMapping.SceneTitles,
|
|
|
|
|
SearchMode = episodeMapping.SearchMode,
|
|
|
|
|
SeasonNumber = episodeMapping.SeasonNumber
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (dict.TryGetValue(seasonMapping, out var existing))
|
|
|
|
|
{
|
|
|
|
|
existing.Episodes.AddRange(seasonMapping.Episodes);
|
|
|
|
|
existing.SceneTitles.AddRange(seasonMapping.SceneTitles);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var searchSpec = Get<SeasonSearchCriteria>(series, sceneSeasonEpisodes.ToList(), userInvokedSearch, interactiveSearch);
|
|
|
|
|
searchSpec.SeasonNumber = sceneSeasonEpisodes.Key;
|
|
|
|
|
searchSpec.MonitoredEpisodesOnly = monitoredOnly;
|
|
|
|
|
|
|
|
|
|
var decisions = Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
|
|
|
|
|
downloadDecisions.AddRange(decisions);
|
|
|
|
|
dict[seasonMapping] = seasonMapping;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
foreach (var item in dict)
|
|
|
|
|
{
|
|
|
|
|
var searchSpec = Get<SeasonSearchCriteria>(series, episodes, userInvokedSearch, interactiveSearch);
|
|
|
|
|
searchSpec.SeasonNumber = seasonNumber;
|
|
|
|
|
searchSpec.MonitoredEpisodesOnly = monitoredOnly;
|
|
|
|
|
item.Value.Episodes = item.Value.Episodes.Distinct().ToList();
|
|
|
|
|
item.Value.SceneTitles = item.Value.SceneTitles.Distinct().ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var decisions = Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
|
|
|
|
|
downloadDecisions.AddRange(decisions);
|
|
|
|
|
return dict.Values.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<SceneEpisodeMapping> GetSceneEpisodeMappings(Series series, Episode episode)
|
|
|
|
|
{
|
|
|
|
|
var dict = new Dictionary<SceneEpisodeMapping, SceneEpisodeMapping>();
|
|
|
|
|
|
|
|
|
|
var sceneMappings = _sceneMapping.FindByTvdbId(series.TvdbId);
|
|
|
|
|
|
|
|
|
|
var episodeMappings = GetSceneEpisodeMappings(series, episode, sceneMappings);
|
|
|
|
|
|
|
|
|
|
foreach (var episodeMapping in episodeMappings)
|
|
|
|
|
{
|
|
|
|
|
if (dict.TryGetValue(episodeMapping, out var existing))
|
|
|
|
|
{
|
|
|
|
|
existing.SceneTitles.AddRange(episodeMapping.SceneTitles);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dict[episodeMapping] = episodeMapping;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return downloadDecisions;
|
|
|
|
|
foreach (var item in dict)
|
|
|
|
|
{
|
|
|
|
|
item.Value.SceneTitles = item.Value.SceneTitles.Distinct().ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dict.Values.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<DownloadDecision> SearchSingle(Series series, Episode episode, bool userInvokedSearch, bool interactiveSearch)
|
|
|
|
|
private IEnumerable<SceneEpisodeMapping> GetSceneEpisodeMappings(Series series, Episode episode, List<SceneMapping> sceneMappings)
|
|
|
|
|
{
|
|
|
|
|
var searchSpec = Get<SingleEpisodeSearchCriteria>(series, new List<Episode> { episode }, userInvokedSearch, interactiveSearch);
|
|
|
|
|
var includeGlobal = true;
|
|
|
|
|
|
|
|
|
|
foreach (var sceneMapping in sceneMappings)
|
|
|
|
|
{
|
|
|
|
|
if (sceneMapping.ParseTerm == series.CleanTitle && sceneMapping.FilterRegex.IsNotNullOrWhiteSpace())
|
|
|
|
|
{
|
|
|
|
|
// Disable the implied mapping if we have an explicit mapping by the same name
|
|
|
|
|
includeGlobal = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// By default we do a alt title search in case indexers don't have the release properly indexed. Services can override this behavior.
|
|
|
|
|
var searchMode = sceneMapping.SearchMode ?? ((sceneMapping.SceneSeasonNumber ?? -1) != -1 ? SearchMode.SearchTitle : SearchMode.Default);
|
|
|
|
|
|
|
|
|
|
if (sceneMapping.SceneOrigin == "tvdb")
|
|
|
|
|
{
|
|
|
|
|
yield return new SceneEpisodeMapping
|
|
|
|
|
{
|
|
|
|
|
Episode = episode,
|
|
|
|
|
SearchMode = searchMode,
|
|
|
|
|
SceneTitles = new List<string> { sceneMapping.SearchTerm },
|
|
|
|
|
SeasonNumber = (sceneMapping.SceneSeasonNumber ?? -1) == -1 ? episode.SeasonNumber : sceneMapping.SceneSeasonNumber.Value,
|
|
|
|
|
EpisodeNumber = episode.EpisodeNumber,
|
|
|
|
|
AbsoluteEpisodeNumber = episode.AbsoluteEpisodeNumber
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
yield return new SceneEpisodeMapping
|
|
|
|
|
{
|
|
|
|
|
Episode = episode,
|
|
|
|
|
SearchMode = searchMode,
|
|
|
|
|
SceneTitles = new List<string> { sceneMapping.SearchTerm },
|
|
|
|
|
SeasonNumber = (sceneMapping.SceneSeasonNumber ?? -1) == -1 ? (episode.SceneSeasonNumber ?? episode.SeasonNumber) : sceneMapping.SceneSeasonNumber.Value,
|
|
|
|
|
EpisodeNumber = episode.SceneEpisodeNumber ?? episode.EpisodeNumber,
|
|
|
|
|
AbsoluteEpisodeNumber = episode.SceneAbsoluteEpisodeNumber ?? episode.AbsoluteEpisodeNumber
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (series.UseSceneNumbering && episode.SceneSeasonNumber.HasValue && episode.SceneEpisodeNumber.HasValue)
|
|
|
|
|
if (includeGlobal)
|
|
|
|
|
{
|
|
|
|
|
searchSpec.EpisodeNumber = episode.SceneEpisodeNumber.Value;
|
|
|
|
|
searchSpec.SeasonNumber = episode.SceneSeasonNumber.Value;
|
|
|
|
|
yield return new SceneEpisodeMapping
|
|
|
|
|
{
|
|
|
|
|
Episode = episode,
|
|
|
|
|
SearchMode = SearchMode.Default,
|
|
|
|
|
SceneTitles = new List<string> { series.Title },
|
|
|
|
|
SeasonNumber = episode.SceneSeasonNumber ?? episode.SeasonNumber,
|
|
|
|
|
EpisodeNumber = episode.SceneEpisodeNumber ?? episode.EpisodeNumber,
|
|
|
|
|
AbsoluteEpisodeNumber = episode.SceneSeasonNumber ?? episode.AbsoluteEpisodeNumber
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<DownloadDecision> SearchSingle(Series series, Episode episode, bool monitoredOnly, bool userInvokedSearch, bool interactiveSearch)
|
|
|
|
|
{
|
|
|
|
|
var mappings = GetSceneEpisodeMappings(series, episode);
|
|
|
|
|
|
|
|
|
|
var downloadDecisions = new List<DownloadDecision>();
|
|
|
|
|
|
|
|
|
|
foreach (var mapping in mappings)
|
|
|
|
|
{
|
|
|
|
|
searchSpec.EpisodeNumber = episode.EpisodeNumber;
|
|
|
|
|
searchSpec.SeasonNumber = episode.SeasonNumber;
|
|
|
|
|
var searchSpec = Get<SingleEpisodeSearchCriteria>(series, mapping, monitoredOnly, userInvokedSearch, interactiveSearch);
|
|
|
|
|
searchSpec.SeasonNumber = mapping.SeasonNumber;
|
|
|
|
|
searchSpec.EpisodeNumber = mapping.EpisodeNumber;
|
|
|
|
|
|
|
|
|
|
var decisions = Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
|
|
|
|
|
downloadDecisions.AddRange(decisions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
|
|
|
|
|
return downloadDecisions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<DownloadDecision> SearchDaily(Series series, Episode episode, bool userInvokedSearch, bool interactiveSearch)
|
|
|
|
|
private List<DownloadDecision> SearchDaily(Series series, Episode episode, bool monitoredOnly, bool userInvokedSearch, bool interactiveSearch)
|
|
|
|
|
{
|
|
|
|
|
var airDate = DateTime.ParseExact(episode.AirDate, Episode.AIR_DATE_FORMAT, CultureInfo.InvariantCulture);
|
|
|
|
|
var searchSpec = Get<DailyEpisodeSearchCriteria>(series, new List<Episode> { episode }, userInvokedSearch, interactiveSearch);
|
|
|
|
|
var searchSpec = Get<DailyEpisodeSearchCriteria>(series, new List<Episode> { episode }, monitoredOnly, userInvokedSearch, interactiveSearch);
|
|
|
|
|
searchSpec.AirDate = airDate;
|
|
|
|
|
|
|
|
|
|
return Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<DownloadDecision> SearchAnime(Series series, Episode episode, bool userInvokedSearch, bool interactiveSearch, bool isSeasonSearch = false)
|
|
|
|
|
private List<DownloadDecision> SearchAnime(Series series, Episode episode, bool monitoredOnly, bool userInvokedSearch, bool interactiveSearch, bool isSeasonSearch = false)
|
|
|
|
|
{
|
|
|
|
|
var searchSpec = Get<AnimeEpisodeSearchCriteria>(series, new List<Episode> { episode }, userInvokedSearch, interactiveSearch);
|
|
|
|
|
var searchSpec = Get<AnimeEpisodeSearchCriteria>(series, new List<Episode> { episode }, monitoredOnly, userInvokedSearch, interactiveSearch);
|
|
|
|
|
|
|
|
|
|
searchSpec.IsSeasonSearch = isSeasonSearch;
|
|
|
|
|
|
|
|
|
@ -233,11 +333,11 @@ namespace NzbDrone.Core.IndexerSearch
|
|
|
|
|
return Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<DownloadDecision> SearchSpecial(Series series, List<Episode> episodes, bool userInvokedSearch, bool interactiveSearch)
|
|
|
|
|
private List<DownloadDecision> SearchSpecial(Series series, List<Episode> episodes,bool monitoredOnly, bool userInvokedSearch, bool interactiveSearch)
|
|
|
|
|
{
|
|
|
|
|
var downloadDecisions = new List<DownloadDecision>();
|
|
|
|
|
|
|
|
|
|
var searchSpec = Get<SpecialEpisodeSearchCriteria>(series, episodes, userInvokedSearch, interactiveSearch);
|
|
|
|
|
var searchSpec = Get<SpecialEpisodeSearchCriteria>(series, episodes, monitoredOnly, userInvokedSearch, interactiveSearch);
|
|
|
|
|
// build list of queries for each episode in the form: "<series> <episode-title>"
|
|
|
|
|
searchSpec.EpisodeQueryTitles = episodes.Where(e => !string.IsNullOrWhiteSpace(e.Title))
|
|
|
|
|
.SelectMany(e => searchSpec.QueryTitles.Select(title => title + " " + SearchCriteriaBase.GetQueryTitle(e.Title)))
|
|
|
|
@ -248,62 +348,69 @@ namespace NzbDrone.Core.IndexerSearch
|
|
|
|
|
// Search for each episode by season/episode number as well
|
|
|
|
|
foreach (var episode in episodes)
|
|
|
|
|
{
|
|
|
|
|
downloadDecisions.AddRange(SearchSingle(series, episode, userInvokedSearch, interactiveSearch));
|
|
|
|
|
// Episode needs to be monitored if it's not an interactive search
|
|
|
|
|
if (!interactiveSearch && monitoredOnly && !episode.Monitored)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
downloadDecisions.AddRange(SearchSingle(series, episode, monitoredOnly, userInvokedSearch, interactiveSearch));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return downloadDecisions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<DownloadDecision> SearchAnimeSeason(Series series, List<Episode> episodes, bool userInvokedSearch, bool interactiveSearch)
|
|
|
|
|
private List<DownloadDecision> SearchAnimeSeason(Series series, List<Episode> episodes, bool monitoredOnly, bool userInvokedSearch, bool interactiveSearch)
|
|
|
|
|
{
|
|
|
|
|
var downloadDecisions = new List<DownloadDecision>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var episodesToSearch = episodes.Where(e =>
|
|
|
|
|
{
|
|
|
|
|
// Episode needs to be monitored if it's not an interactive search
|
|
|
|
|
if (!interactiveSearch && !e.Monitored)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure episode has an airdate and has already aired
|
|
|
|
|
return e.AirDateUtc.HasValue && e.AirDateUtc.Value.Before(DateTime.UtcNow);
|
|
|
|
|
});
|
|
|
|
|
// Episode needs to be monitored if it's not an interactive search
|
|
|
|
|
// and Ensure episode has an airdate and has already aired
|
|
|
|
|
var episodesToSearch = episodes
|
|
|
|
|
.Where(ep => interactiveSearch || !monitoredOnly || ep.Monitored)
|
|
|
|
|
.Where(ep => ep.AirDateUtc.HasValue && ep.AirDateUtc.Value.Before(DateTime.UtcNow))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var episode in episodesToSearch)
|
|
|
|
|
{
|
|
|
|
|
downloadDecisions.AddRange(SearchAnime(series, episode, userInvokedSearch, interactiveSearch, true));
|
|
|
|
|
downloadDecisions.AddRange(SearchAnime(series, episode, monitoredOnly, userInvokedSearch, interactiveSearch, true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return downloadDecisions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<DownloadDecision> SearchDailySeason(Series series, List<Episode> episodes, bool userInvokedSearch, bool interactiveSearch)
|
|
|
|
|
private List<DownloadDecision> SearchDailySeason(Series series, List<Episode> episodes, bool monitoredOnly, bool userInvokedSearch, bool interactiveSearch)
|
|
|
|
|
{
|
|
|
|
|
var downloadDecisions = new List<DownloadDecision>();
|
|
|
|
|
foreach (var yearGroup in episodes.Where(v => v.Monitored && v.AirDate.IsNotNullOrWhiteSpace())
|
|
|
|
|
.GroupBy(v => DateTime.ParseExact(v.AirDate, Episode.AIR_DATE_FORMAT, CultureInfo.InvariantCulture).Year))
|
|
|
|
|
|
|
|
|
|
// Episode needs to be monitored if it's not an interactive search
|
|
|
|
|
// and Ensure episode has an airdate
|
|
|
|
|
var episodesToSearch = episodes
|
|
|
|
|
.Where(ep => interactiveSearch || !monitoredOnly || ep.Monitored)
|
|
|
|
|
.Where(ep => ep.AirDate.IsNotNullOrWhiteSpace())
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var yearGroup in episodesToSearch.GroupBy(v => DateTime.ParseExact(v.AirDate, Episode.AIR_DATE_FORMAT, CultureInfo.InvariantCulture).Year))
|
|
|
|
|
{
|
|
|
|
|
var yearEpisodes = yearGroup.ToList();
|
|
|
|
|
|
|
|
|
|
if (yearEpisodes.Count > 1)
|
|
|
|
|
{
|
|
|
|
|
var searchSpec = Get<DailySeasonSearchCriteria>(series, yearEpisodes, userInvokedSearch, interactiveSearch);
|
|
|
|
|
var searchSpec = Get<DailySeasonSearchCriteria>(series, yearEpisodes, monitoredOnly, userInvokedSearch, interactiveSearch);
|
|
|
|
|
searchSpec.Year = yearGroup.Key;
|
|
|
|
|
|
|
|
|
|
downloadDecisions.AddRange(Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
downloadDecisions.AddRange(SearchDaily(series, yearEpisodes.First(), userInvokedSearch, interactiveSearch));
|
|
|
|
|
downloadDecisions.AddRange(SearchDaily(series, yearEpisodes.First(), monitoredOnly, userInvokedSearch, interactiveSearch));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return downloadDecisions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TSpec Get<TSpec>(Series series, List<Episode> episodes, bool userInvokedSearch, bool interactiveSearch) where TSpec : SearchCriteriaBase, new()
|
|
|
|
|
private TSpec Get<TSpec>(Series series, List<Episode> episodes, bool monitoredOnly, bool userInvokedSearch, bool interactiveSearch) where TSpec : SearchCriteriaBase, new()
|
|
|
|
|
{
|
|
|
|
|
var spec = new TSpec();
|
|
|
|
|
|
|
|
|
@ -311,16 +418,41 @@ namespace NzbDrone.Core.IndexerSearch
|
|
|
|
|
spec.SceneTitles = _sceneMapping.GetSceneNames(series.TvdbId,
|
|
|
|
|
episodes.Select(e => e.SeasonNumber).Distinct().ToList(),
|
|
|
|
|
episodes.Select(e => e.SceneSeasonNumber ?? e.SeasonNumber).Distinct().ToList());
|
|
|
|
|
spec.SceneMappings = _sceneMapping.GetSceneMappings(series.TvdbId,
|
|
|
|
|
episodes.Select(e => e.SeasonNumber).Distinct().ToList());
|
|
|
|
|
|
|
|
|
|
spec.Episodes = episodes;
|
|
|
|
|
spec.MonitoredEpisodesOnly = monitoredOnly;
|
|
|
|
|
spec.UserInvokedSearch = userInvokedSearch;
|
|
|
|
|
spec.InteractiveSearch = interactiveSearch;
|
|
|
|
|
|
|
|
|
|
return spec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!spec.SceneTitles.Contains(series.Title))
|
|
|
|
|
{
|
|
|
|
|
spec.SceneTitles.Add(series.Title);
|
|
|
|
|
}
|
|
|
|
|
private TSpec Get<TSpec>(Series series, SceneEpisodeMapping mapping, bool monitoredOnly, bool userInvokedSearch, bool interactiveSearch) where TSpec : SearchCriteriaBase, new()
|
|
|
|
|
{
|
|
|
|
|
var spec = new TSpec();
|
|
|
|
|
|
|
|
|
|
spec.Episodes = episodes;
|
|
|
|
|
spec.Series = series;
|
|
|
|
|
spec.SceneTitles = mapping.SceneTitles;
|
|
|
|
|
spec.SearchMode = mapping.SearchMode;
|
|
|
|
|
|
|
|
|
|
spec.Episodes = new List<Episode> { mapping.Episode };
|
|
|
|
|
spec.MonitoredEpisodesOnly = monitoredOnly;
|
|
|
|
|
spec.UserInvokedSearch = userInvokedSearch;
|
|
|
|
|
spec.InteractiveSearch = interactiveSearch;
|
|
|
|
|
|
|
|
|
|
return spec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TSpec Get<TSpec>(Series series, SceneSeasonMapping mapping, bool monitoredOnly, bool userInvokedSearch, bool interactiveSearch) where TSpec : SearchCriteriaBase, new()
|
|
|
|
|
{
|
|
|
|
|
var spec = new TSpec();
|
|
|
|
|
|
|
|
|
|
spec.Series = series;
|
|
|
|
|
spec.SceneTitles = mapping.SceneTitles;
|
|
|
|
|
spec.SearchMode = mapping.SearchMode;
|
|
|
|
|
|
|
|
|
|
spec.Episodes = mapping.Episodes;
|
|
|
|
|
spec.MonitoredEpisodesOnly = monitoredOnly;
|
|
|
|
|
spec.UserInvokedSearch = userInvokedSearch;
|
|
|
|
|
spec.InteractiveSearch = interactiveSearch;
|
|
|
|
|
|
|
|
|
|