private void ShowNextEpisode()
        {
            VM_AnimeGroup_User grp = DataContext as VM_AnimeGroup_User;

            if (grp == null)
            {
                return;
            }

            if (grp.AnimeGroupID == 0)
            {
                ucNextEpisode.EpisodeExists  = false;
                ucNextEpisode.EpisodeMissing = true;
                ucNextEpisode.DataContext    = null;
                return;
            }

            VM_AnimeEpisode_User ep = (VM_AnimeEpisode_User)VM_ShokoServer.Instance.ShokoServices.GetNextUnwatchedEpisodeForGroup(grp.AnimeGroupID, VM_ShokoServer.Instance.CurrentUser.JMMUserID);

            if (ep != null)
            {
                ep.SetTvDBInfo();
                ucNextEpisode.DataContext = ep;
            }
            else
            {
                ucNextEpisode.EpisodeExists  = false;
                ucNextEpisode.EpisodeMissing = true;
                ucNextEpisode.DataContext    = null;
            }
        }
        void episodesWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                VM_AnimeSeries_User ser = e.Argument as VM_AnimeSeries_User;

                List <VM_AnimeEpisode_User> rawEps = VM_ShokoServer.Instance.ShokoServices.GetAllUnwatchedEpisodes(ser.AnimeSeriesID,
                                                                                                                   VM_ShokoServer.Instance.CurrentUser.JMMUserID).CastList <VM_AnimeEpisode_User>();

                // find the last watched episode
                VM_AnimeEpisode_User rawLastEp = (VM_AnimeEpisode_User)VM_ShokoServer.Instance.ShokoServices.GetLastWatchedEpisodeForSeries(ser.AnimeSeriesID,
                                                                                                                                            VM_ShokoServer.Instance.CurrentUser.JMMUserID);

                if (rawLastEp != null)
                {
                    rawLastEp.SetTvDBInfo();
                    //if (VM_ShokoServer.Instance.Trakt_IsEnabled)
                    //    ep.SetTraktInfo();
                    rawLastEp.EpisodeOrder = 0;
                    Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                    {
                        UnwatchedEpisodes.Add(rawLastEp);
                    });
                }

                int i = 0;
                foreach (VM_AnimeEpisode_User raw in rawEps)
                {
                    i++;
                    raw.SetTvDBInfo();
                    //if (i == 1 && VM_ShokoServer.Instance.Trakt_IsEnabled) ep.SetTraktInfo();
                    raw.EpisodeOrder = i;
                    Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                    {
                        UnwatchedEpisodes.Add(raw);
                    });

                    if (i == 5)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.ToString());
            }
        }
Exemple #3
0
        void btnTvDBLinkAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // get the current tvdb link
                VM_AnimeEpisode_User ep = DataContext as VM_AnimeEpisode_User;
                ep.RefreshAnime();
                if (ep.AniDB_Anime == null || ep.AniDB_Anime.TvSummary == null || ep.AniDB_Anime.TvSummary.CrossRefTvDBV2 == null ||
                    ep.AniDB_Anime.TvSummary.CrossRefTvDBV2.Count == 0)
                {
                    Utils.ShowErrorMessage(Shoko.Commons.Properties.Resources.EpisodeDetail_TvDBLink);
                    return;
                }

                Window wdw = Window.GetWindow(this);

                Cursor = Cursors.Wait;
                SelectTvDBEpisodeForm frm = new SelectTvDBEpisodeForm();
                frm.Owner = wdw;
                frm.Init(ep, ep.AniDB_Anime);
                bool?result = frm.ShowDialog();
                if (result.Value)
                {
                    // update info
                    CL_AnimeEpisode_User contract = VM_ShokoServer.Instance.ShokoServices.GetEpisode(
                        ep.AnimeEpisodeID, VM_ShokoServer.Instance.CurrentUser.JMMUserID);
                    if (contract != null)
                    {
                        ep.RefreshAnime(true);
                        ep.Populate(contract);
                        ep.SetTvDBInfo();
                    }
                }

                Cursor = Cursors.Arrow;
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Exemple #4
0
        void btnTvDBLinkRemove_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // get the current tvdb link
                VM_AnimeEpisode_User ep = DataContext as VM_AnimeEpisode_User;

                Window wdw = Window.GetWindow(this);

                Cursor = Cursors.Wait;

                string res = VM_ShokoServer.Instance.ShokoServices.RemoveLinkAniDBTvDBEpisode(ep.AniDB_EpisodeID);
                if (res.Length > 0)
                {
                    Cursor = Cursors.Arrow;
                    Utils.ShowErrorMessage(res);
                    return;
                }

                // update info
                VM_AnimeEpisode_User contract = (VM_AnimeEpisode_User)VM_ShokoServer.Instance.ShokoServices.GetEpisode(
                    ep.AnimeEpisodeID, VM_ShokoServer.Instance.CurrentUser.JMMUserID);
                if (contract != null)
                {
                    ep.RefreshAnime(true);
                    ep.Populate(contract);
                    ep.SetTvDBInfo();
                }


                Cursor = Cursors.Arrow;
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Exemple #5
0
        private void CommandBinding_PlayEpisode(object sender, ExecutedRoutedEventArgs e)
        {
            Window parentWindow = Window.GetWindow(this);

            object obj = e.Parameter;

            if (obj == null)
            {
                return;
            }

            try
            {
                if (obj.GetType() == typeof(VM_PlaylistItem))
                {
                    VM_PlaylistItem pli = obj as VM_PlaylistItem;

                    VM_AnimeEpisode_User ep = null;

                    if (pli.ItemType == Models.Enums.PlaylistItemType.Episode)
                    {
                        ep = pli.PlaylistItem as VM_AnimeEpisode_User;
                    }
                    if (pli.ItemType == Models.Enums.PlaylistItemType.AnimeSeries)
                    {
                        VM_AnimeSeries_User ser = pli.PlaylistItem as VM_AnimeSeries_User;
                        if (ser == null)
                        {
                            return;
                        }

                        ep = (VM_AnimeEpisode_User)VM_ShokoServer.Instance.ShokoServices.GetNextUnwatchedEpisode(ser.AnimeSeriesID,
                                                                                                                 VM_ShokoServer.Instance.CurrentUser.JMMUserID);
                    }

                    if (ep == null)
                    {
                        return;
                    }
                    ep.SetTvDBInfo();
                    if (ep.FilesForEpisode.Count == 1)
                    {
                        bool force = true;
                        if (MainWindow.videoHandler.DefaultPlayer.Player.ToString() !=
                            Enum.GetName(typeof(VideoPlayer), VideoPlayer.WindowsDefault))
                        {
                            if (ep.FilesForEpisode[0].VideoLocal_ResumePosition > 0)
                            {
                                AskResumeVideo ask = new AskResumeVideo(ep.FilesForEpisode[0].VideoLocal_ResumePosition);
                                ask.Owner = Window.GetWindow(this);
                                if (ask.ShowDialog() == true)
                                {
                                    force = false;
                                }
                            }
                        }
                        MainWindow.videoHandler.PlayVideo(ep.FilesForEpisode[0], force);
                    }
                    else if (ep.FilesForEpisode.Count > 1)
                    {
                        if (AppSettings.AutoFileSingleEpisode)
                        {
                            VM_VideoDetailed vid = MainWindow.videoHandler.GetAutoFileForEpisode(ep);
                            if (vid != null)
                            {
                                bool force = true;
                                if (MainWindow.videoHandler.DefaultPlayer.Player.ToString() !=
                                    Enum.GetName(typeof(VideoPlayer), VideoPlayer.WindowsDefault))
                                {
                                    if (vid.VideoLocal_ResumePosition > 0)
                                    {
                                        AskResumeVideo ask = new AskResumeVideo(vid.VideoLocal_ResumePosition);
                                        ask.Owner = Window.GetWindow(this);
                                        if (ask.ShowDialog() == true)
                                        {
                                            force = false;
                                        }
                                    }
                                }
                                MainWindow.videoHandler.PlayVideo(vid, force);
                            }
                        }
                        else
                        {
                            PlayVideosForEpisodeForm frm = new PlayVideosForEpisodeForm();
                            frm.Owner = parentWindow;
                            frm.Init(ep);
                            frm.ShowDialog();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }