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;
|
2013-02-19 09:01:03 +03:00
|
|
|
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();
|
|
|
|
|
2013-02-22 03:47:09 +03:00
|
|
|
public TestSearch(ISeriesService seriesService, IEpisodeService episodeService, DownloadProvider downloadProvider,
|
2013-02-23 02:55:43 +03:00
|
|
|
IIndexerService 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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-19 09:01:03 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-19 09:01:03 +03:00
|
|
|
public override SearchHistoryItem CheckReport(Series series, dynamic options, EpisodeParseResult episodeParseResult, Repository.Search.SearchHistoryItem item)
|
2013-01-13 11:24:48 +03:00
|
|
|
{
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2013-02-19 09:01:03 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|