Beispiel #1
0
        private void CommandBinding_RescanFile(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                Window parentWindow = Window.GetWindow(this);

                object obj = e.Parameter;
                if (obj == null)
                {
                    return;
                }

                if (obj.GetType() == typeof(VM_AnimeEpisode_User))
                {
                    VM_VideoLocal vid = DataContext as VM_VideoLocal;
                    VM_ShokoServer.Instance.ShokoServices.RescanFile(vid.VideoLocalID);
                }

                MessageBox.Show(Shoko.Commons.Properties.Resources.MSG_INFO_AddedQueueCmds, Shoko.Commons.Properties.Resources.Done, MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Beispiel #2
0
 public static VideoInfo ToVideoInfo(this VM_VideoLocal vid, bool forcebegining)
 {
     if (string.IsNullOrEmpty(vid.GetLocalFileSystemFullPath()))
     {
         Tuple <string, List <string> > t = GetInfo(vid.VideoLocalID, vid.FullPath, vid.Media);
         return(new VideoInfo
         {
             Uri = t.Item1,
             SubtitlePaths = t.Item2,
             IsUrl = true,
             Duration = vid.Duration,
             ResumePosition = forcebegining ? 0 : vid.ResumePosition,
             VideoLocalId = vid.VideoLocalID,
             VideoLocal = vid,
             WasWatched = vid.WatchedDate.HasValue
         });
     }
     return(new VideoInfo
     {
         Uri = vid.GetLocalFileSystemFullPath(),
         IsUrl = false,
         Duration = vid.Duration,
         ResumePosition = forcebegining ? 0 : vid.ResumePosition,
         VideoLocalId = vid.VideoLocalID,
         VideoLocal = vid,
         WasWatched = vid.WatchedDate.HasValue
     });
 }
Beispiel #3
0
        private void CommandBinding_RehashFile(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                Window parentWindow = Window.GetWindow(this);

                object obj = e.Parameter;
                if (obj == null)
                {
                    return;
                }

                if (obj.GetType() == typeof(VM_VideoLocal))
                {
                    VM_VideoLocal vid = obj as VM_VideoLocal;
                    EnableDisableControls(false);

                    VM_ShokoServer.Instance.ShokoServices.RehashFile(vid.VideoLocalID);
                }

                MessageBox.Show(Shoko.Commons.Properties.Resources.MSG_INFO_AddedQueueCmds, "Done", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }

            EnableDisableControls(true);
        }
        private void CommandBinding_OpenFolder(object sender, ExecutedRoutedEventArgs e)
        {
            object obj = e.Parameter;

            if (obj == null)
            {
                return;
            }

            try
            {
                if (obj.GetType() == typeof(VM_VideoLocal))
                {
                    VM_VideoLocal vid = obj as VM_VideoLocal;

                    if (File.Exists(Commons.Extensions.Models.GetLocalFileSystemFullPath(vid)))
                    {
                        Utils.OpenFolderAndSelectFile(Commons.Extensions.Models.GetLocalFileSystemFullPath(vid));
                    }
                    else
                    {
                        MessageBox.Show(Shoko.Commons.Properties.Resources.MSG_ERR_FileNotFound, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
        private void DgVideos_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                ccDetail.Content         = null;
                ccDetailMultiple.Content = null;

                AnyVideosSelected      = dgVideos.SelectedItems.Count > 0;
                OneVideoSelected       = dgVideos.SelectedItems.Count == 1;
                MultipleVideosSelected = dgVideos.SelectedItems.Count > 1;

                MultipleTypeRange  = cboMultiType.SelectedIndex == 0;
                MultipleTypeSingle = cboMultiType.SelectedIndex == 1;

                Visibility visible = Visibility.Visible;

                // if only one video selected
                if (OneVideoSelected)
                {
                    VM_VideoLocal vid = dgVideos.SelectedItem as VM_VideoLocal;
                    ccDetail.Content = vid;
                    if (vid != null && !vid.IsHashed())
                    {
                        visible = Visibility.Hidden;
                    }
                }

                // if only one video selected
                if (MultipleVideosSelected)
                {
                    MultipleVideos mv = new MultipleVideos();
                    mv.SelectedCount = dgVideos.SelectedItems.Count;
                    mv.VideoLocalIDs = new List <int>();
                    mv.VideoLocals   = new List <VM_VideoLocal>();

                    foreach (object obj in dgVideos.SelectedItems)
                    {
                        VM_VideoLocal vid = obj as VM_VideoLocal;
                        mv.VideoLocalIDs.Add(vid.VideoLocalID);
                        mv.VideoLocals.Add(vid);
                    }

                    ccDetailMultiple.Content = mv;
                    if (!mv.AllHaveHashes)
                    {
                        visible = Visibility.Hidden;
                    }
                }
                SetConfirmDetails();
                Confirm1.Visibility = Confirm2.Visibility = visible;
                if (string.IsNullOrEmpty(txtSeriesSearch.Text))
                {
                    RefreshSeries();
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Beispiel #6
0
 public static VideoInfo ToVideoInfo(this VM_VideoLocal vid, bool forcebegining)
 {
     if (string.IsNullOrEmpty(vid.GetLocalFileSystemFullPath()))
     {
         if (vid.Media?.Parts == null || vid.Media.Parts.Count == 0)
         {
             throw new Exception("There is no media information loaded in the video selected, we're unable to stream the media");
         }
         Tuple <string, List <string> > t = GetInfoFromMedia(vid.Media);
         return(new VideoInfo
         {
             Uri = t.Item1,
             SubtitlePaths = t.Item2,
             IsUrl = true,
             Duration = vid.Duration,
             ResumePosition = forcebegining ? 0 : vid.ResumePosition,
             VideoLocalId = vid.VideoLocalID,
             VideoLocal = vid,
             WasWatched = vid.WatchedDate.HasValue
         });
     }
     return(new VideoInfo
     {
         Uri = vid.GetLocalFileSystemFullPath(),
         IsUrl = false,
         Duration = vid.Duration,
         ResumePosition = forcebegining ? 0 : vid.ResumePosition,
         VideoLocalId = vid.VideoLocalID,
         VideoLocal = vid,
         WasWatched = vid.WatchedDate.HasValue
     });
 }
Beispiel #7
0
        /*public AVDumpVM(VideoDetailedVM vid)
         *      {
         *              this.FullPath = vid.FullPath;
         *              this.FileSize = vid.VideoLocal_FileSize;
         *              this.ED2KDump = "";
         *              this.AVDumpFullResult = "";
         *              this.HasBeenDumped = false;
         *              this.IsBeingDumped = false;
         *              this.DumpStatus = "To be processed";
         *      }*/

        public VM_AVDump(VM_VideoLocal vid)
        {
            FullPath         = vid.GetLocalFileSystemFullPath();
            FileSize         = vid.FileSize;
            ED2KDump         = "";
            AVDumpFullResult = ""; HasBeenDumped = false;
            IsBeingDumped    = false;
            DumpStatus       = "To be processed";
            VideoLocal       = vid;
        }
Beispiel #8
0
 public void DisplayEpisodes()
 {
     try
     {
         VM_VideoLocal vidLocal = DataContext as VM_VideoLocal;
         if (vidLocal != null)
         {
             lbEpisodes.ItemsSource = vidLocal.GetEpisodes();
         }
     }
     catch (Exception ex)
     {
         Utils.ShowErrorMessage(ex);
     }
 }
Beispiel #9
0
        public bool ResumeOrPlay(VM_VideoLocal fileToPlay)
        {
            try
            {
                curEpisode = null;


                if (fileToPlay.IsLocalOrStreaming() == null)
                {
                    Utils.DialogMsg("Error", "File could not be found!");
                    return(false);
                }
                current = fileToPlay;

                BaseConfig.MyAnimeLog.Write("Getting time stopped for : {0}", fileToPlay.FileName);
                BaseConfig.MyAnimeLog.Write("Time stopped for : {0} - {1}", fileToPlay.FileName, fileToPlay.ResumePosition / 1000);


                #region Ask user to Resume
                _timeMovieStopped = (int)(fileToPlay.ResumePosition / 1000);
                if (_timeMovieStopped > 0)
                {
                    GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);

                    if (null != dlgYesNo)
                    {
                        dlgYesNo.SetHeading(GUILocalizeStrings.Get(900));                         //resume movie?
                        dlgYesNo.SetLine(1, fileToPlay.FileName);
                        dlgYesNo.SetLine(2, GUILocalizeStrings.Get(936) + " " + MediaPortal.Util.Utils.SecondsToHMSString(TimeSpan.FromMilliseconds(fileToPlay.ResumePosition)));
                        dlgYesNo.SetDefaultToYes(true);
                        dlgYesNo.DoModal(GUIWindowManager.ActiveWindow);
                        if (!dlgYesNo.IsConfirmed)                         // reset resume data in DB
                        {
                            _timeMovieStopped = 0;
                        }
                    }
                }
                #endregion

                Play(_timeMovieStopped, fileToPlay.DefaultAudioLanguage, fileToPlay.DefaultSubtitleLanguage);
                return(true);
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write("Error inResumeOrPlay : {0}", ex.ToString());
            }
            return(false);
        }
Beispiel #10
0
        private void CommandBinding_IgnoreFile(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                Window parentWindow = Window.GetWindow(this);

                object obj = e.Parameter;
                if (obj == null)
                {
                    return;
                }

                if (obj.GetType() == typeof(VM_VideoLocal))
                {
                    VM_VideoLocal vid = obj as VM_VideoLocal;
                    EnableDisableControls(false);

                    string result = VM_ShokoServer.Instance.ShokoServices.SetIgnoreStatusOnFile(vid.VideoLocalID, true);
                    if (result.Length > 0)
                    {
                        MessageBox.Show(result, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        RefreshUnrecognisedFiles();
                    }
                }
                if (obj.GetType() == typeof(MultipleVideos))
                {
                    MultipleVideos mv = obj as MultipleVideos;
                    foreach (int id in mv.VideoLocalIDs)
                    {
                        string result = VM_ShokoServer.Instance.ShokoServices.SetIgnoreStatusOnFile(id, true);
                        if (result.Length > 0)
                        {
                            MessageBox.Show(result, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    RefreshUnrecognisedFiles();
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }

            EnableDisableControls(true);
        }
        void workerAvdump_DoWork(object sender, DoWorkEventArgs e)
        {
            VM_VideoLocal vid = e.Argument as VM_VideoLocal;

            //Create process
            Process pProcess = new Process();

            //strCommand is path and file name of command to run
            string appPath  = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string filePath = Path.Combine(appPath, "AVDump2CL.exe");

            if (!File.Exists(filePath))
            {
                e.Result = "Could not find AvDump2 CLI: " + filePath;
                return;
            }
            if (string.IsNullOrEmpty(vid.GetLocalFileSystemFullPath()))
            {
                e.Result = "Unable to map video file : " + vid.FileName;
                return;
            }
            if (!File.Exists(vid.GetLocalFileSystemFullPath()))
            {
                e.Result = "Could not find Video File: " + vid.GetLocalFileSystemFullPath();
                return;
            }

            pProcess.StartInfo.FileName = filePath;

            //strCommandParameters are parameters to pass to program
            string fileName = (char)34 + vid.GetLocalFileSystemFullPath() + (char)34;

            pProcess.StartInfo.Arguments =
                $@" --Auth={VM_ShokoServer.Instance.AniDB_Username}:{VM_ShokoServer.Instance.AniDB_AVDumpKey} --LPort={VM_ShokoServer.Instance.AniDB_AVDumpClientPort} --PrintEd2kLink -t {fileName}";

            pProcess.StartInfo.UseShellExecute        = false;
            pProcess.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            pProcess.StartInfo.RedirectStandardOutput = true;
            pProcess.StartInfo.CreateNoWindow         = true;
            pProcess.Start();
            string strOutput = pProcess.StandardOutput.ReadToEnd();

            //Wait for process to finish
            pProcess.WaitForExit();

            e.Result = strOutput;
        }
Beispiel #12
0
        void lbVideos_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // get detailed video, episode and series info
            ccDetail.Content       = null;
            ccSeriesDetail.Content = null;
            if (lbVideos.SelectedItems.Count == 0)
            {
                return;
            }
            if (lbVideos.SelectedItem == null)
            {
                return;
            }

            VM_VideoLocal vid = lbVideos.SelectedItem as VM_VideoLocal;

            displayingVidID = vid.VideoLocalID;
            EnableDisableControls(false);

            try
            {
                Cursor = Cursors.Wait;

                ccDetail.Content = vid;

                // get the episode(s)
                VM_AnimeEpisode_User ep = (VM_AnimeEpisode_User)VM_ShokoServer.Instance.ShokoServices.GetEpisodesForFile(vid.VideoLocalID, VM_ShokoServer.Instance.CurrentUser.JMMUserID).FirstOrDefault();


                if (ep != null)
                {
                    ccSeriesDetail.Content = ep;
                }

                Cursor = Cursors.Arrow;
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
            finally
            {
                Cursor = Cursors.Arrow;
                EnableDisableControls(true);
            }
        }
Beispiel #13
0
        protected override void OnShowContextMenu()
        {
            try
            {
                GUIListItem currentitem = m_Facade.SelectedListItem;
                if (currentitem == null)
                {
                    return;
                }

                VM_VideoLocal vid = currentitem.TVTag as VM_VideoLocal;
                if (vid == null)
                {
                    return;
                }
                ContextMenu cmenu = new ContextMenu(Translation.FileOptions);
                cmenu.AddAction(Translation.PlayFile, () => MainWindow.vidHandler.ResumeOrPlay(vid));
                cmenu.AddAction(Translation.RehashFile, () =>
                {
                    VM_ShokoServer.Instance.ShokoServices.RehashFile(vid.VideoLocalID);
                    DialogProcess();
                });
                cmenu.AddAction(Translation.IgnoreFile, () =>
                {
                    VM_ShokoServer.Instance.ShokoServices.SetIgnoreStatusOnFile(vid.VideoLocalID, true);
                    RefreshUnlinkedFiles();
                });
                cmenu.AddAction(Translation.DeleteFileFromDisk, () =>
                {
                    if (!Utils.DialogConfirm(Translation.AreYouSureYouWantDeleteFile))
                    {
                        return;
                    }
                    foreach (CL_VideoLocal_Place p in vid.Places)
                    {
                        VM_ShokoServer.Instance.ShokoServices.DeleteVideoLocalPlaceAndFile(p.VideoLocal_Place_ID);
                    }
                    RefreshUnlinkedFiles();
                });
                cmenu.Show();
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write("Error in menu: {0}", ex);
            }
        }
Beispiel #14
0
 public void PlayVideo(VM_VideoLocal vid, bool forcebegining)
 {
     try
     {
         IVideoPlayer player = ResolvePlayer();
         if (player == null)
         {
             throw new Exception("Please configure a Video Player");
         }
         VideoInfo info = vid.ToVideoInfo(forcebegining);
         recentlyPlayedFiles[info.VideoLocalId] = info;
         player.Play(info);
     }
     catch (Exception ex)
     {
         Utils.ShowErrorMessage(ex);
     }
 }
        private bool FileSearchFilter(object obj)
        {
            VM_VideoLocal vid = obj as VM_VideoLocal;

            if (vid == null)
            {
                return(true);
            }
            foreach (CL_VideoLocal_Place n in vid.Places)
            {
                int index = n.FilePath.IndexOf(txtFileSearch.Text.Trim(), 0,
                                               StringComparison.InvariantCultureIgnoreCase);
                if (index > -1)
                {
                    return(true);
                }
            }
            return(false);
        }
        private void CommandBinding_RescanFile(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                Window parentWindow = Window.GetWindow(this);

                object obj = e.Parameter;
                if (obj == null)
                {
                    return;
                }

                if (obj.GetType() == typeof(VM_VideoLocal))
                {
                    VM_VideoLocal vid = obj as VM_VideoLocal;
                    EnableDisableControls(false);
                    if (Commons.Extensions.Models.IsHashed(vid))
                    {
                        VM_ShokoServer.Instance.ShokoServices.RescanFile(vid.VideoLocalID);
                    }
                }
                if (obj.GetType() == typeof(MultipleVideos))
                {
                    MultipleVideos mv = obj as MultipleVideos;
                    foreach (VM_VideoLocal v in mv.VideoLocals)
                    {
                        if (Commons.Extensions.Models.IsHashed(v))
                        {
                            VM_ShokoServer.Instance.ShokoServices.RescanFile(v.VideoLocalID);
                        }
                    }
                }

                MessageBox.Show(Shoko.Commons.Properties.Resources.MSG_INFO_AddedQueueCmds, Shoko.Commons.Properties.Resources.Done, MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }

            EnableDisableControls(true);
        }
        private void CommandBinding_DeleteLink(object sender, ExecutedRoutedEventArgs e)
        {
            Window parentWindow = Window.GetWindow(this);

            object obj = e.Parameter;

            if (obj == null)
            {
                return;
            }

            try
            {
                if (obj.GetType() == typeof(VM_AnimeEpisode_User))
                {
                    VM_AnimeEpisode_User ep  = obj as VM_AnimeEpisode_User;
                    VM_VideoLocal        vid = DataContext as VM_VideoLocal;
                    if (ep == null || vid == null)
                    {
                        MessageBox.Show("ep or vid is null. This is not okay, so report it.", Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    string res = VM_ShokoServer.Instance.ShokoServices.RemoveAssociationOnFile(vid.VideoLocalID, ep.AniDB_EpisodeID);
                    if (res.Length > 0)
                    {
                        MessageBox.Show(res, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        VM_MainListHelper.Instance.UpdateHeirarchy(ep);
                        DisplayEpisodes();
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Beispiel #18
0
        private void CommandBinding_PlayVideo(object sender, ExecutedRoutedEventArgs e)
        {
            Window parentWindow = Window.GetWindow(this);

            object obj = e.Parameter;

            if (obj == null)
            {
                return;
            }

            try
            {
                if (obj.GetType() == typeof(VM_VideoLocal))
                {
                    VM_VideoLocal vid   = obj as VM_VideoLocal;
                    bool          force = true;
                    if (MainWindow.videoHandler.DefaultPlayer.Player.ToString() !=
                        Enum.GetName(typeof(VideoPlayer), VideoPlayer.WindowsDefault))
                    {
                        if (vid.ResumePosition > 0)
                        {
                            AskResumeVideo ask = new AskResumeVideo(vid.ResumePosition);
                            ask.Owner = Window.GetWindow(this);
                            if (ask.ShowDialog() == true)
                            {
                                force = false;
                            }
                        }
                    }
                    MainWindow.videoHandler.PlayVideo(vid, force);
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
        void lbVideos_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                ccDetail.Content         = null;
                ccDetailMultiple.Content = null;

                OneVideoSelected       = lbVideos.SelectedItems.Count == 1;
                MultipleVideosSelected = lbVideos.SelectedItems.Count > 1;

                // if only one video selected
                if (OneVideoSelected)
                {
                    VM_VideoLocal vid = lbVideos.SelectedItem as VM_VideoLocal;
                    ccDetail.Content = vid;
                }

                // if only one video selected
                if (MultipleVideosSelected)
                {
                    MultipleVideos mv = new MultipleVideos();
                    mv.SelectedCount = lbVideos.SelectedItems.Count;
                    mv.VideoLocalIDs = new List <int>();

                    foreach (object obj in lbVideos.SelectedItems)
                    {
                        VM_VideoLocal vid = obj as VM_VideoLocal;
                        mv.VideoLocalIDs.Add(vid.VideoLocalID);
                    }

                    ccDetailMultiple.Content = mv;
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Beispiel #20
0
        public override bool OnMessage(GUIMessage message)
        {
            switch (message.Message)
            {
            case GUIMessage.MessageType.GUI_MSG_ITEM_FOCUS_CHANGED:
            {
                int iControl = message.SenderControlId;
                if (iControl == m_Facade.GetID)
                {
                    GUIListItem item = m_Facade.SelectedListItem;

                    if (item == null || item.TVTag == null)
                    {
                        return(true);
                    }

                    // unlinked files
                    if (item.TVTag.GetType() == typeof(VM_VideoLocal))
                    {
                        VM_VideoLocal vid = item.TVTag as VM_VideoLocal;
                        if (vid != null)
                        {
                            SetGUIProperty(GuiProperty.Utilities_UnlinkedFile_Folder, vid.Places.FirstOrDefault()?.ImportFolder.ImportFolderLocation ?? string.Empty);
                            SetGUIProperty(GuiProperty.Utilities_UnlinkedFile_FileName, vid.FileName);
                            SetGUIProperty(GuiProperty.Utilities_UnlinkedFile_Size, Utils.FormatFileSize(vid.FileSize));
                            SetGUIProperty(GuiProperty.Utilities_UnlinkedFile_Hash, vid.Hash);
                        }
                    }
                }
            }

                return(true);

            default:
                return(base.OnMessage(message));
            }
        }
Beispiel #21
0
        private void CommandBinding_AvdumpFile(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                MainWindow MainWindow = (MainWindow)Window.GetWindow(this);

                object obj = e.Parameter;
                if (obj == null)
                {
                    return;
                }

                if (obj.GetType() == typeof(VM_AnimeEpisode_User))
                {
                    VM_AnimeEpisode_User ep  = obj as VM_AnimeEpisode_User;
                    VM_VideoLocal        vid = DataContext as VM_VideoLocal;
                    MainWindow.ShowPinnedFileAvDump(vid);
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Beispiel #22
0
        private void CommandBinding_DeleteFile(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                Window parentWindow = Window.GetWindow(this);

                object obj = e.Parameter;
                if (obj == null)
                {
                    return;
                }

                if (obj.GetType() == typeof(VM_VideoLocal))
                {
                    VM_VideoLocal vid = obj as VM_VideoLocal;

                    AskDeleteFile dlg = new AskDeleteFile(string.Format(Shoko.Commons.Properties.Resources.DeleteFile_Title, vid.FileName),
                                                          string.Format(Shoko.Commons.Properties.Resources.Unrecognized_ConfirmDelete, vid.FileName) + "\r\n\r\n" + Shoko.Commons.Properties.Resources.DeleteFile_Confirm,
                                                          vid.Places);
                    dlg.Owner = Window.GetWindow(this);
                    bool?res = dlg.ShowDialog();
                    if (res.HasValue && res.Value)
                    {
                        string tresult = string.Empty;
                        Cursor = Cursors.Wait;
                        foreach (CL_VideoLocal_Place lv in dlg.Selected)
                        {
                            string result =
                                VM_ShokoServer.Instance.ShokoServices.DeleteVideoLocalPlaceAndFile(
                                    lv.VideoLocal_Place_ID);
                            if (result.Length > 0)
                            {
                                tresult += result + "\r\n";
                            }
                        }
                        if (!string.IsNullOrEmpty(tresult))
                        {
                            MessageBox.Show(tresult, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK,
                                            MessageBoxImage.Error);
                        }
                        RefreshUnrecognisedFiles();
                    }
                }
                if (obj.GetType() == typeof(MultipleVideos))
                {
                    MultipleVideos mv  = obj as MultipleVideos;
                    AskDeleteFile  dlg = new AskDeleteFile(Shoko.Commons.Properties.Resources.DeleteFile_Multiple,
                                                           Shoko.Commons.Properties.Resources.Unrecognized_DeleteSelected + "\r\n\r\n" + Shoko.Commons.Properties.Resources.DeleteFile_Confirm,
                                                           mv.VideoLocals.SelectMany(a => a.Places).ToList());
                    dlg.Owner = Window.GetWindow(this);
                    bool?res = dlg.ShowDialog();
                    if (res.HasValue && res.Value)
                    {
                        string tresult = string.Empty;
                        Cursor = Cursors.Wait;
                        foreach (CL_VideoLocal_Place lv in dlg.Selected)
                        {
                            string result = VM_ShokoServer.Instance.ShokoServices.DeleteVideoLocalPlaceAndFile(lv.VideoLocal_Place_ID);
                            if (result.Length > 0)
                            {
                                tresult += result + "\r\n";
                            }
                        }
                        if (!string.IsNullOrEmpty(tresult))
                        {
                            MessageBox.Show(tresult, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        RefreshUnrecognisedFiles();
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
                RefreshUnrecognisedFiles();
            }
            finally
            {
                Cursor = Cursors.Arrow;
            }
        }
Beispiel #23
0
        void lbVideos_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // get detailed video, episode and series info
            if (lbVideos.SelectedItems.Count == 0)
            {
                ccDetail.Content       = null;
                ccSeriesDetail.Content = null;
                OneVideoSelected       = false;
                MultipleVideosSelected = false;
                return;
            }

            if (lbVideos.SelectedItems.Count == 1)
            {
                VM_VideoLocal vid = lbVideos.SelectedItem as VM_VideoLocal;
                OneVideoSelected       = true;
                MultipleVideosSelected = false;
                displayingVidID        = vid.VideoLocalID;
                EnableDisableControls(false);

                try
                {
                    Cursor = Cursors.Wait;

                    ccDetail.Content = vid;

                    // get the episode(s)
                    VM_AnimeEpisode_User ep = (VM_AnimeEpisode_User)VM_ShokoServer.Instance.ShokoServices
                                              .GetEpisodesForFile(vid.VideoLocalID, VM_ShokoServer.Instance.CurrentUser.JMMUserID)
                                              .FirstOrDefault();

                    // whether it's null or not
                    ccSeriesDetail.Content = ep;

                    Cursor = Cursors.Arrow;
                }
                catch (Exception ex)
                {
                    Utils.ShowErrorMessage(ex);
                }
                finally
                {
                    Cursor = Cursors.Arrow;
                    EnableDisableControls(true);
                }
            }
            else
            {
                try
                {
                    Cursor = Cursors.Wait;
                    var vids = lbVideos.SelectedItems.Cast <VM_VideoLocal>().ToList();
                    OneVideoSelected       = false;
                    MultipleVideosSelected = true;
                    MultipleVideos mv = new MultipleVideos();
                    mv.SelectedCount = vids.Count;
                    mv.VideoLocalIDs = new List <int>();
                    mv.VideoLocals   = new List <VM_VideoLocal>();

                    var eps = new List <VM_AnimeEpisode_User>();

                    foreach (var vid in vids)
                    {
                        mv.VideoLocalIDs.Add(vid.VideoLocalID);
                        mv.VideoLocals.Add(vid);
                        // get the episode(s)
                        VM_AnimeEpisode_User ep = (VM_AnimeEpisode_User)VM_ShokoServer.Instance.ShokoServices
                                                  .GetEpisodesForFile(vid.VideoLocalID, VM_ShokoServer.Instance.CurrentUser.JMMUserID)
                                                  .FirstOrDefault();
                        if (ep != null)
                        {
                            eps.Add(ep);
                        }
                    }

                    ccDetailMultiple.Content = mv;
                    displayingVidID          = vids.First().VideoLocalID;

                    if (eps.GroupBy(a => a?.AnimeSeriesID ?? 0).Distinct().Count(a => a.Key != 0) == 1)
                    {
                        ccSeriesDetail.Content = eps.FirstOrDefault();
                    }
                    else
                    {
                        ccSeriesDetail.Content = null;
                    }

                    Cursor = Cursors.Arrow;
                }
                catch (Exception ex)
                {
                    Utils.ShowErrorMessage(ex);
                }
                finally
                {
                    Cursor = Cursors.Arrow;
                    EnableDisableControls(true);
                }
            }
        }
Beispiel #24
0
        void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Window parentWindow = Window.GetWindow(this);

                // if only one video selected
                logger.Info($"[Unrecognizedfiles] Selected one video for linking = {OneVideoSelected}");
                logger.Info($"[Unrecognizedfiles] Multiple videos selected for linking = {MultipleVideosSelected}");

                if (OneVideoSelected)
                {
                    EnableDisableControls(false);

                    VM_VideoLocal vid = dgVideos.SelectedItem as VM_VideoLocal;
                    logger.Info($"[Unrecognizedfiles] Multiple type selected index = {cboMultiType.SelectedIndex}");
                    if (cboMultiType.SelectedIndex == 0)
                    {
                        // single file to multiple episodes
                        // eg a file is a double episode

                        int startEpNum = 0, endEpNum = 0;

                        int.TryParse(txtStartEpNum.Text, out startEpNum);
                        int.TryParse(txtEndEpNumSingle.Text, out endEpNum);

                        string result = "";
                        // make sure the episode range is valid
                        // make sure the last episode number is within the valid range
                        VM_AnimeSeries_User series = lbSeries.SelectedItem as VM_AnimeSeries_User;
                        logger.Info($"[Unrecognizedfiles] Selected series group: {series?.GroupName}");
                        logger.Info($"[Unrecognizedfiles] Selected start episode number: {startEpNum}");
                        logger.Info($"[Unrecognizedfiles] Selected end episode number: {endEpNum}");
                        logger.Info($"[Unrecognizedfiles] Series last regular episode number: {series?.LatestRegularEpisodeNumber}");

                        if (series?.LatestRegularEpisodeNumber < endEpNum ||
                            startEpNum <= 0 && endEpNum <= 0 && endEpNum <= startEpNum)
                        {
                            // otherwise allow the user to refresh it from anidb
                            MessageBoxResult res = MessageBox.Show(
                                Shoko.Commons.Properties.Resources.MSG_ERR_InvalidEpGetAnime,
                                Shoko.Commons.Properties.Resources.Error, MessageBoxButton.YesNo,
                                MessageBoxImage.Exclamation);
                            if (res == MessageBoxResult.Yes)
                            {
                                result = VM_ShokoServer.Instance.ShokoServices.UpdateAnimeData(series.AniDB_ID);
                                if (result.Length > 0)
                                {
                                    MessageBox.Show(result, Shoko.Commons.Properties.Resources.Error,
                                                    MessageBoxButton.OK, MessageBoxImage.Error);
                                    EnableDisableControls(true);
                                    return;
                                }
                                else
                                {
                                    // check again
                                    if (series.LatestRegularEpisodeNumber < endEpNum)
                                    {
                                        MessageBox.Show(Shoko.Commons.Properties.Resources.MSG_ERR_InvalidEp,
                                                        Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK,
                                                        MessageBoxImage.Exclamation);
                                        EnableDisableControls(true);
                                        return;
                                    }
                                }
                            }
                            else
                            {
                                EnableDisableControls(true);
                                return;
                            }
                        }

                        logger.Info($"[Unrecognizedfiles] linking single video: {vid.FullPath} [{vid.VideoLocalID}] to series => {series.GroupName} [{series.AnimeSeriesID}] with episode range {startEpNum} - {endEpNum}");
                        result = VM_ShokoServer.Instance.ShokoServices.AssociateSingleFileWithMultipleEpisodes(
                            vid.VideoLocalID, series.AnimeSeriesID, startEpNum, endEpNum);

                        if (result.Length > 0)
                        {
                            logger.Error($"[Unrecognizedfiles] error occured during single file linking to multiple episodes: {result}");

                            MessageBox.Show(result, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK,
                                            MessageBoxImage.Error);
                        }
                    }
                    else
                    {
                        // single file to a single episode
                        VM_AnimeEpisode_User ep = cboEpisodes.SelectedItem as VM_AnimeEpisode_User;
                        logger.Info(
                            $"[Unrecognizedfiles] Linking single episode for anime: {ep?.AnimeName} | episodeNumbnerName {ep?.EpisodeNumberAndName} | videolocal: {vid?.VideoLocalID} | animeEpisodeID: {ep?.AnimeEpisodeID}");

                        string result =
                            VM_ShokoServer.Instance.ShokoServices.AssociateSingleFile(vid.VideoLocalID,
                                                                                      ep.AnimeEpisodeID);
                        if (result.Length > 0)
                        {
                            logger.Error($"[Unrecognizedfiles] error occured during episode linking: {result}");

                            MessageBox.Show(result, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK,
                                            MessageBoxImage.Error);
                        }
                        else
                        {
                            logger.Info("[Unrecognizedfiles] episode linked successfully");
                        }
                    }
                }

                // if multiple videos selected
                if (MultipleVideosSelected)
                {
                    int startEpNum = 0, endEpNum = 0;

                    int.TryParse(txtStartEpNum.Text, out startEpNum);

                    if (MultipleTypeRange)
                    {
                        endEpNum = startEpNum + dgVideos.SelectedItems.Count - 1;
                    }
                    else
                    {
                        endEpNum = startEpNum;
                    }

                    logger.Info(
                        $"[Unrecognizedfiles] Selected multiple episodeds for linking, range = {startEpNum} to {endEpNum}");
                    // make sure the last episode number is within the valid range
                    VM_AnimeSeries_User series = lbSeries.SelectedItem as VM_AnimeSeries_User;
                    if (series.LatestRegularEpisodeNumber < endEpNum && startEpNum > 0)
                    {
                        // otherwise allow the user to refresh it from anidb
                        MessageBoxResult res = MessageBox.Show(
                            Shoko.Commons.Properties.Resources.MSG_ERR_InvalidEpGetAnime,
                            Shoko.Commons.Properties.Resources.Error, MessageBoxButton.YesNo,
                            MessageBoxImage.Exclamation);
                        if (res == MessageBoxResult.Yes)
                        {
                            string result = VM_ShokoServer.Instance.ShokoServices.UpdateAnimeData(series.AniDB_ID);
                            if (result.Length > 0)
                            {
                                MessageBox.Show(result, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK,
                                                MessageBoxImage.Error);
                                EnableDisableControls(true);
                                return;
                            }
                            // check again
                            if (series.LatestRegularEpisodeNumber < endEpNum)
                            {
                                MessageBox.Show(Shoko.Commons.Properties.Resources.MSG_ERR_InvalidEp,
                                                Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK,
                                                MessageBoxImage.Exclamation);
                                EnableDisableControls(true);
                                return;
                            }
                        }
                        else
                        {
                            EnableDisableControls(true);
                            return;
                        }
                    }

                    // get all the selected videos
                    logger.Info($"[Unrecognizedfiles] linking {dgVideos.SelectedItems.Count} videos");
                    List <int> vidIDs = new List <int>();
                    foreach (object obj in dgVideos.SelectedItems)
                    {
                        VM_VideoLocal vid = obj as VM_VideoLocal;
                        vidIDs.Add(vid.VideoLocalID);
                        logger.Info(
                            $"[Unrecognizedfiles] Gonna link {vid.FullPath} | {vid.VideoLocalID} => {series?.GroupName}");
                    }

                    string response = VM_ShokoServer.Instance.ShokoServices.AssociateMultipleFiles(vidIDs,
                                                                                                   series.AnimeSeriesID, startEpNum, MultipleTypeSingle);
                    if (response.Length > 0)
                    {
                        logger.Error($"[Unrecognizedfiles] Error occured during multiple episodes linking: {response}");

                        MessageBox.Show(response, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                    }
                    else
                    {
                        logger.Info("[Unrecognizedfiles] Multiple episodes linked successfully");
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
            finally
            {
                EnableDisableControls(true);
            }
        }
        void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Window parentWindow = Window.GetWindow(this);

                // if only one video selected
                if (OneVideoSelected)
                {
                    EnableDisableControls(false);

                    VM_VideoLocal vid = dgVideos.SelectedItem as VM_VideoLocal;

                    if (cboMultiType.SelectedIndex == 0)
                    {
                        // single file to multiple episodes
                        // eg a file is a double episode

                        int startEpNum = 0, endEpNum = 0;

                        int.TryParse(txtStartEpNum.Text, out startEpNum);
                        int.TryParse(txtEndEpNumSingle.Text, out endEpNum);

                        string result = "";
                        // make sure the episode range is valid
                        // make sure the last episode number is within the valid range
                        VM_AnimeSeries_User series = lbSeries.SelectedItem as VM_AnimeSeries_User;
                        if (series.LatestRegularEpisodeNumber < endEpNum || startEpNum <= 0 && endEpNum <= 0 && endEpNum <= startEpNum)
                        {
                            // otherwise allow the user to refresh it from anidb
                            MessageBoxResult res = MessageBox.Show(Shoko.Commons.Properties.Resources.MSG_ERR_InvalidEpGetAnime, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
                            if (res == MessageBoxResult.Yes)
                            {
                                result = VM_ShokoServer.Instance.ShokoServices.UpdateAnimeData(series.AniDB_ID);
                                if (result.Length > 0)
                                {
                                    MessageBox.Show(result, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                                    EnableDisableControls(true);
                                    return;
                                }
                                else
                                {
                                    // check again
                                    if (series.LatestRegularEpisodeNumber < endEpNum)
                                    {
                                        MessageBox.Show(Shoko.Commons.Properties.Resources.MSG_ERR_InvalidEp, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                                        EnableDisableControls(true);
                                        return;
                                    }
                                }
                            }
                            else
                            {
                                EnableDisableControls(true);
                                return;
                            }
                        }

                        result = VM_ShokoServer.Instance.ShokoServices.AssociateSingleFileWithMultipleEpisodes(vid.VideoLocalID, series.AnimeSeriesID, startEpNum, endEpNum);
                        if (result.Length > 0)
                        {
                            MessageBox.Show(result, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else
                    {
                        // single file to a single episode
                        VM_AnimeEpisode_User ep = cboEpisodes.SelectedItem as VM_AnimeEpisode_User;

                        string result = VM_ShokoServer.Instance.ShokoServices.AssociateSingleFile(vid.VideoLocalID, ep.AnimeEpisodeID);
                        if (result.Length > 0)
                        {
                            MessageBox.Show(result, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                }

                // if multiple videos selected
                if (MultipleVideosSelected)
                {
                    int startEpNum = 0, endEpNum = 0;

                    int.TryParse(txtStartEpNum.Text, out startEpNum);

                    if (MultipleTypeRange)
                    {
                        endEpNum = startEpNum + dgVideos.SelectedItems.Count - 1;
                    }
                    else
                    {
                        endEpNum = startEpNum;
                    }

                    // make sure the last episode number is within the valid range
                    VM_AnimeSeries_User series = lbSeries.SelectedItem as VM_AnimeSeries_User;
                    if (series.LatestRegularEpisodeNumber < endEpNum && startEpNum > 0)
                    {
                        // otherwise allow the user to refresh it from anidb
                        MessageBoxResult res = MessageBox.Show(Shoko.Commons.Properties.Resources.MSG_ERR_InvalidEpGetAnime, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
                        if (res == MessageBoxResult.Yes)
                        {
                            string result = VM_ShokoServer.Instance.ShokoServices.UpdateAnimeData(series.AniDB_ID);
                            if (result.Length > 0)
                            {
                                MessageBox.Show(result, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                                EnableDisableControls(true);
                                return;
                            }
                            // check again
                            if (series.LatestRegularEpisodeNumber < endEpNum)
                            {
                                MessageBox.Show(Shoko.Commons.Properties.Resources.MSG_ERR_InvalidEp, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                                EnableDisableControls(true);
                                return;
                            }
                        }
                        else
                        {
                            EnableDisableControls(true);
                            return;
                        }
                    }

                    // get all the selected videos
                    List <int> vidIDs = new List <int>();
                    foreach (object obj in dgVideos.SelectedItems)
                    {
                        VM_VideoLocal vid = obj as VM_VideoLocal;
                        vidIDs.Add(vid.VideoLocalID);
                    }

                    string msg = VM_ShokoServer.Instance.ShokoServices.AssociateMultipleFiles(vidIDs, series.AnimeSeriesID, startEpNum, MultipleTypeSingle);
                    if (msg.Length > 0)
                    {
                        MessageBox.Show(msg, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
            EnableDisableControls(true);
        }