2013-01-13 08:24:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using NLog;
|
2013-02-24 19:18:48 +00:00
|
|
|
|
using NzbDrone.Core.Download;
|
2013-02-21 07:07:34 +00:00
|
|
|
|
using NzbDrone.Core.Indexers;
|
2013-03-02 18:25:39 +00:00
|
|
|
|
using NzbDrone.Core.ReferenceData;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2013-01-13 08:24:48 +00:00
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
2013-02-19 02:19:38 +00:00
|
|
|
|
using NzbDrone.Core.DecisionEngine;
|
2013-01-13 08:24:48 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Repository.Search;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers.Search
|
|
|
|
|
{
|
|
|
|
|
public class DailyEpisodeSearch : SearchBase
|
|
|
|
|
{
|
2013-02-19 06:56:02 +00:00
|
|
|
|
private readonly ISeriesRepository _seriesRepository;
|
2013-01-13 08:24:48 +00:00
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
public DailyEpisodeSearch(ISeriesService seriesService, IEpisodeService episodeService, DownloadProvider downloadProvider, IIndexerService indexerService,
|
2013-03-02 18:25:39 +00:00
|
|
|
|
SceneMappingService sceneMappingService, AllowedDownloadSpecification allowedDownloadSpecification,
|
2013-02-26 02:20:42 +00:00
|
|
|
|
ISeriesRepository seriesRepository)
|
2013-03-02 18:25:39 +00:00
|
|
|
|
: base(seriesService, seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingService,
|
2013-02-26 02:20:42 +00:00
|
|
|
|
allowedDownloadSpecification)
|
2013-02-19 06:56:02 +00:00
|
|
|
|
{
|
|
|
|
|
_seriesRepository = seriesRepository;
|
2013-01-13 08:24:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-13 18:29:53 +00:00
|
|
|
|
public DailyEpisodeSearch()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-13 08:24:48 +00:00
|
|
|
|
public override List<EpisodeParseResult> PerformSearch(Series series, dynamic options, ProgressNotification notification)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
2013-02-21 07:07:34 +00:00
|
|
|
|
Parallel.ForEach(_indexerService.GetEnabledIndexers(), indexer =>
|
2013-01-13 08:24:48 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
reports.AddRange(indexer.FetchDailyEpisode(title, options.Episode.AirDate));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
logger.ErrorException(String.Format("An error has occurred while searching for {0} - {1:yyyy-MM-dd} from: {2}",
|
|
|
|
|
series.Title, options.Episode.AirDate, indexer.Name), e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return reports;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override SearchHistoryItem CheckReport(Series series, dynamic options, EpisodeParseResult episodeParseResult,
|
|
|
|
|
SearchHistoryItem item)
|
|
|
|
|
{
|
|
|
|
|
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.");
|
|
|
|
|
item.SearchError = ReportRejectionType.WrongEpisode;
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void FinalizeSearch(Series series, dynamic options, Boolean reportsFound, ProgressNotification notification)
|
|
|
|
|
{
|
|
|
|
|
logger.Warn("Unable to find {0} in any of indexers.", options.Episode);
|
|
|
|
|
|
2013-01-17 07:29:43 +00:00
|
|
|
|
notification.CurrentMessage = reportsFound ? String.Format("Sorry, couldn't find {0}, that matches your preferences.", options.Episode.AirDate)
|
2013-01-13 08:24:48 +00:00
|
|
|
|
: String.Format("Sorry, couldn't find {0} in any of indexers.", options.Episode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|