110 lines
4.0 KiB
C#
110 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using NLog;
|
|
using NzbDrone.Core.Download;
|
|
using NzbDrone.Core.Indexers;
|
|
using NzbDrone.Core.ReferenceData;
|
|
using NzbDrone.Core.Tv;
|
|
using NzbDrone.Core.Model;
|
|
using NzbDrone.Core.Model.Notification;
|
|
using NzbDrone.Core.DecisionEngine;
|
|
|
|
namespace NzbDrone.Core.Providers.Search
|
|
{
|
|
public class EpisodeSearch : SearchBase
|
|
{
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
public EpisodeSearch(IEpisodeService episodeService, DownloadProvider downloadProvider, IIndexerService indexerService,
|
|
SceneMappingService sceneMappingService, DownloadDirector downloadDirector,
|
|
ISeriesRepository seriesRepository)
|
|
: base(seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingService,
|
|
downloadDirector)
|
|
{
|
|
}
|
|
|
|
public EpisodeSearch()
|
|
{
|
|
}
|
|
|
|
public override List<EpisodeParseResult> PerformSearch(Series series, dynamic options, ProgressNotification notification)
|
|
{
|
|
//Todo: Daily and Anime or separate them out?
|
|
//Todo: Epsiodes that use scene numbering
|
|
|
|
if (options.Episode == null)
|
|
throw new ArgumentException("Episode is invalid");
|
|
|
|
notification.CurrentMessage = "Looking for " + options.Episode;
|
|
|
|
var reports = new List<EpisodeParseResult>();
|
|
var title = GetSearchTitle(series);
|
|
|
|
var seasonNumber = options.Episode.SeasonNumber;
|
|
var episodeNumber = options.Episode.EpisodeNumber;
|
|
|
|
if (series.UseSceneNumbering)
|
|
{
|
|
if (options.Episode.SceneSeasonNumber > 0 && options.Episode.SceneEpisodeNumber > 0)
|
|
{
|
|
logger.Trace("Using Scene Numbering for: {0}", options.Episode);
|
|
seasonNumber = options.Episode.SceneSeasonNumber;
|
|
episodeNumber = options.Episode.SceneEpisodeNumber;
|
|
}
|
|
}
|
|
|
|
Parallel.ForEach(_indexerService.GetEnabledIndexers(), indexer =>
|
|
{
|
|
try
|
|
{
|
|
reports.AddRange(indexer.FetchEpisode(title, seasonNumber, episodeNumber));
|
|
}
|
|
|
|
catch (Exception e)
|
|
{
|
|
logger.ErrorException(String.Format("An error has occurred while searching for {0}-S{1:00}E{2:00} from: {3}",
|
|
series.Title, options.Episode.SeasonNumber, options.Episode.EpisodeNumber, indexer.Name), e);
|
|
}
|
|
});
|
|
|
|
return reports;
|
|
}
|
|
|
|
public override bool IsEpisodeMatch(Series series, dynamic options, EpisodeParseResult episodeParseResult)
|
|
{
|
|
if (series.UseSceneNumbering && options.Episode.SeasonNumber > 0 && options.Episode.EpisodeNumber > 0)
|
|
{
|
|
if (options.Episode.SceneSeasonNumber != episodeParseResult.SeasonNumber)
|
|
{
|
|
logger.Trace("Season number does not match searched season number, skipping.");
|
|
return false;
|
|
}
|
|
|
|
if (!episodeParseResult.EpisodeNumbers.Contains(options.Episode.SceneEpisodeNumber))
|
|
{
|
|
logger.Trace("Episode number does not match searched episode number, skipping.");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
if (options.Episode.SeasonNumber != episodeParseResult.SeasonNumber)
|
|
{
|
|
logger.Trace("Season number does not match searched season number, skipping.");
|
|
return false;
|
|
}
|
|
|
|
if (!episodeParseResult.EpisodeNumbers.Contains(options.Episode.EpisodeNumber))
|
|
{
|
|
logger.Trace("Episode number does not match searched episode number, skipping.");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|
|
}
|