diff --git a/docs/Changelog.md b/docs/Changelog.md index e3305be..00ae62b 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -5,10 +5,18 @@ - New options `autofit-image` and `autofit-audio`, like autofit but used for image and audio files. Default 80. - New [auto-mode](https://github.com/stax76/mpv-scripts) script to use mpv and mpv.net as image viewer and audio player. - New support of the mpv option `snap-window`. +- New feature to show chapters in the command palette, see binding and menu definition below. - Fix long commands causing key bindings not visible in the command palette. - Fix script compatibility with mordenx and mpv-osc-tethys. - Fix borderless window not resizable with mouse. +input.conf changes: + +New: + +``` +Ctrl+c script-message-to mpvnet show-chapters #menu: View > Show Chapters +``` # 6.0.0.0 Beta (2022-06-05) diff --git a/docs/Manual.md b/docs/Manual.md index 2a9c048..e837343 100644 --- a/docs/Manual.md +++ b/docs/Manual.md @@ -298,6 +298,9 @@ Shows available audio devices in a message box. Shows available audio tracks in the command palette and allows to load the selected audio track. +### show-chapters +Shows chapters in the command palette. + ### show-command-palette Shows the command palette. diff --git a/src/Misc/Commands.cs b/src/Misc/Commands.cs index 1e6ccbe..19830fb 100644 --- a/src/Misc/Commands.cs +++ b/src/Misc/Commands.cs @@ -46,6 +46,7 @@ namespace mpvnet case "show-about": ShowDialog(typeof(AboutWindow)); break; case "show-audio-devices": Msg.ShowInfo(Core.GetPropertyOsdString("audio-device-list")); break; case "show-audio-tracks": ShowAudioTracks(); break; + case "show-chapters": ShowChapters(); break; case "show-command-palette": ShowCommandPalette(); break; case "show-commands": ShowCommands(); break; case "show-conf-editor": ShowDialog(typeof(ConfWindow)); break; @@ -669,6 +670,16 @@ namespace mpvnet CommandPalette.Instance.SelectFirst(); }); + public static void ShowChapters() => App.InvokeOnMainThread(() => + { + var items = Core.Chapters.Select(i => new CommandPaletteItem(i.Title, i.TimeDisplay, () => + Core.CommandV("seek", i.Time.ToString(CultureInfo.InvariantCulture), "absolute"))); + + CommandPalette.Instance.SetItems(items); + MainForm.Instance.ShowCommandPalette(); + CommandPalette.Instance.SelectFirst(); + }); + public static void ShowMenu() => Core.RaiseShowMenu(); public static void PlaylistAdd(int value) diff --git a/src/Misc/Misc.cs b/src/Misc/Misc.cs index 11b032d..32ef126 100644 --- a/src/Misc/Misc.cs +++ b/src/Misc/Misc.cs @@ -261,6 +261,13 @@ namespace mpvnet Action = action; } + public CommandPaletteItem(string text, string secondaryText, Action action) + { + Text = text; + Action = action; + SecondaryText = secondaryText; + } + public string Text { get; set; } = ""; public string SecondaryText { get; set; } = ""; public Action Action { get; set; } @@ -283,4 +290,26 @@ namespace mpvnet }); } } + + public class Chapter + { + public string Title { get; set; } + public double Time { get; set; } + + string _TimeDisplay; + + public string TimeDisplay { + get { + if (_TimeDisplay == null) + { + _TimeDisplay = TimeSpan.FromSeconds(Time).ToString(); + + if (_TimeDisplay.ContainsEx(".")) + _TimeDisplay = _TimeDisplay.Substring(0, _TimeDisplay.LastIndexOf(".")); + } + + return _TimeDisplay; + } + } + } } diff --git a/src/Misc/Player.cs b/src/Misc/Player.cs index 4440aff..b840d90 100644 --- a/src/Misc/Player.cs +++ b/src/Misc/Player.cs @@ -74,7 +74,7 @@ namespace mpvnet public AutoResetEvent VideoSizeAutoResetEvent { get; } = new AutoResetEvent(false); public IntPtr Handle { get; set; } public IntPtr NamedHandle { get; set; } - public List> Chapters { get; set; } = new List>(); + public List Chapters { get; set; } = new List(); public List MediaTracks { get; set; } = new List(); public List BluRayTitles { get; } = new List(); public object MediaTracksLock { get; } = new object(); @@ -1458,13 +1458,15 @@ namespace mpvnet for (int x = 0; x < count; x++) { - string text = GetPropertyString($"chapter-list/{x}/title"); + string title = GetPropertyString($"chapter-list/{x}/title"); double time = GetPropertyDouble($"chapter-list/{x}/time"); - if (string.IsNullOrEmpty(text)) - text = "Chapter " + (x + 1); + if (string.IsNullOrEmpty(title) || + (title.Length == 12 && title.Contains(":") && title.Contains("."))) - Chapters.Add(new KeyValuePair(text, time)); + title = "Chapter " + (x + 1); + + Chapters.Add(new Chapter() { Title = title, Time = time }); } } } diff --git a/src/Resources/input.conf.txt b/src/Resources/input.conf.txt index 62cfe93..15e6305 100644 --- a/src/Resources/input.conf.txt +++ b/src/Resources/input.conf.txt @@ -118,6 +118,7 @@ Ctrl+p script-message-to mpvnet select-profile #menu: View > Show Profile Ctrl+P script-message-to mpvnet show-profiles #menu: View > Show Profiles Ctrl+7 script-message-to mpvnet show-audio-tracks #menu: View > Show Audio Tracks Ctrl+8 script-message-to mpvnet show-subtitle-tracks #menu: View > Show Subtitle Tracks +Ctrl+c script-message-to mpvnet show-chapters #menu: View > Show Chapters b cycle border #menu: View > Toggle Border Ctrl+t cycle ontop #menu: View > Toggle On Top t script-binding stats/display-stats-toggle #menu: View > Toggle Statistics diff --git a/src/WinForms/MainForm.cs b/src/WinForms/MainForm.cs index 052c05f..c2eb8aa 100644 --- a/src/WinForms/MainForm.cs +++ b/src/WinForms/MainForm.cs @@ -301,16 +301,11 @@ namespace mpvnet { chaptersMenuItem.Items.Clear(); - foreach (var pair in Core.Chapters) + foreach (Chapter chapter in Core.Chapters) { - string caption = TimeSpan.FromSeconds(pair.Value).ToString(); - - if (caption.ContainsEx(".")) - caption = caption.Substring(0, caption.LastIndexOf(".")); - - var chapterMenuItem = new WpfControls.MenuItem() { Header = pair.Key }; - chapterMenuItem.InputGestureText = caption; - chapterMenuItem.Click += (sender, args) => Core.CommandV("seek", pair.Value.ToString(CultureInfo.InvariantCulture), "absolute"); + var chapterMenuItem = new WpfControls.MenuItem() { Header = chapter.Title }; + chapterMenuItem.InputGestureText = chapter.TimeDisplay; + chapterMenuItem.Click += (sender, args) => Core.CommandV("seek", chapter.Time.ToString(CultureInfo.InvariantCulture), "absolute"); chaptersMenuItem.Items.Add(chapterMenuItem); } }