2013-03-07 04:45:36 +01:00
|
|
|
using System;
|
2013-01-11 01:35:33 +01:00
|
|
|
using System.Collections.Generic;
|
2013-03-07 04:45:36 +01:00
|
|
|
using System.Linq;
|
2013-01-11 01:35:33 +01:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using NLog;
|
2013-03-07 04:45:36 +01:00
|
|
|
using NzbDrone.Core.DecisionEngine;
|
2013-02-24 20:18:48 +01:00
|
|
|
using NzbDrone.Core.Download;
|
2013-02-21 08:07:34 +01:00
|
|
|
using NzbDrone.Core.Indexers;
|
2013-01-11 01:35:33 +01:00
|
|
|
using NzbDrone.Core.Model;
|
2013-01-13 09:24:48 +01:00
|
|
|
using NzbDrone.Core.Model.Notification;
|
2013-03-07 04:45:36 +01:00
|
|
|
using NzbDrone.Core.ReferenceData;
|
|
|
|
using NzbDrone.Core.Tv;
|
2013-01-11 01:35:33 +01:00
|
|
|
|
2013-03-07 04:45:36 +01:00
|
|
|
namespace NzbDrone.Core.IndexerSearch
|
2013-01-11 01:35:33 +01:00
|
|
|
{
|
2013-03-07 05:34:56 +01:00
|
|
|
public class EpisodeSearch : IndexerSearchBase
|
2013-01-11 01:35:33 +01:00
|
|
|
{
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
2013-03-28 19:06:27 +01:00
|
|
|
public EpisodeSearch(IEpisodeService episodeService, IDownloadProvider downloadProvider, IIndexerService indexerService,
|
2013-03-07 04:45:36 +01:00
|
|
|
ISceneMappingService sceneMappingService, IDownloadDirector downloadDirector,
|
2013-02-26 03:20:42 +01:00
|
|
|
ISeriesRepository seriesRepository)
|
2013-03-07 02:51:47 +01:00
|
|
|
: base(seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingService,
|
|
|
|
downloadDirector)
|
|
|
|
{
|
2013-01-11 01:35:33 +01:00
|
|
|
}
|
|
|
|
|
2013-01-13 19:29:53 +01:00
|
|
|
public EpisodeSearch()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-07 04:45:36 +01:00
|
|
|
public override List<EpisodeParseResult> PerformSearch(Series series, List<Episode> episodes, ProgressNotification notification)
|
2013-01-11 01:35:33 +01:00
|
|
|
{
|
2013-01-13 09:24:48 +01:00
|
|
|
//Todo: Daily and Anime or separate them out?
|
|
|
|
//Todo: Epsiodes that use scene numbering
|
2013-01-11 01:35:33 +01:00
|
|
|
|
2013-03-07 04:45:36 +01:00
|
|
|
var episode = episodes.Single();
|
2013-01-11 01:35:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
var reports = new List<EpisodeParseResult>();
|
2013-01-13 09:24:48 +01:00
|
|
|
var title = GetSearchTitle(series);
|
|
|
|
|
2013-03-07 04:45:36 +01:00
|
|
|
var seasonNumber = episode.SeasonNumber;
|
|
|
|
var episodeNumber = episode.EpisodeNumber;
|
2013-01-13 09:24:48 +01:00
|
|
|
|
|
|
|
if (series.UseSceneNumbering)
|
|
|
|
{
|
2013-03-07 04:45:36 +01:00
|
|
|
if (episode.SceneSeasonNumber > 0 && episode.SceneEpisodeNumber > 0)
|
2013-01-13 09:24:48 +01:00
|
|
|
{
|
2013-03-07 04:45:36 +01:00
|
|
|
logger.Trace("Using Scene Numbering for: {0}", episode);
|
|
|
|
seasonNumber = episode.SceneSeasonNumber;
|
|
|
|
episodeNumber = episode.SceneEpisodeNumber;
|
2013-01-13 09:24:48 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-11 01:35:33 +01:00
|
|
|
|
2013-02-21 08:07:34 +01:00
|
|
|
Parallel.ForEach(_indexerService.GetEnabledIndexers(), indexer =>
|
2013-01-11 01:35:33 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-01-13 09:24:48 +01:00
|
|
|
reports.AddRange(indexer.FetchEpisode(title, seasonNumber, episodeNumber));
|
2013-01-11 01:35:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
logger.ErrorException(String.Format("An error has occurred while searching for {0}-S{1:00}E{2:00} from: {3}",
|
2013-03-07 04:45:36 +01:00
|
|
|
series.Title, episode.SeasonNumber, episode.EpisodeNumber, indexer.Name), e);
|
2013-01-11 01:35:33 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return reports;
|
|
|
|
}
|
|
|
|
|
2013-03-07 02:51:47 +01:00
|
|
|
public override bool IsEpisodeMatch(Series series, dynamic options, EpisodeParseResult episodeParseResult)
|
2013-01-11 01:35:33 +01:00
|
|
|
{
|
2013-03-07 02:51:47 +01:00
|
|
|
if (series.UseSceneNumbering && options.Episode.SeasonNumber > 0 && options.Episode.EpisodeNumber > 0)
|
2013-01-13 09:24:48 +01:00
|
|
|
{
|
|
|
|
if (options.Episode.SceneSeasonNumber != episodeParseResult.SeasonNumber)
|
|
|
|
{
|
|
|
|
logger.Trace("Season number does not match searched season number, skipping.");
|
2013-03-07 02:51:47 +01:00
|
|
|
return false;
|
2013-01-13 09:24:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!episodeParseResult.EpisodeNumbers.Contains(options.Episode.SceneEpisodeNumber))
|
|
|
|
{
|
|
|
|
logger.Trace("Episode number does not match searched episode number, skipping.");
|
2013-03-07 02:51:47 +01:00
|
|
|
return false;
|
2013-01-13 09:24:48 +01:00
|
|
|
}
|
|
|
|
|
2013-03-07 02:51:47 +01:00
|
|
|
return true;
|
2013-01-13 09:24:48 +01:00
|
|
|
}
|
|
|
|
|
2013-03-07 02:51:47 +01:00
|
|
|
if (options.Episode.SeasonNumber != episodeParseResult.SeasonNumber)
|
2013-01-13 09:24:48 +01:00
|
|
|
{
|
|
|
|
logger.Trace("Season number does not match searched season number, skipping.");
|
2013-03-07 02:51:47 +01:00
|
|
|
return false;
|
2013-01-13 09:24:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!episodeParseResult.EpisodeNumbers.Contains(options.Episode.EpisodeNumber))
|
|
|
|
{
|
|
|
|
logger.Trace("Episode number does not match searched episode number, skipping.");
|
2013-03-07 02:51:47 +01:00
|
|
|
return false;
|
2013-01-13 09:24:48 +01:00
|
|
|
}
|
|
|
|
|
2013-03-07 02:51:47 +01:00
|
|
|
return true;
|
2013-01-13 09:24:48 +01:00
|
|
|
}
|
|
|
|
|
2013-01-11 01:35:33 +01:00
|
|
|
}
|
|
|
|
}
|