2013-11-20 00:42:17 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-05-31 00:12:20 +00:00
|
|
|
|
using NzbDrone.Api.REST;
|
2013-09-30 15:09:47 +00:00
|
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
2013-03-02 19:13:23 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2014-08-18 22:24:44 +00:00
|
|
|
|
using NzbDrone.Api.Mapping;
|
|
|
|
|
using NzbDrone.Core.DecisionEngine;
|
2013-03-02 19:13:23 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Episodes
|
|
|
|
|
{
|
2014-08-18 22:24:44 +00:00
|
|
|
|
public class EpisodeModule : EpisodeModuleWithSignalR
|
2013-03-02 19:13:23 +00:00
|
|
|
|
{
|
2014-08-18 22:24:44 +00:00
|
|
|
|
private readonly ISeriesService _seriesService;
|
2013-04-01 06:22:16 +00:00
|
|
|
|
private readonly IEpisodeService _episodeService;
|
2014-08-18 22:24:44 +00:00
|
|
|
|
private readonly IQualityUpgradableSpecification _qualityUpgradableSpecification;
|
2013-03-02 19:13:23 +00:00
|
|
|
|
|
2014-08-18 22:24:44 +00:00
|
|
|
|
public EpisodeModule(ICommandExecutor commandExecutor, ISeriesService seriesService, IEpisodeService episodeService, IQualityUpgradableSpecification qualityUpgradableSpecification)
|
2014-06-28 16:45:50 +00:00
|
|
|
|
: base(episodeService, commandExecutor)
|
2013-03-02 19:13:23 +00:00
|
|
|
|
{
|
2014-08-18 22:24:44 +00:00
|
|
|
|
_seriesService = seriesService;
|
2013-03-02 19:13:23 +00:00
|
|
|
|
_episodeService = episodeService;
|
2014-08-18 22:24:44 +00:00
|
|
|
|
_qualityUpgradableSpecification = qualityUpgradableSpecification;
|
2013-05-31 00:12:20 +00:00
|
|
|
|
|
|
|
|
|
GetResourceAll = GetEpisodes;
|
2013-07-09 15:41:42 +00:00
|
|
|
|
UpdateResource = SetMonitored;
|
2013-03-02 19:13:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-31 00:12:20 +00:00
|
|
|
|
private List<EpisodeResource> GetEpisodes()
|
2013-03-02 19:13:23 +00:00
|
|
|
|
{
|
2013-05-31 00:12:20 +00:00
|
|
|
|
var seriesId = (int?)Request.Query.SeriesId;
|
|
|
|
|
|
|
|
|
|
if (seriesId == null)
|
|
|
|
|
{
|
|
|
|
|
throw new BadRequestException("seriesId is missing");
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-18 22:24:44 +00:00
|
|
|
|
var series = _seriesService.GetSeries(seriesId.Value);
|
|
|
|
|
|
|
|
|
|
var resources = new List<EpisodeResource>();
|
|
|
|
|
foreach (var episode in _episodeService.GetEpisodeBySeries(seriesId.Value))
|
|
|
|
|
{
|
|
|
|
|
var resource = episode.InjectTo<EpisodeResource>();
|
|
|
|
|
if (episode.EpisodeFile.IsLoaded)
|
|
|
|
|
{
|
|
|
|
|
resource.EpisodeFile.QualityCutoffNotMet = _qualityUpgradableSpecification.CutoffNotMet(series.Profile.Value, episode.EpisodeFile.Value.Quality);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resources.Add(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resources;
|
2013-03-02 19:13:23 +00:00
|
|
|
|
}
|
2013-07-09 15:41:42 +00:00
|
|
|
|
|
2013-08-26 05:14:55 +00:00
|
|
|
|
private void SetMonitored(EpisodeResource episodeResource)
|
2013-07-09 15:41:42 +00:00
|
|
|
|
{
|
|
|
|
|
_episodeService.SetEpisodeMonitored(episodeResource.Id, episodeResource.Monitored);
|
|
|
|
|
}
|
2013-03-02 19:13:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|