Lidarr/NzbDrone.Core/IndexerSearch/DailyEpisodeSearch.cs

73 lines
2.5 KiB
C#
Raw Normal View History

2013-03-07 03:45:36 +00:00
using System;
2013-01-13 08:24:48 +00:00
using System.Collections.Generic;
2013-03-07 03:45:36 +00:00
using System.Linq;
2013-01-13 08:24:48 +00:00
using System.Threading.Tasks;
using NLog;
2013-03-07 03:45:36 +00:00
using NzbDrone.Common.EnsureThat;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download;
2013-02-21 07:07:34 +00:00
using NzbDrone.Core.Indexers;
2013-01-13 08:24:48 +00:00
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
2013-03-07 03:45:36 +00:00
using NzbDrone.Core.ReferenceData;
using NzbDrone.Core.Tv;
2013-01-13 08:24:48 +00:00
2013-03-07 03:45:36 +00:00
namespace NzbDrone.Core.IndexerSearch
2013-01-13 08:24:48 +00:00
{
public class DailyEpisodeSearch : IndexerSearchBase
2013-01-13 08:24:48 +00:00
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
2013-03-28 18:06:27 +00:00
public DailyEpisodeSearch(IEpisodeService episodeService, IDownloadProvider downloadProvider, IIndexerService indexerService,
2013-03-07 03:45:36 +00:00
ISceneMappingService sceneMappingService, IDownloadDirector downloadDirector,
2013-02-26 02:20:42 +00:00
ISeriesRepository seriesRepository)
2013-03-05 19:58:53 +00:00
: base(seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingService,
2013-03-07 01:51:47 +00:00
downloadDirector)
2013-02-19 06:56:02 +00:00
{
2013-01-13 08:24:48 +00:00
}
2013-01-13 18:29:53 +00:00
public DailyEpisodeSearch()
{
}
2013-03-07 03:45:36 +00:00
public override List<EpisodeParseResult> PerformSearch(Series series, List<Episode> episodes, ProgressNotification notification)
2013-01-13 08:24:48 +00:00
{
2013-03-07 03:45:36 +00:00
var episode = episodes.Single();
2013-01-13 08:24:48 +00:00
2013-03-07 03:45:36 +00:00
notification.CurrentMessage = "Looking for " + episode;
2013-01-13 08:24:48 +00:00
var reports = new List<EpisodeParseResult>();
var title = GetSearchTitle(series);
2013-02-21 07:07:34 +00:00
Parallel.ForEach(_indexerService.GetEnabledIndexers(), indexer =>
2013-01-13 08:24:48 +00:00
{
try
{
2013-03-07 03:45:36 +00:00
reports.AddRange(indexer.FetchDailyEpisode(title, episode.AirDate.Value));
2013-01-13 08:24:48 +00:00
}
catch (Exception e)
{
logger.ErrorException(String.Format("An error has occurred while searching for {0} - {1:yyyy-MM-dd} from: {2}",
2013-03-07 03:45:36 +00:00
series.Title, episode.AirDate, indexer.Name), e);
2013-01-13 08:24:48 +00:00
}
});
return reports;
}
2013-03-07 01:51:47 +00:00
public override bool IsEpisodeMatch(Series series, dynamic options, EpisodeParseResult episodeParseResult)
2013-01-13 08:24:48 +00:00
{
Episode episode = options.Episode;
if (!episodeParseResult.AirDate.HasValue || episodeParseResult.AirDate.Value != episode.AirDate.Value)
{
logger.Trace("Episode AirDate does not match searched episode number, skipping.");
2013-03-07 01:51:47 +00:00
return false;
2013-01-13 08:24:48 +00:00
}
2013-03-07 01:51:47 +00:00
return true;
2013-01-13 08:24:48 +00:00
}
}
}