1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-30 20:05:41 +00:00
Radarr/NzbDrone.Core/IndexerSearch/DailyEpisodeSearch.cs
2013-03-31 19:43:58 -07:00

74 lines
No EOL
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NLog;
using NzbDrone.Common.EnsureThat;
using NzbDrone.Core.DataAugmentation;
using NzbDrone.Core.DataAugmentation.Scene;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.IndexerSearch
{
public class DailyEpisodeSearch : IndexerSearchBase
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public DailyEpisodeSearch(IEpisodeService episodeService, IDownloadProvider downloadProvider, IIndexerService indexerService,
ISceneMappingService sceneMappingService, IDownloadDirector downloadDirector,
ISeriesRepository seriesRepository)
: base(seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingService,
downloadDirector)
{
}
public DailyEpisodeSearch()
{
}
public override List<EpisodeParseResult> PerformSearch(Series series, List<Episode> episodes, ProgressNotification notification)
{
var episode = episodes.Single();
notification.CurrentMessage = "Looking for " + episode;
var reports = new List<EpisodeParseResult>();
var title = GetSearchTitle(series);
Parallel.ForEach(_indexerService.GetEnabledIndexers(), indexer =>
{
try
{
reports.AddRange(indexer.FetchDailyEpisode(title, episode.AirDate.Value));
}
catch (Exception e)
{
logger.ErrorException(String.Format("An error has occurred while searching for {0} - {1:yyyy-MM-dd} from: {2}",
series.Title, episode.AirDate, indexer.Name), e);
}
});
return reports;
}
public override bool IsEpisodeMatch(Series series, dynamic options, EpisodeParseResult episodeParseResult)
{
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.");
return false;
}
return true;
}
}
}