2013-08-21 08:46:23 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using NzbDrone.Api.REST;
|
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
2013-08-26 07:14:55 +02:00
|
|
|
|
using NzbDrone.Api.Mapping;
|
2013-08-21 08:46:23 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.EpisodeFiles
|
|
|
|
|
{
|
|
|
|
|
public class EpisodeModule : NzbDroneRestModule<EpisodeFileResource>
|
|
|
|
|
{
|
|
|
|
|
private readonly IMediaFileService _mediaFileService;
|
|
|
|
|
|
|
|
|
|
public EpisodeModule(IMediaFileService mediaFileService)
|
|
|
|
|
: base("/episodefile")
|
|
|
|
|
{
|
|
|
|
|
_mediaFileService = mediaFileService;
|
2013-08-22 05:24:50 +02:00
|
|
|
|
GetResourceById = GetEpisodeFile;
|
2013-08-22 02:56:25 +02:00
|
|
|
|
GetResourceAll = GetEpisodeFiles;
|
2013-08-21 08:46:23 +02:00
|
|
|
|
UpdateResource = SetQuality;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-22 05:24:50 +02:00
|
|
|
|
private EpisodeFileResource GetEpisodeFile(int id)
|
|
|
|
|
{
|
2013-08-26 07:14:55 +02:00
|
|
|
|
return _mediaFileService.Get(id).InjectTo<EpisodeFileResource>();
|
2013-08-22 05:24:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-22 02:56:25 +02:00
|
|
|
|
private List<EpisodeFileResource> GetEpisodeFiles()
|
|
|
|
|
{
|
|
|
|
|
var seriesId = (int?)Request.Query.SeriesId;
|
|
|
|
|
|
|
|
|
|
if (seriesId == null)
|
|
|
|
|
{
|
|
|
|
|
throw new BadRequestException("seriesId is missing");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ToListResource(() => _mediaFileService.GetFilesBySeries(seriesId.Value));
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-26 07:14:55 +02:00
|
|
|
|
private void SetQuality(EpisodeFileResource episodeFileResource)
|
2013-08-21 08:46:23 +02:00
|
|
|
|
{
|
|
|
|
|
var episodeFile = _mediaFileService.Get(episodeFileResource.Id);
|
|
|
|
|
episodeFile.Quality = episodeFileResource.Quality;
|
|
|
|
|
_mediaFileService.Update(episodeFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|