Sonarr/NzbDrone.Core.Test/ProviderTests/SearchTests/TestSearch.cs

72 lines
2.8 KiB
C#
Raw Normal View History

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;
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;
using NzbDrone.Core.Tv;
2013-01-13 08:24:48 +00:00
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
2013-02-19 02:19:38 +00:00
using NzbDrone.Core.DecisionEngine;
2013-01-13 08:24:48 +00:00
using NzbDrone.Core.Providers.Search;
using NzbDrone.Core.Repository.Search;
namespace NzbDrone.Core.Test.ProviderTests.SearchTests
{
public class TestSearch : SearchBase
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public TestSearch(ISeriesService seriesService, IEpisodeService episodeService, DownloadProvider downloadProvider,
2013-03-02 18:25:39 +00:00
IIndexerService indexerService, SceneMappingService sceneMappingService,
2013-02-26 02:20:42 +00:00
AllowedDownloadSpecification allowedDownloadSpecification, 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-01-13 08:24:48 +00:00
{
}
public override List<EpisodeParseResult> PerformSearch(Series series, dynamic options, Model.Notification.ProgressNotification notification)
2013-01-13 08:24:48 +00:00
{
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;
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.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.SeasonNumber, options.EpisodeNumber, indexer.Name), e);
}
});
return reports;
}
public override SearchHistoryItem CheckReport(Series series, dynamic options, EpisodeParseResult episodeParseResult, Repository.Search.SearchHistoryItem item)
2013-01-13 08:24:48 +00:00
{
return item;
}
protected override void FinalizeSearch(Series series, dynamic options, bool reportsFound, Model.Notification.ProgressNotification notification)
2013-01-13 08:24:48 +00:00
{
logger.Warn("Unable to find {0} in any of indexers.", series.Title);
}
}
}