Exemplo n.º 1
0
		public void PlayVideo(VideoDetailedVM vid)
		{
			try
			{
				recentlyPlayedFiles[vid.VideoLocalID] = vid;
				Process.Start(new ProcessStartInfo(vid.FullPath));
			}
			catch (Exception ex)
			{
				Utils.ShowErrorMessage(ex);
			}
		}
Exemplo n.º 2
0
 public VideoWatchedEventArgs(int videoLocalID, VideoDetailedVM vid)
 {
     this.VideoLocalID = videoLocalID;
     this.VideoLocal = vid;
 }
Exemplo n.º 3
0
 public void PlayVideo(VideoDetailedVM vid)
 {
     try
     {
         defaultplayer = UserSettingsVM.Instance.DefaultPlayer_GroupList.ToString();
         switch (defaultplayer)
         {
             case "1":
                 defaultplayer = "mpc-hc";
                 break;
             case "2":
                 defaultplayer = "PotPlayerMini";
                 break;
             case "3":
                 defaultplayer = "vlc";
                 break;
             default:
                 defaultplayer = "vlc";
                 break;
         }
         recentlyPlayedFiles[vid.VideoLocalID] = vid;
         if (vid.FullPath.Contains("http:")) {
             try
             {
                 Process.Start(defaultplayer, '"' + vid.FullPath.Replace(@"\", "/") + '"');
             }
             catch(Exception e)
             {
                 Process.Start(defaultplayer+"64", '"' + vid.FullPath.Replace(@"\", "/") + '"');
             }
         }
         else
         {
             try
             {
                 Process.Start(defaultplayer, '"' + vid.FullPath + '"');
             }
             catch (Exception e)
             {
                 Process.Start(defaultplayer + "64", '"' + vid.FullPath.Replace(@"\", "/") + '"');
             }
         }
         defaultplayer = UserSettingsVM.Instance.DefaultPlayer_GroupList.ToString();
     }
     catch (Exception ex)
     {
         Utils.ShowErrorMessage(ex);
     }
 }
Exemplo n.º 4
0
 public void PlayVideo(VideoDetailedVM 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);
     }
 }
Exemplo n.º 5
0
        private void CommandBinding_ToggleWatchedStatus(object sender, ExecutedRoutedEventArgs e)
        {
            object obj = e.Parameter;

            if (obj == null)
            {
                return;
            }

            this.Cursor = Cursors.Wait;

            try
            {
                Window        parentWindow = Window.GetWindow(this);
                AnimeSeriesVM ser          = null;
                bool          newStatus    = false;

                if (obj.GetType() == typeof(VideoDetailedVM))
                {
                    VideoDetailedVM vid = obj as VideoDetailedVM;
                    newStatus = !vid.Watched;
                    JMMServerVM.Instance.clientBinaryHTTP.ToggleWatchedStatusOnVideo(vid.VideoLocalID, newStatus, JMMServerVM.Instance.CurrentUser.JMMUserID.Value);

                    MainListHelperVM.Instance.UpdateHeirarchy(vid);

                    ser = MainListHelperVM.Instance.GetSeriesForVideo(vid.VideoLocalID);
                }

                if (obj.GetType() == typeof(AnimeEpisodeVM))
                {
                    AnimeEpisodeVM ep = obj as AnimeEpisodeVM;
                    newStatus = !ep.Watched;

                    JMMServerBinary.Contract_ToggleWatchedStatusOnEpisode_Response response = JMMServerVM.Instance.clientBinaryHTTP.ToggleWatchedStatusOnEpisode(ep.AnimeEpisodeID,
                                                                                                                                                                 newStatus, JMMServerVM.Instance.CurrentUser.JMMUserID.Value);
                    if (!string.IsNullOrEmpty(response.ErrorMessage))
                    {
                        MessageBox.Show(response.ErrorMessage, JMMClient.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    MainListHelperVM.Instance.UpdateHeirarchy(response.AnimeEpisode);

                    ser = MainListHelperVM.Instance.GetSeriesForEpisode(ep);
                }

                RefreshData(true, true, false);
                if (newStatus == true && ser != null)
                {
                    Utils.PromptToRateSeries(ser, parentWindow);
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        }
Exemplo n.º 6
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(AnimeEpisodeDisplayVM))
                {
                    AnimeEpisodeDisplayVM ep = obj as AnimeEpisodeDisplayVM;

                    if (ep.FilesForEpisode.Count == 1)
                    {
                        bool force = true;
                        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)
                        {
                            VideoDetailedVM vid = MainWindow.videoHandler.GetAutoFileForEpisode(ep);
                            if (vid != null)
                            {
                                bool force = true;
                                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);
                            bool?result = frm.ShowDialog();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Exemplo n.º 7
0
        void btnPlayNextEp_Click(object sender, RoutedEventArgs e)
        {
            if (UnwatchedEpisodes.Count == 0)
            {
                return;
            }

            try
            {
                AnimeEpisodeVM ep = UnwatchedEpisodes[0];

                if (ep.IsWatched == 1)
                {
                    if (UnwatchedEpisodes.Count == 1)
                    {
                        ep = UnwatchedEpisodes[1];
                    }
                    else
                    {
                        return;
                    }
                }

                if (ep.FilesForEpisode.Count == 1)
                {
                    bool force = true;
                    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)
                    {
                        VideoDetailedVM vid = MainWindow.videoHandler.GetAutoFileForEpisode(ep);
                        if (vid != null)
                        {
                            bool force = true;
                            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
                    {
                        MainWindow mainwdw = (MainWindow)Window.GetWindow(this);

                        PlayVideosForEpisodeForm frm = new PlayVideosForEpisodeForm();
                        frm.Owner = mainwdw;
                        frm.Init(ep);
                        bool?result = frm.ShowDialog();
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
        public void Init(int animeID, GroupFileSummaryVM gfs)
        {
            this.Cursor = Cursors.Wait;

            GroupFileSummary = gfs;
            AnimeID = animeID;

            // get the videos
            try
            {
                JMMServerVM.Instance.RefreshCloudAccounts();
                dict = JMMServerVM.Instance.FolderProviders.ToDictionary(a => a.CloudID ?? 0, a => new Tuple<string, BitmapImage>(a.Provider, a.Icon));
                chks = new Dictionary<string, bool>();
                Dictionary<string, BitmapImage> types = new Dictionary<string, BitmapImage>();

                List<JMMServerBinary.Contract_VideoDetailed> vidContracts = JMMServerVM.Instance.clientBinaryHTTP.GetFilesByGroup(AnimeID,
                    GroupFileSummary.GroupName, JMMServerVM.Instance.CurrentUser.JMMUserID.Value);
                vids = new List<VideoDetailedVM>();
                foreach (JMMServerBinary.Contract_VideoDetailed contract in vidContracts)
                {
                    VideoDetailedVM vid = new VideoDetailedVM(contract);
                    foreach (VideoLocal_PlaceVM vv in vid.Places)
                    {
                        Tuple<string, BitmapImage> tup = dict[vv.ImportFolder.CloudID ?? 0];
                        if (!types.ContainsKey(tup.Item1))
                            types.Add(tup.Item1, tup.Item2);
                    }
                    vids.Add(vid);
                }
                FileCount = vids.Count;
                lbFiles.ItemsSource = vids;

                GroupName = GroupFileSummary.GroupName;
                SummaryText = "";
                InitImportFolders(types);

            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        }
Exemplo n.º 9
0
 public VideoWatchedEventArgs(int videoLocalID, VideoDetailedVM vid)
 {
     this.VideoLocalID = videoLocalID;
     this.VideoLocal   = vid;
 }
Exemplo n.º 10
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(PlaylistItemVM))
                {
                    PlaylistItemVM pli = obj as PlaylistItemVM;

                    AnimeEpisodeVM ep = null;

                    if (pli.ItemType == JMMClient.PlaylistItemType.Episode)
                    {
                        ep = pli.PlaylistItem as AnimeEpisodeVM;
                    }
                    if (pli.ItemType == JMMClient.PlaylistItemType.AnimeSeries)
                    {
                        AnimeSeriesVM ser = pli.PlaylistItem as AnimeSeriesVM;
                        if (ser == null)
                        {
                            return;
                        }

                        JMMServerBinary.Contract_AnimeEpisode contract = JMMServerVM.Instance.clientBinaryHTTP.GetNextUnwatchedEpisode(ser.AnimeSeriesID.Value,
                                                                                                                                       JMMServerVM.Instance.CurrentUser.JMMUserID.Value);
                        if (contract != null)
                        {
                            ep = new AnimeEpisodeVM(contract);
                        }
                    }

                    if (ep == null)
                    {
                        return;
                    }
                    ep.SetTvDBInfo();

                    if (ep.FilesForEpisode.Count == 1)
                    {
                        MainWindow.videoHandler.PlayVideo(ep.FilesForEpisode[0]);
                    }
                    else if (ep.FilesForEpisode.Count > 1)
                    {
                        if (AppSettings.AutoFileSingleEpisode)
                        {
                            VideoDetailedVM vid = MainWindow.videoHandler.GetAutoFileForEpisode(ep);
                            if (vid != null)
                            {
                                MainWindow.videoHandler.PlayVideo(vid);
                            }
                        }
                        else
                        {
                            PlayVideosForEpisodeForm frm = new PlayVideosForEpisodeForm();
                            frm.Owner = parentWindow;
                            frm.Init(ep);
                            frm.ShowDialog();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Exemplo n.º 11
0
		public void Init(int animeID, GroupFileSummaryVM gfs)
		{
			this.Cursor = Cursors.Wait;

			GroupFileSummary = gfs;
			AnimeID = animeID;

			// get the videos
			try
			{
				List<JMMServerBinary.Contract_VideoDetailed> vidContracts = JMMServerVM.Instance.clientBinaryHTTP.GetFilesByGroup(AnimeID,
					GroupFileSummary.GroupName, JMMServerVM.Instance.CurrentUser.JMMUserID.Value);
				vids = new List<VideoDetailedVM>();
				foreach (JMMServerBinary.Contract_VideoDetailed contract in vidContracts)
				{
					VideoDetailedVM vid = new VideoDetailedVM(contract);
					vids.Add(vid);
				}
				FileCount = vids.Count;
				lbFiles.ItemsSource = vids;

				GroupName = GroupFileSummary.GroupName;
				SummaryText = "";
			}
			catch (Exception ex)
			{
				Utils.ShowErrorMessage(ex);
			}
			finally
			{
				this.Cursor = Cursors.Arrow;
			}

		}
Exemplo n.º 12
0
		public void Init(int animeID, GroupVideoQualityVM gvq)
		{
			this.Cursor = Cursors.Wait;

			GroupVideoQuality = gvq;
			AnimeID = animeID;

			// get the videos
			try
			{
				List<JMMServerBinary.Contract_VideoDetailed> vidContracts = JMMServerVM.Instance.clientBinaryHTTP.GetFilesByGroupAndResolution(AnimeID,
					GroupVideoQuality.GroupName, GroupVideoQuality.Resolution, GroupVideoQuality.VideoSource, GroupVideoQuality.VideoBitDepth, JMMServerVM.Instance.CurrentUser.JMMUserID.Value);
				vids = new List<VideoDetailedVM>();
				foreach (JMMServerBinary.Contract_VideoDetailed contract in vidContracts)
				{
					VideoDetailedVM vid = new VideoDetailedVM(contract);
					vids.Add(vid);
				}
				FileCount = vids.Count;
				lbFiles.ItemsSource = vids;

				GroupName = GroupVideoQuality.GroupName;
				SummaryText = string.Format("{0} - {1}", GroupVideoQuality.VideoSource, GroupVideoQuality.Resolution);
			}
			catch (Exception ex)
			{
				Utils.ShowErrorMessage(ex);
			}
			finally
			{
				this.Cursor = Cursors.Arrow;
			}

		}
Exemplo n.º 13
0
        void lbEpisodes_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            try
            {
                FrameworkElement ctrl = e.OriginalSource as FrameworkElement;

                if (ctrl == null || lbEpisodes.SelectedItem == null)
                {
                    return;
                }

                // The below while loop, etc. is used to make sure that the double click event is coming from an episode detail.
                // When the ListBox is responsible for rendering the scrollbar, it turns out that the scrollbar will also raise
                // double click events. So we'll see if the EpisodeDetail is an ancestor of the original source of the event
                bool srcWasListItem = false;

                while (ctrl != null)
                {
                    if (ctrl is EpisodeDetail)
                    {
                        srcWasListItem = true;
                        break;
                    }

                    ctrl = ctrl.Parent as FrameworkElement;
                }

                if (!srcWasListItem)
                {
                    return;                     // The source of the event wasn't an EpisodeDetail
                }
                AnimeEpisodeVM ep = lbEpisodes.SelectedItem as AnimeEpisodeVM;

                if (ep != null)
                {
                    ep.RefreshFilesForEpisode();

                    if (ep.FilesForEpisode.Count == 1)
                    {
                        MainWindow.videoHandler.PlayVideo(ep.FilesForEpisode[0]);
                    }
                    else if (ep.FilesForEpisode.Count > 1)
                    {
                        Window parentWindow = Window.GetWindow(this);

                        if (AppSettings.AutoFileSingleEpisode)
                        {
                            VideoDetailedVM vid = MainWindow.videoHandler.GetAutoFileForEpisode(ep);
                            if (vid != null)
                            {
                                MainWindow.videoHandler.PlayVideo(vid);
                            }
                        }
                        else
                        {
                            PlayVideosForEpisodeForm frm = new PlayVideosForEpisodeForm();
                            frm.Owner = parentWindow;
                            frm.Init(ep);
                            frm.ShowDialog();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex.ToString());
            }
        }
Exemplo n.º 14
0
        public void HandleFileChangeMPC(string filePath)
        {
            try
            {
                if (!AppSettings.VideoAutoSetWatched)
                {
                    return;
                }

                List <int> allFilesHeaders   = new List <int>();
                List <int> allFilesPositions = new List <int>();

                string[] lines = File.ReadAllLines(filePath);

                // really we only need to check the first file, but will do this just in case

                // MPC 1.3 and lower looks like this
                // File Name 0=M:\[ Anime to Watch - New ]\Arata Kangatari\[HorribleSubs] Arata Kangatari - 05 [720p].mkv
                // File Position 0=14251233493
                // File Name 1=M:\[ Anime to Watch - New ]\Hentai Ouji to Warawanai Neko\[gg]_Hentai_Ouji_to_Warawanai_Neko_-_04_[62E1DBF8].mkv
                // File Position 1=13688612500

                // MPC 1.6 and lower looks like this
                // File Name 0=M:\[ Anime to Watch - New ]\Arata Kangatari\[HorribleSubs] Arata Kangatari - 05 [720p].mkv
                // File Name 1=M:\[ Anime to Watch - New ]\Hentai Ouji to Warawanai Neko\[gg]_Hentai_Ouji_to_Warawanai_Neko_-_04_[62E1DBF8].mkv
                // File Position 0=14251233493
                // File Position 1=13688612500

                // get file name header lines
                string prefixHeader = string.Format("File Name ");
                for (int i = 0; i < lines.Length; i++)
                {
                    string line = lines[i];

                    if (line.StartsWith(prefixHeader, StringComparison.InvariantCultureIgnoreCase))
                    {
                        allFilesHeaders.Add(i);
                    }

                    if (allFilesHeaders.Count == 20)
                    {
                        break;
                    }
                }

                if (allFilesHeaders.Count == 0)
                {
                    return;
                }

                string prefixPos = string.Format("File Position ");
                for (int i = 0; i < lines.Length; i++)
                {
                    string line = lines[i];

                    if (line.StartsWith(prefixPos, StringComparison.InvariantCultureIgnoreCase))
                    {
                        allFilesPositions.Add(i);
                    }

                    if (allFilesPositions.Count == 20)
                    {
                        break;
                    }
                }

                Dictionary <string, string> filePositions = new Dictionary <string, string>();
                foreach (int lineNumber in allFilesHeaders)
                {
                    // find the last file played
                    string fileNameLine = lines[lineNumber];

                    // find the number of this file
                    string temp     = fileNameLine.Trim().Replace(prefixHeader, "");
                    int    iPosTemp = temp.IndexOf("=");
                    if (iPosTemp < 0)
                    {
                        continue;
                    }

                    string fileNumber = temp.Substring(0, iPosTemp);

                    // now find the match play position line
                    string properPosLine = string.Empty;
                    foreach (int lineNumberPos in allFilesPositions)
                    {
                        string filePosLineTemp = lines[lineNumberPos];

                        // find the number of this file
                        string temp2     = filePosLineTemp.Trim().Replace(prefixPos, "");
                        int    iPosTemp2 = temp2.IndexOf("=");
                        if (iPosTemp2 < 0)
                        {
                            continue;
                        }

                        string fileNumber2 = temp2.Substring(0, iPosTemp2);
                        if (fileNumber.Equals(fileNumber2, StringComparison.InvariantCultureIgnoreCase))
                        {
                            properPosLine = filePosLineTemp;
                            break;
                        }
                    }

                    if (string.IsNullOrEmpty(properPosLine))
                    {
                        continue;
                    }

                    // extract the file name and position
                    int iPos1 = fileNameLine.IndexOf("=");
                    if (iPos1 < 0)
                    {
                        continue;
                    }

                    int iPos2 = properPosLine.IndexOf("=");

                    string fileName = fileNameLine.Substring(iPos1 + 1, fileNameLine.Length - iPos1 - 1);
                    string position = properPosLine.Substring(iPos2 + 1, properPosLine.Length - iPos2 - 1);

                    filePositions[fileName] = position;
                }

                // find all the files which have changed
                Dictionary <string, string> changedFilePositions = new Dictionary <string, string>();

                foreach (KeyValuePair <string, string> kvp in filePositions)
                {
                    changedFilePositions[kvp.Key] = kvp.Value;
                }

                // update the changed positions
                foreach (KeyValuePair <string, string> kvp in changedFilePositions)
                {
                    previousFilePositions[kvp.Key] = kvp.Value;
                }

                foreach (KeyValuePair <string, string> kvp in changedFilePositions)
                {
                    lastFileNameProcessed = kvp.Key;
                    lastPositionProcessed = kvp.Value;

                    long mpcPos = 0;
                    if (!long.TryParse(kvp.Value, out mpcPos))
                    {
                        continue;
                    }

                    // if mpcPos == 0, it means that file has finished played completely

                    // MPC position is in micro-seconds
                    // convert to milli-seconds
                    double mpcPosMS = (double)mpcPos / (double)10000;

                    foreach (KeyValuePair <int, VideoDetailedVM> kvpVid in recentlyPlayedFiles)
                    {
                        if (kvpVid.Value.FullPath.Equals(kvp.Key, StringComparison.InvariantCultureIgnoreCase))
                        {
                            // we don't care about files that are already watched
                            if (kvpVid.Value.Watched)
                            {
                                continue;
                            }

                            logger.Info(string.Format("Video position for {0} has changed to {1}", kvp.Key, kvp.Value));

                            // now check if this file is considered watched
                            double fileDurationMS = (double)kvpVid.Value.VideoInfo_Duration;

                            double progress = mpcPosMS / fileDurationMS * (double)100;
                            if (progress > (double)AppSettings.VideoWatchedPct || mpcPos == 0)
                            {
                                VideoDetailedVM vid = kvpVid.Value;

                                logger.Info(string.Format("Updating to watched from MPC: {0}", kvp.Key));

                                JMMServerVM.Instance.clientBinaryHTTP.ToggleWatchedStatusOnVideo(vid.VideoLocalID, true, JMMServerVM.Instance.CurrentUser.JMMUserID.Value);
                                MainListHelperVM.Instance.UpdateHeirarchy(vid);
                                MainListHelperVM.Instance.GetSeriesForVideo(vid.VideoLocalID);

                                //kvp.Value.VideoLocal_IsWatched = 1;
                                OnVideoWatchedEvent(new VideoWatchedEventArgs(vid.VideoLocalID, vid));

                                Debug.WriteLine("complete");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
        }
Exemplo n.º 15
0
        public void HandleFileChangePotPlayer(string filePath)
        {
            try
            {
                if (!AppSettings.VideoAutoSetWatched)
                {
                    return;
                }

                List <int> allFiles = new List <int>();

                string[] lines = File.ReadAllLines(filePath);

                bool foundSectionStart = false;
                bool foundSectionEnd   = false;

                for (int i = 0; i < lines.Length; i++)
                {
                    string line = lines[i];

                    if (line.ToLower().Contains("[rememberfiles]"))
                    {
                        foundSectionStart = true;
                    }

                    if (foundSectionStart && line.Trim().ToLower().StartsWith("[") && !line.ToLower().Contains("[rememberfiles]"))
                    {
                        foundSectionEnd = true;
                    }

                    if (foundSectionStart && !foundSectionEnd)
                    {
                        if (!line.ToLower().Contains("[rememberfiles]") && !string.IsNullOrEmpty(line))
                        {
                            allFiles.Add(i);
                        }
                    }
                }

                if (allFiles.Count == 0)
                {
                    return;
                }

                Dictionary <string, string> filePositions = new Dictionary <string, string>();
                foreach (int lineNumber in allFiles)
                {
                    // find the last file played
                    string fileNameLine = lines[lineNumber];

                    int iPos1 = fileNameLine.IndexOf("=");
                    int iPos2 = fileNameLine.IndexOf("=", iPos1 + 1);

                    if (iPos1 <= 0 || iPos2 <= 0)
                    {
                        continue;
                    }

                    string position = fileNameLine.Substring(iPos1 + 1, iPos2 - iPos1 - 1);
                    string fileName = fileNameLine.Substring(iPos2 + 1, fileNameLine.Length - iPos2 - 1);


                    filePositions[fileName] = position;
                }

                // find all the files which have changed
                Dictionary <string, string> changedFilePositions = new Dictionary <string, string>();

                foreach (KeyValuePair <string, string> kvp in filePositions)
                {
                    changedFilePositions[kvp.Key] = kvp.Value;
                }

                // update the changed positions
                foreach (KeyValuePair <string, string> kvp in changedFilePositions)
                {
                    previousFilePositions[kvp.Key] = kvp.Value;
                }

                foreach (KeyValuePair <string, string> kvp in changedFilePositions)
                {
                    lastFileNameProcessed = kvp.Key;
                    lastPositionProcessed = kvp.Value;

                    long mpcPos = 0;
                    if (!long.TryParse(kvp.Value, out mpcPos))
                    {
                        continue;
                    }

                    // if mpcPos == 0, it means that file has finished played completely

                    // MPC position is in micro-seconds
                    // convert to milli-seconds
                    //double mpcPosMS = (double)mpcPos / (double)10000;
                    double mpcPosMS = (double)mpcPos;

                    foreach (KeyValuePair <int, VideoDetailedVM> kvpVid in recentlyPlayedFiles)
                    {
                        if (kvpVid.Value.FullPath.Equals(kvp.Key, StringComparison.InvariantCultureIgnoreCase))
                        {
                            // we don't care about files that are already watched
                            if (kvpVid.Value.Watched)
                            {
                                continue;
                            }

                            logger.Info(string.Format("Video position for {0} has changed to {1}", kvp.Key, kvp.Value));

                            // now check if this file is considered watched
                            double fileDurationMS = (double)kvpVid.Value.VideoInfo_Duration;

                            double progress = mpcPosMS / fileDurationMS * (double)100;
                            if (progress > (double)AppSettings.VideoWatchedPct || mpcPos == 0)
                            {
                                VideoDetailedVM vid = kvpVid.Value;

                                logger.Info(string.Format("Updating to watched from MPC: {0}", kvp.Key));

                                JMMServerVM.Instance.clientBinaryHTTP.ToggleWatchedStatusOnVideo(vid.VideoLocalID, true, JMMServerVM.Instance.CurrentUser.JMMUserID.Value);
                                MainListHelperVM.Instance.UpdateHeirarchy(vid);
                                MainListHelperVM.Instance.GetSeriesForVideo(vid.VideoLocalID);

                                //kvp.Value.VideoLocal_IsWatched = 1;
                                OnVideoWatchedEvent(new VideoWatchedEventArgs(vid.VideoLocalID, vid));

                                Debug.WriteLine("complete");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
        }
Exemplo n.º 16
0
        private void FindChangedFiles(Dictionary <string, long> filePositions)
        {
            // find all the files which have changed
            Dictionary <string, long> changedFilePositions = new Dictionary <string, long>();

            foreach (KeyValuePair <string, long> kvp in filePositions)
            {
                changedFilePositions[kvp.Key] = kvp.Value;
            }

            // update the changed positions
            foreach (KeyValuePair <string, long> kvp in changedFilePositions)
            {
                previousFilePositions[kvp.Key] = kvp.Value.ToString();
            }

            foreach (KeyValuePair <string, long> kvp in changedFilePositions)
            {
                long mpcPosMS = kvp.Value;

                foreach (KeyValuePair <int, VideoDetailedVM> kvpVid in recentlyPlayedFiles)
                {
                    bool found =
                        (AppSettings.UseStreaming && kvpVid.Value.Media != null && kvpVid.Value.Media.Parts != null && kvpVid.Value.Media.Parts.Count > 0) ?
                        kvpVid.Value.Media.Parts[0].Key.Equals(kvp.Key, StringComparison.InvariantCultureIgnoreCase) :
                        kvpVid.Value.FullPath.Equals(Path.GetFullPath(kvp.Key), StringComparison.InvariantCultureIgnoreCase);

                    if (found)
                    {
                        // we don't care about files that are already watched
                        if (kvpVid.Value.Watched)
                        {
                            continue;
                        }

                        logger.Info(string.Format("Video position for {0} has changed to {1}", kvp.Key, kvp.Value));

                        // now check if this file is considered watched
                        double fileDurationMS = (double)kvpVid.Value.VideoInfo_Duration;

                        double progress = mpcPosMS / fileDurationMS * 100.0d;

                        if (progress > (double)AppSettings.VideoWatchedPct)
                        {
                            VideoDetailedVM vid = kvpVid.Value;

                            logger.Info(string.Format("Updating to watched by media player: {0}", kvp.Key));

                            JMMServerVM.Instance.clientBinaryHTTP.ToggleWatchedStatusOnVideo(vid.VideoLocalID, true, JMMServerVM.Instance.CurrentUser.JMMUserID.Value);
                            MainListHelperVM.Instance.UpdateHeirarchy(vid);
                            MainListHelperVM.Instance.GetSeriesForVideo(vid.VideoLocalID);

                            //kvp.Value.VideoLocal_IsWatched = 1;
                            OnVideoWatchedEvent(new VideoWatchedEventArgs(vid.VideoLocalID, vid));

                            Debug.WriteLine("complete");
                        }
                    }
                }
            }
        }