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