|
|
|
@ -0,0 +1,193 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
|
using NzbDrone.Common.Http;
|
|
|
|
|
using NzbDrone.Core.MediaCover;
|
|
|
|
|
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
|
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
{
|
|
|
|
|
public class SkyHookProxy : IProvideSeriesInfo
|
|
|
|
|
{
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
private readonly IHttpClient _httpClient;
|
|
|
|
|
private readonly HttpRequestBuilder _requestBuilder;
|
|
|
|
|
|
|
|
|
|
public SkyHookProxy(Logger logger, IHttpClient httpClient)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_httpClient = httpClient;
|
|
|
|
|
|
|
|
|
|
_requestBuilder = new HttpRequestBuilder("http://skyhook.sonarr.tv/v1/tvdb/shows/en/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Tuple<Series, List<Episode>> GetSeriesInfo(int tvdbSeriesId)
|
|
|
|
|
{
|
|
|
|
|
var httpRequest = _requestBuilder.Build(tvdbSeriesId.ToString());
|
|
|
|
|
var httpResponse = _httpClient.Get<ShowResource>(httpRequest);
|
|
|
|
|
var episodes = httpResponse.Resource.Episodes.Select(MapEpisode);
|
|
|
|
|
var series = MapSeries(httpResponse.Resource);
|
|
|
|
|
|
|
|
|
|
return new Tuple<Series, List<Episode>>(series, episodes.ToList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Series MapSeries(ShowResource show)
|
|
|
|
|
{
|
|
|
|
|
var series = new Series();
|
|
|
|
|
series.TvdbId = show.TvdbId;
|
|
|
|
|
|
|
|
|
|
if (show.TvRageId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
series.TvRageId = show.TvRageId.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
series.ImdbId = show.ImdbId;
|
|
|
|
|
series.Title = show.Title;
|
|
|
|
|
series.CleanTitle = Parser.Parser.CleanSeriesTitle(show.Title);
|
|
|
|
|
series.SortTitle = SeriesTitleNormalizer.Normalize(show.Title, show.TvdbId);
|
|
|
|
|
|
|
|
|
|
if (show.FirstAired != null)
|
|
|
|
|
{
|
|
|
|
|
series.FirstAired = DateTime.Parse(show.FirstAired).ToUniversalTime();
|
|
|
|
|
series.Year = series.FirstAired.Value.Year;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
series.Overview = show.Overview;
|
|
|
|
|
|
|
|
|
|
if (show.Runtime != null)
|
|
|
|
|
{
|
|
|
|
|
series.Runtime = show.Runtime.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
series.Network = show.Network;
|
|
|
|
|
|
|
|
|
|
if (show.TimeOfDay != null)
|
|
|
|
|
{
|
|
|
|
|
series.AirTime = string.Format("{0:00}:{1:00}", show.TimeOfDay.Hours, show.TimeOfDay.Minutes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
series.TitleSlug = show.Slug;
|
|
|
|
|
series.Status = MapSeriesStatus(show.Status);
|
|
|
|
|
series.Ratings = MapRatings(show.Rating);
|
|
|
|
|
series.Genres = show.Genres;
|
|
|
|
|
|
|
|
|
|
if (show.ContentRating.IsNotNullOrWhiteSpace())
|
|
|
|
|
{
|
|
|
|
|
series.Certification = show.ContentRating.ToUpper();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
series.Actors = show.Actors.Select(MapActors).ToList();
|
|
|
|
|
series.Seasons = show.Seasons.Select(MapSeason).ToList();
|
|
|
|
|
series.Images = show.Images.Select(MapImage).ToList();
|
|
|
|
|
|
|
|
|
|
return series;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Actor MapActors(ActorResource arg)
|
|
|
|
|
{
|
|
|
|
|
var newActor = new Actor
|
|
|
|
|
{
|
|
|
|
|
Name = arg.Name,
|
|
|
|
|
Character = arg.Character,
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (arg.Image != null)
|
|
|
|
|
{
|
|
|
|
|
newActor.Images = new List<MediaCover.MediaCover>
|
|
|
|
|
{
|
|
|
|
|
new MediaCover.MediaCover(MediaCoverTypes.Headshot, arg.Image)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newActor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Episode MapEpisode(EpisodeResource oracleEpisode)
|
|
|
|
|
{
|
|
|
|
|
var episode = new Episode();
|
|
|
|
|
episode.Overview = oracleEpisode.Overview;
|
|
|
|
|
episode.SeasonNumber = oracleEpisode.SeasonNumber;
|
|
|
|
|
episode.EpisodeNumber = oracleEpisode.EpisodeNumber;
|
|
|
|
|
episode.AbsoluteEpisodeNumber = oracleEpisode.AbsoluteEpisodeNumber;
|
|
|
|
|
episode.Title = oracleEpisode.Title;
|
|
|
|
|
|
|
|
|
|
episode.AirDate = oracleEpisode.AirDate;
|
|
|
|
|
episode.AirDateUtc = oracleEpisode.AirDateUtc;
|
|
|
|
|
|
|
|
|
|
if (oracleEpisode.Rating != null)
|
|
|
|
|
{
|
|
|
|
|
episode.Ratings = MapRatings(oracleEpisode.Rating);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Don't include series fanart images as episode screenshot
|
|
|
|
|
if (oracleEpisode.Image != null)
|
|
|
|
|
{
|
|
|
|
|
episode.Images.Add(new MediaCover.MediaCover(MediaCoverTypes.Screenshot, oracleEpisode.Image));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return episode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Season MapSeason(SeasonResource seasonResource)
|
|
|
|
|
{
|
|
|
|
|
return new Season
|
|
|
|
|
{
|
|
|
|
|
SeasonNumber = seasonResource.SeasonNumber,
|
|
|
|
|
Images = seasonResource.Images.Select(MapImage).ToList()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static SeriesStatusType MapSeriesStatus(string status)
|
|
|
|
|
{
|
|
|
|
|
if (status.Equals("ended", StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return SeriesStatusType.Ended;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SeriesStatusType.Continuing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Ratings MapRatings(RatingResource rating)
|
|
|
|
|
{
|
|
|
|
|
if (rating == null)
|
|
|
|
|
{
|
|
|
|
|
return new Ratings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Ratings
|
|
|
|
|
{
|
|
|
|
|
Votes = rating.Count,
|
|
|
|
|
Value = rating.Value
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static MediaCover.MediaCover MapImage(ImageResource arg)
|
|
|
|
|
{
|
|
|
|
|
return new MediaCover.MediaCover
|
|
|
|
|
{
|
|
|
|
|
Url = arg.Url,
|
|
|
|
|
CoverType = MapCoverType(arg.CoverType)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static MediaCoverTypes MapCoverType(string coverType)
|
|
|
|
|
{
|
|
|
|
|
switch (coverType.ToLower())
|
|
|
|
|
{
|
|
|
|
|
case "poster":
|
|
|
|
|
return MediaCoverTypes.Poster;
|
|
|
|
|
case "banner":
|
|
|
|
|
return MediaCoverTypes.Banner;
|
|
|
|
|
case "fanart":
|
|
|
|
|
return MediaCoverTypes.Fanart;
|
|
|
|
|
default:
|
|
|
|
|
return MediaCoverTypes.Unknown;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|