public List <VM_AnimeEpisode_User> GetAllEpisodes(bool onlyRandom) { List <VM_AnimeEpisode_User> allEps = new List <VM_AnimeEpisode_User>(); // find the next episode to play if (DefaultPlayOrderEnum == PlaylistPlayOrder.Sequential && !onlyRandom) { 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)) { allEps.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.OrderBy(a => a.EpisodeType).ThenBy(a => a.EpisodeNumber).ToList(); foreach (VM_AnimeEpisode_User epTemp in eps) { if (epTemp.EpisodeTypeEnum == EpisodeType.Episode || epTemp.EpisodeTypeEnum == EpisodeType.Special) { if (CanUseEpisode(this, epTemp)) { allEps.Add(epTemp); } } } } } } else // random { 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)) { allEps.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)) { allEps.Add(epTemp); } } } } } allEps.Shuffle(); } return(allEps); }
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]; } } }