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