public static CachedSeriesInfo GetSeriesDetails([NotNull] SeriesSpecifier ss) { JObject results = ss.TvMazeSeriesId > 0 ? GetSeriesDetails(ss.TvMazeSeriesId) : GetSeriesDetails(GetSeriesIdFromOtherCodes(ss.TvdbSeriesId, ss.ImdbCode)); CachedSeriesInfo downloadedSi = GenerateSeriesInfo(results); JToken jToken = GetChild(results, "_embedded"); foreach (string name in GetChild(jToken, "akas").Select(akaJson => (string)akaJson["name"]).Where(name => name != null)) { downloadedSi.AddAlias(name); } List <string> writers = GetWriters(GetChild(jToken, "crew")); List <string> directors = GetDirectors(GetChild(jToken, "crew")); foreach (JToken epJson in GetChild(jToken, "episodes")) { downloadedSi.AddEpisode(GenerateEpisode(ss.TvMazeSeriesId, writers, directors, (JObject)epJson, downloadedSi)); } foreach (JToken jsonSeason in GetChild(jToken, "seasons")) { downloadedSi.AddSeason(GenerateSeason(ss.TvMazeSeriesId, jsonSeason)); JToken imageNode = GetChild(jsonSeason, "image"); if (imageNode.HasValues) { string child = (string)GetChild(imageNode, "original"); if (child != null) { downloadedSi.AddOrUpdateBanner(GenerateBanner(ss.TvMazeSeriesId, (int)jsonSeason["number"], child)); } } } foreach (JToken imageJson in GetChild(jToken, "images").Where(imageJson => (string)imageJson["type"] == "background")) { downloadedSi.AddOrUpdateBanner(GenerateBanner(ss.TvMazeSeriesId, imageJson)); } downloadedSi.BannersLoaded = true; downloadedSi.ClearActors(); foreach (JToken jsonActor in GetChild(jToken, "cast")) { downloadedSi.AddActor(GenerateActor(ss.TvMazeSeriesId, jsonActor)); } return(downloadedSi); }
public void AddOrUpdateEpisode(Episode e, CachedSeriesInfo si) { lock (SERIES_LOCK) { if (!Series.ContainsKey(e.SeriesId)) { throw new SourceConsistencyException( $"Can't find the cachedSeries to add the episode to. EpId:{e.EpisodeId} SeriesId:{e.SeriesId} {e.Name}", TVDoc.ProviderType.TVmaze); } CachedSeriesInfo ser = Series[e.SeriesId]; ser.AddEpisode(e); } }
internal CachedSeriesInfo DownloadSeriesNow(SeriesSpecifier ss, bool showErrorMsgBox) { int id = ss.TmdbId > 0 ? ss.TmdbId : GetSeriesIdFromOtherCodes(ss) ?? 0; TvShow?downloadedSeries = Client.GetTvShowAsync(id, TvShowMethods.ExternalIds | TvShowMethods.Images | TvShowMethods.AlternativeTitles | TvShowMethods.ContentRatings | TvShowMethods.Changes | TvShowMethods.Videos | TvShowMethods.Credits).Result; if (downloadedSeries is null) { throw new ShowNotFoundException(id, "TMDB no longer has this show", TVDoc.ProviderType.TMDB, TVDoc.ProviderType.TMDB); } CachedSeriesInfo m = new CachedSeriesInfo { Imdb = downloadedSeries.ExternalIds.ImdbId, TmdbCode = downloadedSeries.Id, TvdbCode = downloadedSeries.ExternalIds.TvdbId.ToInt(ss.TvdbSeriesId), TvMazeCode = downloadedSeries.ExternalIds.TvrageId.ToInt(ss.TvMazeSeriesId), Name = downloadedSeries.Name, //Runtime = downloadedSeries.Runtime.ToString(), FirstAired = downloadedSeries.FirstAirDate, Genres = downloadedSeries.Genres.Select(genre => genre.Name).ToList(), Overview = downloadedSeries.Overview, Network = downloadedSeries.ProductionCompanies.FirstOrDefault()?.Name, Status = MapStatus(downloadedSeries.Status), ShowLanguage = downloadedSeries.OriginalLanguage, SiteRating = (float)downloadedSeries.VoteAverage, SiteRatingVotes = downloadedSeries.VoteCount, PosterUrl = ImageURL(downloadedSeries.PosterPath), SrvLastUpdated = DateTime.UtcNow.Date.ToUnixTime(), //CollectionName = downloadedSeries.BelongsToCollection?.Name, //CollectionId = downloadedSeries.BelongsToCollection?.Id, //TagLine = downloadedSeries., TwitterId = downloadedSeries.ExternalIds.TwitterId, InstagramId = downloadedSeries.ExternalIds.InstagramId, FacebookId = downloadedSeries.ExternalIds.InstagramId, //FanartUrl = ImageURL(downloadedSeries.BackdropPath), //ContentRating = GetCertification(downloadedSeries, "AU") ?? GetCertification(downloadedSeries, "US") ?? string.Empty,// todo allow user to choose OfficialUrl = downloadedSeries.Homepage, Type = downloadedSeries.Type, //TrailerUrl = GetYouTubeUrl(downloadedSeries), Dirty = false, }; foreach (var s in downloadedSeries.AlternativeTitles.Results.Select(title => title.Title)) { m.AddAlias(s); } foreach (var s in downloadedSeries.Credits.Cast) { m.AddActor(new Actor(s.Id, s.ProfilePath, s.Name, s.Character, 0, s.Order)); } foreach (var s in downloadedSeries.Credits.Crew) { m.AddCrew(new Crew(s.Id, s.ProfilePath, s.Name, s.Job, s.Department, s.CreditId)); } foreach (int snum in Enumerable.Range(1, downloadedSeries.NumberOfSeasons)) { var downloadedSeason = Client.GetTvSeasonAsync(downloadedSeries.Id, snum, TvSeasonMethods.Images).Result; // TODO add language Season newSeason = new Season(downloadedSeason.Id ?? 0, snum, downloadedSeason.Name, downloadedSeason.Overview, String.Empty, downloadedSeason.PosterPath, downloadedSeries.Id); m.AddSeason(newSeason); foreach (var downloadedEpisode in downloadedSeason.Episodes) { Episode newEpisode = new Episode(downloadedSeries.Id, m) { Name = downloadedEpisode.Name, Overview = downloadedEpisode.Overview, AirTime = downloadedEpisode.AirDate, AirStamp = downloadedEpisode.AirDate, FirstAired = downloadedEpisode.AirDate, AiredEpNum = downloadedEpisode.EpisodeNumber, AiredSeasonNumber = downloadedEpisode.SeasonNumber, ProductionCode = downloadedEpisode.ProductionCode, EpisodeId = downloadedEpisode.Id, SiteRatingCount = downloadedEpisode.VoteCount, EpisodeRating = downloadedEpisode.VoteAverage.ToString(System.Globalization.CultureInfo.InvariantCulture), SeasonId = newSeason.SeasonId, Filename = ImageURL(downloadedEpisode.StillPath, "original") }; //todo - add cast and crew m.AddEpisode(newEpisode); } if (downloadedSeason.Images != null) { foreach (var image in downloadedSeason.Images.Posters) { Banner newBanner = new Banner(downloadedSeries.Id) { BannerPath = image.FilePath, BannerType = "fanart", Rating = image.VoteAverage, RatingCount = image.VoteCount }; m.AddOrUpdateBanner(newBanner); } } } m.BannersLoaded = true; File(m); return(m); }