1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-23 02:05:27 +02:00
Sonarr/NzbDrone.Core.Test/ProviderTests/SearchTests/TestSearch.cs

70 lines
2.8 KiB
C#
Raw Normal View History

2013-01-13 11:24:48 +03:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;
2013-02-21 10:07:34 +03:00
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Tv;
2013-01-13 11:24:48 +03:00
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
2013-02-19 05:19:38 +03:00
using NzbDrone.Core.DecisionEngine;
2013-01-13 11:24:48 +03: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-02-21 10:07:34 +03:00
IndexerService indexerService, SceneMappingProvider sceneMappingProvider,
2013-02-19 09:56:02 +03:00
AllowedDownloadSpecification allowedDownloadSpecification, SearchHistoryProvider searchHistoryProvider,ISeriesRepository seriesRepository)
2013-02-21 10:07:34 +03:00
: base(seriesService, seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingProvider,
2013-01-13 11:24:48 +03:00
allowedDownloadSpecification, searchHistoryProvider)
{
}
public override List<EpisodeParseResult> PerformSearch(Series series, dynamic options, Model.Notification.ProgressNotification notification)
2013-01-13 11:24:48 +03: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 10:07:34 +03:00
Parallel.ForEach(_indexerService.GetEnabledIndexers(), indexer =>
2013-01-13 11:24:48 +03: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 11:24:48 +03:00
{
return item;
}
protected override void FinalizeSearch(Series series, dynamic options, bool reportsFound, Model.Notification.ProgressNotification notification)
2013-01-13 11:24:48 +03:00
{
logger.Warn("Unable to find {0} in any of indexers.", series.Title);
}
}
}