2013-03-05 22:58:53 +03:00
|
|
|
using System.Collections.Generic;
|
2011-08-28 08:45:36 +03:00
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
2013-03-07 06:45:36 +03:00
|
|
|
using NzbDrone.Core.IndexerSearch;
|
2013-02-19 09:01:03 +03:00
|
|
|
using NzbDrone.Core.Tv;
|
2011-08-28 08:45:36 +03:00
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers
|
|
|
|
{
|
|
|
|
public class SearchProvider
|
|
|
|
{
|
2013-02-22 03:47:09 +03:00
|
|
|
private readonly IEpisodeService _episodeService;
|
2013-01-13 11:24:48 +03:00
|
|
|
private readonly PartialSeasonSearch _partialSeasonSearch;
|
2013-02-19 09:56:02 +03:00
|
|
|
private readonly ISeriesRepository _seriesRepository;
|
2011-08-28 08:45:36 +03:00
|
|
|
|
2012-11-23 03:38:38 +03:00
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
2011-08-28 08:45:36 +03:00
|
|
|
|
2013-03-05 22:58:53 +03:00
|
|
|
public SearchProvider(IEpisodeService episodeService, PartialSeasonSearch partialSeasonSearch, ISeriesRepository seriesRepository)
|
2011-08-28 08:45:36 +03:00
|
|
|
{
|
2013-02-20 05:05:15 +03:00
|
|
|
_episodeService = episodeService;
|
2013-01-13 11:24:48 +03:00
|
|
|
_partialSeasonSearch = partialSeasonSearch;
|
2013-02-19 09:56:02 +03:00
|
|
|
_seriesRepository = seriesRepository;
|
2011-08-28 08:45:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public SearchProvider()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-18 02:52:26 +03:00
|
|
|
public virtual List<int> SeasonSearch(ProgressNotification notification, int seriesId, int seasonNumber)
|
2011-08-28 08:45:36 +03:00
|
|
|
{
|
2013-02-19 09:56:02 +03:00
|
|
|
var series = _seriesRepository.Get(seriesId);
|
2011-08-28 08:45:36 +03:00
|
|
|
|
|
|
|
if (series == null)
|
|
|
|
{
|
2012-11-23 03:38:38 +03:00
|
|
|
logger.Error("Unable to find an series {0} in database", seriesId);
|
2012-05-18 02:52:26 +03:00
|
|
|
return new List<int>();
|
2012-11-16 19:39:54 +03:00
|
|
|
}
|
2011-08-28 08:45:36 +03:00
|
|
|
|
2013-03-24 07:16:00 +03:00
|
|
|
if (series.SeriesType == SeriesTypes.Daily)
|
2012-11-16 19:39:54 +03:00
|
|
|
{
|
2012-11-23 03:38:38 +03:00
|
|
|
logger.Trace("Daily series detected, skipping season search: {0}", series.Title);
|
2012-11-16 19:39:54 +03:00
|
|
|
return new List<int>();
|
|
|
|
}
|
|
|
|
|
2012-11-23 03:38:38 +03:00
|
|
|
logger.Debug("Getting episodes from database for series: {0} and season: {1}", seriesId, seasonNumber);
|
2013-02-20 05:05:15 +03:00
|
|
|
var episodes = _episodeService.GetEpisodesBySeason(seriesId, seasonNumber);
|
2012-11-16 19:39:54 +03:00
|
|
|
|
|
|
|
if (episodes == null || episodes.Count == 0)
|
|
|
|
{
|
2012-11-23 03:38:38 +03:00
|
|
|
logger.Warn("No episodes in database found for series: {0} and season: {1}.", seriesId, seasonNumber);
|
2012-05-18 02:52:26 +03:00
|
|
|
return new List<int>();
|
2012-11-16 19:39:54 +03:00
|
|
|
}
|
2011-11-26 09:13:47 +03:00
|
|
|
|
2013-01-13 11:24:48 +03:00
|
|
|
//Todo: Support full season searching
|
|
|
|
return new List<int>();
|
2011-08-28 08:45:36 +03:00
|
|
|
}
|
|
|
|
|
2012-04-23 09:31:11 +03:00
|
|
|
public virtual List<int> PartialSeasonSearch(ProgressNotification notification, int seriesId, int seasonNumber)
|
2011-08-28 08:45:36 +03:00
|
|
|
{
|
2013-02-19 09:56:02 +03:00
|
|
|
var series = _seriesRepository.Get(seriesId);
|
2011-11-18 05:36:53 +03:00
|
|
|
|
|
|
|
if (series == null)
|
2011-08-28 08:45:36 +03:00
|
|
|
{
|
2012-11-23 03:38:38 +03:00
|
|
|
logger.Error("Unable to find an series {0} in database", seriesId);
|
2012-04-23 09:31:11 +03:00
|
|
|
return new List<int>();
|
2011-11-18 05:36:53 +03:00
|
|
|
}
|
2011-11-17 09:32:44 +03:00
|
|
|
|
2013-03-24 07:16:00 +03:00
|
|
|
if (series.SeriesType == SeriesTypes.Daily)
|
2012-11-16 19:39:54 +03:00
|
|
|
{
|
2012-11-23 03:38:38 +03:00
|
|
|
logger.Trace("Daily series detected, skipping season search: {0}", series.Title);
|
2012-04-23 09:31:11 +03:00
|
|
|
return new List<int>();
|
2012-11-16 19:39:54 +03:00
|
|
|
}
|
2011-11-26 09:13:47 +03:00
|
|
|
|
2013-02-20 05:05:15 +03:00
|
|
|
var episodes = _episodeService.GetEpisodesBySeason(seriesId, seasonNumber);
|
2012-11-16 19:39:54 +03:00
|
|
|
|
2013-01-13 11:24:48 +03:00
|
|
|
if (episodes == null || episodes.Count == 0)
|
2012-11-16 19:39:54 +03:00
|
|
|
{
|
2013-01-13 11:24:48 +03:00
|
|
|
logger.Warn("No episodes in database found for series: {0} Season: {1}.", seriesId, seasonNumber);
|
2012-04-23 09:31:11 +03:00
|
|
|
return new List<int>();
|
2012-12-20 19:31:05 +03:00
|
|
|
}
|
2012-11-16 19:39:54 +03:00
|
|
|
|
2013-03-05 22:58:53 +03:00
|
|
|
return _partialSeasonSearch.Search(series, new { SeasonNumber = seasonNumber, Episodes = episodes }, notification);
|
2012-11-16 19:39:54 +03:00
|
|
|
}
|
2011-08-28 08:45:36 +03:00
|
|
|
}
|
|
|
|
}
|