private static void MapSeasons(List <SeasonRequests> seasonRequests, Season tvSeason, SeasonDetails seasonEpisodes) { foreach (var episode in seasonEpisodes.episodes) { var season = seasonRequests.FirstOrDefault(x => x.SeasonNumber == episode.season_number); if (season == null) { var newSeason = new SeasonRequests { SeasonNumber = episode.season_number, Overview = tvSeason.overview, Episodes = new List <EpisodeRequests>() }; newSeason.Episodes.Add(new EpisodeRequests { //Url = episode...ToHttpsUrl(), Title = episode.name, AirDate = episode.air_date.HasValue() ? DateTime.Parse(episode.air_date) : DateTime.MinValue, EpisodeNumber = episode.episode_number, }); seasonRequests.Add(newSeason); } else { // We already have the season, so just add the episode season.Episodes.Add(new EpisodeRequests { //Url = e.url.ToHttpsUrl(), Title = episode.name, AirDate = episode.air_date.HasValue() ? DateTime.Parse(episode.air_date) : DateTime.MinValue, EpisodeNumber = episode.episode_number, }); } } }
public static async Task SingleEpisodeCheck(bool useImdb, IQueryable <EmbyEpisode> allEpisodes, EpisodeRequests episode, SeasonRequests season, EmbyContent item, bool useTheMovieDb, bool useTvDb) { EmbyEpisode epExists = null; if (useImdb) { epExists = await allEpisodes.FirstOrDefaultAsync(x => x.EpisodeNumber == episode.EpisodeNumber && x.SeasonNumber == season.SeasonNumber && x.Series.ImdbId == item.ImdbId); } if (useTheMovieDb) { epExists = await allEpisodes.FirstOrDefaultAsync(x => x.EpisodeNumber == episode.EpisodeNumber && x.SeasonNumber == season.SeasonNumber && x.Series.TheMovieDbId == item.TheMovieDbId); } if (useTvDb) { epExists = await allEpisodes.FirstOrDefaultAsync(x => x.EpisodeNumber == episode.EpisodeNumber && x.SeasonNumber == season.SeasonNumber && x.Series.TvDbId == item.TvDbId); } if (epExists != null) { episode.Available = true; } }
public async Task <SearchTvShowViewModel> GetShowInformation(string tvdbid, CancellationToken token) { var show = await Cache.GetOrAdd(nameof(GetShowInformation) + tvdbid, async() => await TvMazeApi.ShowLookupByTheTvDbId(int.Parse(tvdbid)), DateTime.Now.AddHours(12)); if (show == null) { // We don't have enough information return(null); } var episodes = await Cache.GetOrAdd("TvMazeEpisodeLookup" + show.id, async() => await TvMazeApi.EpisodeLookup(show.id), DateTime.Now.AddHours(12)); if (episodes == null || !episodes.Any()) { // We don't have enough information return(null); } var mapped = Mapper.Map <SearchTvShowViewModel>(show); foreach (var e in episodes) { var season = mapped.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == e.season); if (season == null) { var newSeason = new SeasonRequests { SeasonNumber = e.season, Episodes = new List <EpisodeRequests>() }; newSeason.Episodes.Add(new EpisodeRequests { Url = e.url.ToHttpsUrl(), Title = e.name, AirDate = e.airstamp.HasValue() ? DateTime.Parse(e.airstamp) : DateTime.MinValue, EpisodeNumber = e.number, }); mapped.SeasonRequests.Add(newSeason); } else { // We already have the season, so just add the episode season.Episodes.Add(new EpisodeRequests { Url = e.url.ToHttpsUrl(), Title = e.name, AirDate = e.airstamp.HasValue() ? DateTime.Parse(e.airstamp) : DateTime.MinValue, EpisodeNumber = e.number, }); } } return(await ProcessResult(mapped, false)); }
public async Task <SearchTvShowViewModel> GetShowInformation(int tvdbid) { var show = await TvMazeApi.ShowLookupByTheTvDbId(tvdbid); if (show == null) { // We don't have enough information return(null); } var episodes = await TvMazeApi.EpisodeLookup(show.id); if (episodes == null || !episodes.Any()) { // We don't have enough information return(null); } var mapped = Mapper.Map <SearchTvShowViewModel>(show); foreach (var e in episodes) { var season = mapped.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == e.season); if (season == null) { var newSeason = new SeasonRequests { SeasonNumber = e.season, Episodes = new List <EpisodeRequests>() }; newSeason.Episodes.Add(new EpisodeRequests { Url = e.url, Title = e.name, AirDate = e.airstamp.HasValue() ? DateTime.Parse(e.airstamp) : DateTime.MinValue, EpisodeNumber = e.number, }); mapped.SeasonRequests.Add(newSeason); } else { // We already have the season, so just add the episode season.Episodes.Add(new EpisodeRequests { Url = e.url, Title = e.name, AirDate = e.airstamp.HasValue() ? DateTime.Parse(e.airstamp) : DateTime.MinValue, EpisodeNumber = e.number, }); } } return(await ProcessResult(mapped)); }
public static async Task SingleEpisodeCheck(bool useImdb, IQueryable <PlexEpisode> allEpisodes, EpisodeRequests episode, SeasonRequests season, PlexServerContent item, bool useTheMovieDb, bool useTvDb, ILogger log) { PlexEpisode epExists = null; try { if (useImdb) { epExists = await allEpisodes.FirstOrDefaultAsync(x => x.EpisodeNumber == episode.EpisodeNumber && x.SeasonNumber == season.SeasonNumber && x.Series.ImdbId == item.ImdbId); } if (useTheMovieDb) { epExists = await allEpisodes.FirstOrDefaultAsync(x => x.EpisodeNumber == episode.EpisodeNumber && x.SeasonNumber == season.SeasonNumber && x.Series.TheMovieDbId == item.TheMovieDbId); } if (useTvDb) { epExists = await allEpisodes.FirstOrDefaultAsync(x => x.EpisodeNumber == episode.EpisodeNumber && x.SeasonNumber == season.SeasonNumber && x.Series.TvDbId == item.TvDbId); } } catch (Exception e) { log.LogError(e, "Exception thrown when attempting to check if something is available"); } if (epExists != null) { episode.Available = true; } }
public async Task <TvShowRequestBuilder> BuildEpisodes(TvRequestViewModel tv) { if (tv.RequestAll) { var episodes = await TvApi.EpisodeLookup(ShowInfo.id); foreach (var ep in episodes) { var season = ChildRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == ep.season); if (season == null) { ChildRequest.SeasonRequests.Add(new SeasonRequests { Episodes = new List <EpisodeRequests> { new EpisodeRequests { EpisodeNumber = ep.number, AirDate = FormatDate(ep.airdate), Title = ep.name, Url = ep.url.ToHttpsUrl() } }, SeasonNumber = ep.season, }); } else { season.Episodes.Add(new EpisodeRequests { EpisodeNumber = ep.number, AirDate = FormatDate(ep.airdate), Title = ep.name, Url = ep.url.ToHttpsUrl() }); } } } else if (tv.LatestSeason) { var episodes = await TvApi.EpisodeLookup(ShowInfo.id); var latest = episodes.OrderByDescending(x => x.season).FirstOrDefault(); var episodesRequests = new List <EpisodeRequests>(); foreach (var ep in episodes) { if (ep.season == latest.season) { episodesRequests.Add(new EpisodeRequests { EpisodeNumber = ep.number, AirDate = FormatDate(ep.airdate), Title = ep.name, Url = ep.url.ToHttpsUrl() }); } } ChildRequest.SeasonRequests.Add(new SeasonRequests { Episodes = episodesRequests, SeasonNumber = latest.season, }); } else if (tv.FirstSeason) { var episodes = await TvApi.EpisodeLookup(ShowInfo.id); var first = episodes.OrderBy(x => x.season).FirstOrDefault(); var episodesRequests = new List <EpisodeRequests>(); foreach (var ep in episodes) { if (ep.season == first.season) { episodesRequests.Add(new EpisodeRequests { EpisodeNumber = ep.number, AirDate = FormatDate(ep.airdate), Title = ep.name, Url = ep.url.ToHttpsUrl() }); } } ChildRequest.SeasonRequests.Add(new SeasonRequests { Episodes = episodesRequests, SeasonNumber = first.season, }); } else { // It's a custom request var seasonRequests = new List <SeasonRequests>(); var episodes = await TvApi.EpisodeLookup(ShowInfo.id); foreach (var ep in episodes) { var existingSeasonRequest = seasonRequests.FirstOrDefault(x => x.SeasonNumber == ep.season); if (existingSeasonRequest != null) { var requestedSeason = tv.Seasons.FirstOrDefault(x => x.SeasonNumber == ep.season); var requestedEpisode = requestedSeason?.Episodes?.Any(x => x.EpisodeNumber == ep.number) ?? false; if (requestedSeason != null && requestedEpisode) { // We already have this, let's just add the episodes to it existingSeasonRequest.Episodes.Add(new EpisodeRequests { EpisodeNumber = ep.number, AirDate = FormatDate(ep.airdate), Title = ep.name, Url = ep.url.ToHttpsUrl() }); } } else { var newRequest = new SeasonRequests { SeasonNumber = ep.season }; var requestedSeason = tv.Seasons.FirstOrDefault(x => x.SeasonNumber == ep.season); var requestedEpisode = requestedSeason?.Episodes?.Any(x => x.EpisodeNumber == ep.number) ?? false; if (requestedSeason != null && requestedEpisode) { newRequest.Episodes.Add(new EpisodeRequests { EpisodeNumber = ep.number, AirDate = FormatDate(ep.airdate), Title = ep.name, Url = ep.url.ToHttpsUrl() }); seasonRequests.Add(newRequest); } } } foreach (var s in seasonRequests) { ChildRequest.SeasonRequests.Add(s); } } return(this); }
public async Task <TvShowRequestBuilderV2> BuildEpisodes(TvRequestViewModelV2 tv) { var allEpisodes = new List <Episode>(); foreach (var season in TheMovieDbRecord.seasons) { var seasonEpisodes = await MovieDbApi.GetSeasonEpisodes(TheMovieDbRecord.id, season.season_number, CancellationToken.None); allEpisodes.AddRange(seasonEpisodes.episodes); } if (tv.RequestAll) { foreach (var ep in allEpisodes) { var season = ChildRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == ep.season_number); if (season == null) { ChildRequest.SeasonRequests.Add(new SeasonRequests { Episodes = new List <EpisodeRequests> { new EpisodeRequests { EpisodeNumber = ep.episode_number, AirDate = FormatDate(ep.air_date), Title = ep.name, } }, SeasonNumber = ep.season_number, }); } else { season.Episodes.Add(new EpisodeRequests { EpisodeNumber = ep.episode_number, AirDate = FormatDate(ep.air_date), Title = ep.name, }); } } } else if (tv.LatestSeason) { var latest = allEpisodes.OrderByDescending(x => x.season_number).FirstOrDefault(); var episodesRequests = new List <EpisodeRequests>(); foreach (var ep in allEpisodes) { if (ep.season_number == latest.season_number) { episodesRequests.Add(new EpisodeRequests { EpisodeNumber = ep.episode_number, AirDate = FormatDate(ep.air_date), Title = ep.name, }); } } ChildRequest.SeasonRequests.Add(new SeasonRequests { Episodes = episodesRequests, SeasonNumber = latest.season_number, }); } else if (tv.FirstSeason) { var first = allEpisodes.OrderBy(x => x.season_number).FirstOrDefault(); var episodesRequests = new List <EpisodeRequests>(); foreach (var ep in allEpisodes) { if (ep.season_number == first.season_number) { episodesRequests.Add(new EpisodeRequests { EpisodeNumber = ep.episode_number, AirDate = FormatDate(ep.air_date), Title = ep.name, }); } } ChildRequest.SeasonRequests.Add(new SeasonRequests { Episodes = episodesRequests, SeasonNumber = first.season_number, }); } else { // It's a custom request var seasonRequests = new List <SeasonRequests>(); foreach (var ep in allEpisodes) { var existingSeasonRequest = seasonRequests.FirstOrDefault(x => x.SeasonNumber == ep.season_number); if (existingSeasonRequest != null) { var requestedSeason = tv.Seasons.FirstOrDefault(x => x.SeasonNumber == ep.season_number); var requestedEpisode = requestedSeason?.Episodes?.Any(x => x.EpisodeNumber == ep.episode_number) ?? false; if (requestedSeason != null && requestedEpisode) { // We already have this, let's just add the episodes to it existingSeasonRequest.Episodes.Add(new EpisodeRequests { EpisodeNumber = ep.episode_number, AirDate = FormatDate(ep.air_date), Title = ep.name, }); } } else { var newRequest = new SeasonRequests { SeasonNumber = ep.season_number }; var requestedSeason = tv.Seasons.FirstOrDefault(x => x.SeasonNumber == ep.season_number); var requestedEpisode = requestedSeason?.Episodes?.Any(x => x.EpisodeNumber == ep.episode_number) ?? false; if (requestedSeason != null && requestedEpisode) { newRequest.Episodes.Add(new EpisodeRequests { EpisodeNumber = ep.episode_number, AirDate = FormatDate(ep.air_date), Title = ep.name, }); seasonRequests.Add(newRequest); } } } foreach (var s in seasonRequests) { ChildRequest.SeasonRequests.Add(s); } } return(this); }