Sonarr/NzbDrone.Core/Providers/SearchProvider.cs

96 lines
3.3 KiB
C#
Raw Normal View History

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NLog;
using NzbDrone.Core.Tv;
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.Providers.Search;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Search;
namespace NzbDrone.Core.Providers
{
public class SearchProvider
{
private readonly SeriesProvider _seriesProvider;
2013-01-13 08:24:48 +00:00
private readonly EpisodeProvider _episodeProvider;
private readonly PartialSeasonSearch _partialSeasonSearch;
2013-02-19 06:56:02 +00:00
private readonly ISeriesRepository _seriesRepository;
2012-11-23 00:38:38 +00:00
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
2013-01-13 08:24:48 +00:00
public SearchProvider(SeriesProvider seriesProvider, EpisodeProvider episodeProvider,
2013-02-19 06:56:02 +00:00
PartialSeasonSearch partialSeasonSearch,ISeriesRepository seriesRepository)
{
_seriesProvider = seriesProvider;
2013-01-13 08:24:48 +00:00
_episodeProvider = episodeProvider;
_partialSeasonSearch = partialSeasonSearch;
2013-02-19 06:56:02 +00:00
_seriesRepository = seriesRepository;
}
public SearchProvider()
{
}
public virtual List<int> SeasonSearch(ProgressNotification notification, int seriesId, int seasonNumber)
{
2013-02-19 06:56:02 +00:00
var series = _seriesRepository.Get(seriesId);
if (series == null)
{
2012-11-23 00:38:38 +00:00
logger.Error("Unable to find an series {0} in database", seriesId);
return new List<int>();
}
if (series.IsDaily)
{
2012-11-23 00:38:38 +00:00
logger.Trace("Daily series detected, skipping season search: {0}", series.Title);
return new List<int>();
}
2012-11-23 00:38:38 +00:00
logger.Debug("Getting episodes from database for series: {0} and season: {1}", seriesId, seasonNumber);
var episodes = _episodeProvider.GetEpisodesBySeason(seriesId, seasonNumber);
if (episodes == null || episodes.Count == 0)
{
2012-11-23 00:38:38 +00:00
logger.Warn("No episodes in database found for series: {0} and season: {1}.", seriesId, seasonNumber);
return new List<int>();
}
2013-01-13 08:24:48 +00:00
//Todo: Support full season searching
return new List<int>();
}
public virtual List<int> PartialSeasonSearch(ProgressNotification notification, int seriesId, int seasonNumber)
{
2013-02-19 06:56:02 +00:00
var series = _seriesRepository.Get(seriesId);
if (series == null)
{
2012-11-23 00:38:38 +00:00
logger.Error("Unable to find an series {0} in database", seriesId);
return new List<int>();
}
if (series.IsDaily)
{
2012-11-23 00:38:38 +00:00
logger.Trace("Daily series detected, skipping season search: {0}", series.Title);
return new List<int>();
}
var episodes = _episodeProvider.GetEpisodesBySeason(seriesId, seasonNumber);
2013-01-13 08:24:48 +00:00
if (episodes == null || episodes.Count == 0)
{
2013-01-13 08:24:48 +00:00
logger.Warn("No episodes in database found for series: {0} Season: {1}.", seriesId, seasonNumber);
return new List<int>();
}
2013-01-13 08:24:48 +00:00
return _partialSeasonSearch.Search(series, new {SeasonNumber = seasonNumber, Episodes = episodes}, notification);
}
}
}