public ShowInformation GetShowInformation(object show, bool withImages, bool withPreviousNextEp) { if (!(show is int)) { throw new ArgumentException(); } if (client?.Config == null) { return(null); } var showinfo = client.GetTvShow((int)show, withImages?TvShowMethods.Images:TvShowMethods.Undefined); if (showinfo?.Name == null) { return(null); } var si = new ShowInformation { Status = showinfo.Status, PreviousEpisodeDate = showinfo.LastAirDate, NumberEpisodes = showinfo.NumberOfEpisodes, NumberSeasons = showinfo.NumberOfSeasons, ProviderHomepage = "https://www.themoviedb.org/tv/" + ((int)show), PublisherHomepage = (showinfo.Homepage == null || showinfo.Homepage.Trim().Length == 0) ?null:showinfo.Homepage, Title = showinfo.OriginalName, Backdrop = String.IsNullOrWhiteSpace(showinfo.BackdropPath) ? null : client.GetImageUrl("original", showinfo.BackdropPath).AbsoluteUri, Poster = String.IsNullOrWhiteSpace(showinfo.PosterPath) ? null : client.GetImageUrl("original", showinfo.PosterPath).AbsoluteUri, Backdrops = showinfo.Images?.Backdrops, Posters = showinfo.Images?.Posters }; if (withPreviousNextEp) { bool first = true; int lastSeasonNr = -1; int lastEpisodeNr = -1; DateTime lastEpisodeDateTime = DateTime.MinValue; for (int curSeasonIdx = showinfo.Seasons.Count - 1; curSeasonIdx >= 0; curSeasonIdx--) { var seasoninfo = client.GetTvSeason((int)show, showinfo.Seasons[curSeasonIdx].SeasonNumber); if (seasoninfo == null) { return(si); } for (int curEpisodeIdx = seasoninfo.Episodes.Count - 1; curEpisodeIdx >= 0; curEpisodeIdx--) { if (seasoninfo.Episodes[curEpisodeIdx].AirDate.Date <= DateTime.Today) //air date of ep lies in past { if (first) //first check => there's no next episode because the first that we checked already lies in the past { si.PreviousEpisodeSeasonNr = showinfo.Seasons[curSeasonIdx].SeasonNumber; si.PreviousEpisodeEpisodeNr = seasoninfo.Episodes[curEpisodeIdx].EpisodeNumber; si.PreviousEpisodeDate = seasoninfo.Episodes[curEpisodeIdx].AirDate; return(si); } else // no the first check => the last ep we iterated through must be the "next" to be aired { si.NextEpisodeSeasonNr = lastSeasonNr; si.NextEpisodeEpisodeNr = lastEpisodeNr; si.NextEpisodeDate = lastEpisodeDateTime; si.PreviousEpisodeSeasonNr = showinfo.Seasons[curSeasonIdx].SeasonNumber; si.PreviousEpisodeEpisodeNr = seasoninfo.Episodes[curEpisodeIdx].EpisodeNumber; si.PreviousEpisodeDate = seasoninfo.Episodes[curEpisodeIdx].AirDate; return(si); } } first = false; lastEpisodeNr = seasoninfo.Episodes[curEpisodeIdx].EpisodeNumber; lastEpisodeDateTime = seasoninfo.Episodes[curEpisodeIdx].AirDate; lastSeasonNr = showinfo.Seasons[curSeasonIdx].SeasonNumber; } } } return(si); }
public ShowInformation GetShowInformation(object show, bool withImages, bool withPreviousNextEp) { if(!(show is int)) throw new ArgumentException(); if (client?.Config == null) return null; var showinfo = client.GetTvShow((int) show,withImages?TvShowMethods.Images:TvShowMethods.Undefined); if(showinfo?.Name == null) return null; var si= new ShowInformation { Status = showinfo.Status, PreviousEpisodeDate = showinfo.LastAirDate, NumberEpisodes = showinfo.NumberOfEpisodes, NumberSeasons = showinfo.NumberOfSeasons, ProviderHomepage = "https://www.themoviedb.org/tv/"+((int)show), PublisherHomepage = (showinfo.Homepage==null || showinfo.Homepage.Trim().Length==0) ?null:showinfo.Homepage, Title = showinfo.OriginalName, Backdrop = String.IsNullOrWhiteSpace(showinfo.BackdropPath) ? null : client.GetImageUrl("original", showinfo.BackdropPath).AbsoluteUri, Poster = String.IsNullOrWhiteSpace(showinfo.PosterPath) ? null : client.GetImageUrl("original", showinfo.PosterPath).AbsoluteUri, Backdrops = showinfo.Images?.Backdrops, Posters = showinfo.Images?.Posters }; if (withPreviousNextEp) { bool first = true; int lastSeasonNr = -1; int lastEpisodeNr = -1; DateTime lastEpisodeDateTime = DateTime.MinValue; for (int curSeasonIdx = showinfo.Seasons.Count - 1; curSeasonIdx >= 0; curSeasonIdx--) { var seasoninfo = client.GetTvSeason((int) show, showinfo.Seasons[curSeasonIdx].SeasonNumber); if (seasoninfo == null) return si; for (int curEpisodeIdx = seasoninfo.Episodes.Count - 1; curEpisodeIdx >= 0; curEpisodeIdx--) { if (seasoninfo.Episodes[curEpisodeIdx].AirDate.Date <= DateTime.Today) //air date of ep lies in past { if (first) //first check => there's no next episode because the first that we checked already lies in the past { si.PreviousEpisodeSeasonNr = showinfo.Seasons[curSeasonIdx].SeasonNumber; si.PreviousEpisodeEpisodeNr = seasoninfo.Episodes[curEpisodeIdx].EpisodeNumber; si.PreviousEpisodeDate = seasoninfo.Episodes[curEpisodeIdx].AirDate; return si; } else // no the first check => the last ep we iterated through must be the "next" to be aired { si.NextEpisodeSeasonNr = lastSeasonNr; si.NextEpisodeEpisodeNr = lastEpisodeNr; si.NextEpisodeDate = lastEpisodeDateTime; si.PreviousEpisodeSeasonNr = showinfo.Seasons[curSeasonIdx].SeasonNumber; si.PreviousEpisodeEpisodeNr = seasoninfo.Episodes[curEpisodeIdx].EpisodeNumber; si.PreviousEpisodeDate = seasoninfo.Episodes[curEpisodeIdx].AirDate; return si; } } first = false; lastEpisodeNr = seasoninfo.Episodes[curEpisodeIdx].EpisodeNumber; lastEpisodeDateTime = seasoninfo.Episodes[curEpisodeIdx].AirDate; lastSeasonNr = showinfo.Seasons[curSeasonIdx].SeasonNumber; } } } return si; }