protected async Task <MediaElementBase> GetNextMediaElement(TvShowEpisode episode) { var episodes = episode.Season.TvShowEpisodes.OrderBy(q => q.IndexNumber).ToList(); int epNumber = 0; for (; epNumber < episode.Season.TvShowEpisodes.Count; epNumber++) { TvShowEpisode episodeCheck = episode.Season.TvShowEpisodes[epNumber]; if (episode.Id == episodeCheck.Id) { break; } } if (epNumber == episodes.Count) { var season = episode.Season; var seasons = episode.TvShow.Seasons; int seasonNumber = 0; for (; seasonNumber < episode.TvShow.Seasons.Count; seasonNumber++) { TvShowSeason seasonCheck = episode.TvShow.Seasons[seasonNumber]; if (season.Id == seasonCheck.Id) { break; } } if (seasonNumber == seasons.Count) { return(null); } var nextSeason = seasons[seasonNumber + 1]; IUnityContainer container = Globals.Instance.Container; var tvShowService = container.Resolve <ITvShowService>(); var nextSeasonEpisodes = await tvShowService.GetEpisodesBy(episode.TvShow, nextSeason); return(nextSeasonEpisodes.FirstOrDefault()); } return(episodes[epNumber + 1]); }
private void SelectedSeasonChanged(TvShowSeason season) { if (season.TvShowEpisodes.Any()) { var firstEpisodeFromCurrentSeason = season.TvShowEpisodes.OrderBy(q => q.IndexNumber).FirstOrDefault(); if (firstEpisodeFromCurrentSeason != null && firstEpisodeFromCurrentSeason != FirstAvailableEpisode && firstEpisodeFromCurrentSeason != ContinueWatchingEpisode && firstEpisodeFromCurrentSeason != NextUnplayedEpisode) { FirstEpisodeFromCurrentSeason = firstEpisodeFromCurrentSeason; _logManager.LogDebug($"TV Show {season.TvShow}: season {season} premiere: {FirstEpisodeFromCurrentSeason}"); } } SelectedSeasonEpisodes = season.TvShowEpisodes; RaisePropertyChanged(nameof(SelectedSeasonEpisodes)); RaisePropertyChanged(nameof(SeasonEpisodesText)); }
public async Task Load() { IsLoading = true; try { if (!TvShows.Any()) { IList <TvShow> tvShows = (await _tvShowService.GetTvShows()).ToList(); foreach (TvShow tvShow in tvShows.OrderBy(q => q.Name)) { TvShows.Add(tvShow); } } IList <TvShowEpisode> tvShowEpisodes = (await _tvShowService.GetContinueWatchingEpisodes()).ToList(); foreach (TvShowEpisode tvShowEpisode in tvShowEpisodes) { if (ContinueWatchingTvShows.All(q => q.Id != tvShowEpisode.Id)) { ContinueWatchingTvShows.Add(tvShowEpisode); TvShow correspondingTvShow = TvShows.FirstOrDefault(q => q.Id == tvShowEpisode.SeriesId); if (correspondingTvShow != null) { tvShowEpisode.TvShow = correspondingTvShow; TvShowSeason correspondingSeason = correspondingTvShow.Seasons.FirstOrDefault(q => q.Id == tvShowEpisode.SeasonId); if (correspondingSeason != null) { tvShowEpisode.Season = correspondingSeason; } else { IEnumerable <TvShowSeason> seasons = await _tvShowService.GetSeasonsBy(correspondingTvShow); correspondingSeason = seasons.FirstOrDefault(q => q.Id == tvShowEpisode.SeasonId); tvShowEpisode.Season = correspondingSeason; await _tvShowService.GetEpisodesBy(correspondingTvShow, correspondingSeason); } } } } OrderByName(); } catch (Exception xc) { _logManager.LogError(xc, "An error occurred while loading tv shows."); } finally { IsLoading = false; } }