private NextEpisode GetNextEpisodeId(Show currentShow) { string url = "http://www.omdbapi.com/?i=" + currentShow.SeriesId + "&apikey=cca62f46&season=" + currentShow.Season; NextEpisode nextEpisode = null; using (var client = new HttpClient()) { var content = client.GetStringAsync(url).Result; var show = JsonConvert.DeserializeObject <ImdbEntity>(content); if (show != null && show.Episodes != null && show.Episodes.Any()) { if (currentShow.SeriesId == currentShow.ShowId) { nextEpisode = show.Episodes.OrderBy(x => x.Episode).FirstOrDefault(); return(nextEpisode); } var currentEpisode = show.Episodes.Where(x => x.imdbID == currentShow.ShowId).FirstOrDefault(); nextEpisode = show.Episodes.Where(x => x.Episode > currentEpisode.Episode).OrderBy(x => x.Episode).FirstOrDefault(); //if (nextEpisode == null && show.TotalSeasons == currentShow.Season) //{ // return null; //} if (nextEpisode == null && show.TotalSeasons > currentShow.Season) { url = "http://www.omdbapi.com/?i=" + currentShow.SeriesId + "&apikey=cca62f46&season=" + (currentShow.Season + 1); content = client.GetStringAsync(url).Result; show = JsonConvert.DeserializeObject <ImdbEntity>(content); if (show != null && show.Episodes != null && show.Episodes.Any()) { nextEpisode = show.Episodes.OrderBy(x => x.Episode).FirstOrDefault(); return(nextEpisode); } } } return(nextEpisode); } }
public void SetNextEpisode(bool onlyRandom) { if (PlaylistObjects.Count == 0) { return; } // find the next episode to play NextEpisode = null; if (DefaultPlayOrderEnum == PlaylistPlayOrder.Sequential && !onlyRandom) { while (true) { foreach (VM_PlaylistItem pli in PlaylistObjects) { if (pli.ItemType == PlaylistItemType.Episode) { VM_AnimeEpisode_User epTemp = pli.PlaylistItem as VM_AnimeEpisode_User; if (CanUseEpisode(this, epTemp)) { NextEpisode = epTemp; break; } } if (pli.ItemType == PlaylistItemType.AnimeSeries) { VM_AnimeSeries_User ser = (VM_AnimeSeries_User)pli.PlaylistItem; VM_MainListHelper.Instance.UpdateAll(); ser.RefreshEpisodes(); List <VM_AnimeEpisode_User> eps = ser.AllEpisodes.OrderBy(a => a.EpisodeType).ThenBy(a => a.EpisodeNumber).ToList(); bool foundEp = false; foreach (VM_AnimeEpisode_User epTemp in eps) { if (epTemp.EpisodeTypeEnum == EpisodeType.Episode || epTemp.EpisodeTypeEnum == EpisodeType.Special) { if (CanUseEpisode(this, epTemp)) { NextEpisode = epTemp; foundEp = true; break; } } } if (foundEp) { break; } } } break; } } else // random { // get all the candidate episodes List <VM_AnimeEpisode_User> canidateEps = new List <VM_AnimeEpisode_User>(); foreach (VM_PlaylistItem pli in PlaylistObjects) { if (pli.ItemType == PlaylistItemType.Episode) { VM_AnimeEpisode_User epTemp = pli.PlaylistItem as VM_AnimeEpisode_User; if (CanUseEpisode(this, epTemp)) { canidateEps.Add(epTemp); } } if (pli.ItemType == PlaylistItemType.AnimeSeries) { VM_AnimeSeries_User ser = (VM_AnimeSeries_User)pli.PlaylistItem; VM_MainListHelper.Instance.UpdateAll(); ser.RefreshEpisodes(); List <VM_AnimeEpisode_User> eps = ser.AllEpisodes; foreach (VM_AnimeEpisode_User epTemp in eps) { if (epTemp.EpisodeTypeEnum == EpisodeType.Episode || epTemp.EpisodeTypeEnum == EpisodeType.Special) { if (CanUseEpisode(this, epTemp)) { canidateEps.Add(epTemp); } } } } } // pick a random object from the play list if (canidateEps.Count > 0) { NextEpisode = canidateEps[epRandom.Next(0, canidateEps.Count)]; } } if (NextEpisode != null) { NextEpisode.SetTvDBInfo(); NextEpisode.RefreshAnime(); AniDB_Anime = NextEpisode.AniDBAnime; if (VM_MainListHelper.Instance.AllSeriesDictionary.ContainsKey(NextEpisode.AnimeSeriesID)) { Series = VM_MainListHelper.Instance.AllSeriesDictionary[NextEpisode.AnimeSeriesID]; } } }
public void SetNextEpisode(bool onlyRandom) { if (PlaylistObjects.Count == 0) { return; } // find the next episode to play NextEpisode = null; if (DefaultPlayOrderEnum == PlaylistPlayOrder.Sequential && !onlyRandom) { bool foundEp = false; while (!foundEp) { foreach (PlaylistItemVM pli in PlaylistObjects) { if (pli.ItemType == JMMClient.PlaylistItemType.Episode) { AnimeEpisodeVM epTemp = pli.PlaylistItem as AnimeEpisodeVM; if (CanUseEpisode(this, epTemp)) { NextEpisode = epTemp; foundEp = true; break; } } if (pli.ItemType == JMMClient.PlaylistItemType.AnimeSeries) { AnimeSeriesVM ser = pli.PlaylistItem as AnimeSeriesVM; ser.RefreshBase(); ser.RefreshEpisodes(); List <AnimeEpisodeVM> eps = ser.AllEpisodes; List <SortPropOrFieldAndDirection> sortCriteria = new List <SortPropOrFieldAndDirection>(); sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeType", false, JMMClient.SortType.eInteger)); sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeNumber", false, JMMClient.SortType.eInteger)); eps = Sorting.MultiSort <AnimeEpisodeVM>(eps, sortCriteria); foreach (AnimeEpisodeVM epTemp in eps) { if (epTemp.EpisodeTypeEnum == EpisodeType.Episode || epTemp.EpisodeTypeEnum == EpisodeType.Special) { if (CanUseEpisode(this, epTemp)) { NextEpisode = epTemp; foundEp = true; break; } } } if (foundEp) { break; } } } break; } } else // random { // get all the candidate episodes List <AnimeEpisodeVM> canidateEps = new List <AnimeEpisodeVM>(); foreach (PlaylistItemVM pli in PlaylistObjects) { if (pli.ItemType == JMMClient.PlaylistItemType.Episode) { AnimeEpisodeVM epTemp = pli.PlaylistItem as AnimeEpisodeVM; if (CanUseEpisode(this, epTemp)) { canidateEps.Add(epTemp); } } if (pli.ItemType == JMMClient.PlaylistItemType.AnimeSeries) { AnimeSeriesVM ser = pli.PlaylistItem as AnimeSeriesVM; ser.RefreshBase(); ser.RefreshEpisodes(); List <AnimeEpisodeVM> eps = ser.AllEpisodes; foreach (AnimeEpisodeVM epTemp in eps) { if (epTemp.EpisodeTypeEnum == EpisodeType.Episode || epTemp.EpisodeTypeEnum == EpisodeType.Special) { if (CanUseEpisode(this, epTemp)) { canidateEps.Add(epTemp); } } } } } // pick a random object from the play list if (canidateEps.Count > 0) { NextEpisode = canidateEps[epRandom.Next(0, canidateEps.Count)]; } } if (NextEpisode != null) { NextEpisode.SetTvDBInfo(); NextEpisode.RefreshAnime(); AniDB_Anime = NextEpisode.AniDB_Anime; if (MainListHelperVM.Instance.AllSeriesDictionary.ContainsKey(NextEpisode.AnimeSeriesID)) { Series = MainListHelperVM.Instance.AllSeriesDictionary[NextEpisode.AnimeSeriesID]; } } }