sonarr-repo-only/src/NzbDrone.Api/EpisodeFiles/EpisodeFileResource.cs

75 lines
2.6 KiB
C#
Raw Normal View History

using System;
using System.IO;
2017-02-11 06:46:39 +00:00
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.MediaFiles;
using Sonarr.Http.REST;
using NzbDrone.Core.Qualities;
2015-07-12 16:44:33 +00:00
using NzbDrone.Core.Languages;
2013-08-21 06:46:23 +00:00
namespace NzbDrone.Api.EpisodeFiles
{
public class EpisodeFileResource : RestResource
{
public int SeriesId { get; set; }
public int SeasonNumber { get; set; }
public string RelativePath { get; set; }
public string Path { get; set; }
public long Size { get; set; }
2013-08-21 06:46:23 +00:00
public DateTime DateAdded { get; set; }
public string SceneName { get; set; }
2013-08-21 06:46:23 +00:00
public QualityModel Quality { get; set; }
2015-07-12 16:44:33 +00:00
public Language Language { get; set; }
public MediaInfoResource MediaInfo { get; set; }
public string OriginalFilePath { get; set; }
public bool QualityCutoffNotMet { get; set; }
2013-08-21 06:46:23 +00:00
}
public static class EpisodeFileResourceMapper
{
2017-02-11 06:46:39 +00:00
private static EpisodeFileResource ToResource(this EpisodeFile model)
{
if (model == null) return null;
return new EpisodeFileResource
{
Id = model.Id,
SeriesId = model.SeriesId,
SeasonNumber = model.SeasonNumber,
RelativePath = model.RelativePath,
//Path
Size = model.Size,
DateAdded = model.DateAdded,
SceneName = model.SceneName,
Quality = model.Quality,
MediaInfo = model.MediaInfo.ToResource(model.SceneName),
OriginalFilePath = model.OriginalFilePath
};
}
2015-07-12 16:44:33 +00:00
public static EpisodeFileResource ToResource(this EpisodeFile model, Core.Tv.Series series, IUpgradableSpecification upgradableSpecification)
{
if (model == null) return null;
return new EpisodeFileResource
{
Id = model.Id,
SeriesId = model.SeriesId,
SeasonNumber = model.SeasonNumber,
RelativePath = model.RelativePath,
Path = Path.Combine(series.Path, model.RelativePath),
Size = model.Size,
DateAdded = model.DateAdded,
SceneName = model.SceneName,
Quality = model.Quality,
2015-07-12 16:44:33 +00:00
Language = model.Language,
2017-02-11 06:46:39 +00:00
QualityCutoffNotMet = upgradableSpecification.QualityCutoffNotMet(series.Profile.Value, model.Quality),
MediaInfo = model.MediaInfo.ToResource(model.SceneName),
OriginalFilePath = model.OriginalFilePath
};
}
}
2013-08-21 06:46:23 +00:00
}