Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
stax76 committed Aug 1, 2019
1 parent a572bd8 commit d90025e
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 124 deletions.
27 changes: 22 additions & 5 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,30 @@
- 'Tools > Manage File Associations' was replaced by 'Tools > OS Setup',
it has now a feature to add and remove mpv.net to and from the Path
environment variable and the OS default apps settings can be opened (Win 10 only)
- startup folder and config folder beeing identical is no longer a supported scenaria
- startup folder and config folder beeing identical was causing a critical issue
as mpv.net was loading extensions twice and scripts four times, now identical
folders are no longer permitted
- error messages are shown when unknown scripts and extensions are found in the startup folder
because user scripts and extensions are supposed to be located in the config folder instead
- changing from maximized to fullscreen did not work
- the search field in the config editor was not always remembered
- new setting remember-volume added, saves volume and mute on exit
and restores it on start.
- it's now enforced that mpv properties on the command line and in
the mpv.conf config file are lowercase, if not a error is shown
- gpu-api vulkan was not working if media files were opened via
command line (that included Explorer), Vulkan unlike d3d11 and opengl
requires a window being visible, this is now satisfied with a
workaround, it's only possible showing a window with default size
first as defines by autofit. Vulkan has few issues, usually the auto option
which uses d3d11 is better! Using Vulkan the mpv.net setting
- new setting minimum-aspect-ratio added, minimum aspect ratio for the window,
this was previously hard coded to 1.3
- new setting auto-load-folder added, for single files automatically load
the entire directory into the playlist, previously this was forced,
now it can be disabled
- new setting themed-menu added, follow theme color in context menu,
default: no, UI related settings have now a separate UI tab in the config editor

### 5.0

Expand Down Expand Up @@ -98,10 +119,6 @@
the task bar because this is the WinForms default behavier. This
was fixed by calling Spy++ to the rescue and adding WS_MINIMIZEBOX
in CreateParams
- changing from maximized to fullscreen did not work
- the search field in the config editor was not always remembered
- new setting remember-volume added, saves volume and mute on exit
and restores it on start.

### 4.6

Expand Down
26 changes: 15 additions & 11 deletions mpv.net/Misc/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,31 @@ namespace mpvnet
{
public class App
{
public static string[] VideoTypes { get; } = "264 265 asf avc avi avs flv h264 h265 hevc m2ts m2v m4v mkv mov mp4 mpeg mpg mpv mts ts vob vpy webm webm wmv y4m".Split(' ');
public static string[] AudioTypes { get; } = "mp3 mp2 ac3 ogg opus flac wav w64 m4a dts dtsma dtshr dtshd eac3 thd thd+ac3 mka aac mpa".Split(' ');
public static string[] ImageTypes { get; } = {"jpg", "bmp", "gif", "png"};
public static string[] SubtitleTypes { get; } = { "srt", "ass", "idx", "sup", "ttxt", "ssa", "smi" };
public static string[] UrlWhitelist { get; set; } = { "tube", "vimeo", "ard", "zdf" };

public static string RegPath { get; } = @"HKCU\Software\" + Application.ProductName;
public static string ConfPath { get; } = mp.ConfigFolder + "\\mpvnet.conf";
public static string DarkMode { get; set; } = "always";
public static string ProcessInstance { get; set; } = "single";
public static string DarkColor { get; set; }
public static string LightColor { get; set; }

public static string[] VideoTypes { get; } = "264 265 asf avc avi avs flv h264 h265 hevc m2ts m2v m4v mkv mov mp4 mpeg mpg mpv mts ts vob vpy webm webm wmv y4m".Split(' ');
public static string[] AudioTypes { get; } = "mp3 mp2 ac3 ogg opus flac wav w64 m4a dts dtsma dtshr dtshd eac3 thd thd+ac3 mka aac mpa".Split(' ');
public static string[] ImageTypes { get; } = "jpg bmp gif png".Split(' ');
public static string[] SubtitleTypes { get; } = "srt ass idx sup ttxt ssa smi".Split(' ');
public static string[] UrlWhitelist { get; set; } = { "tube", "vimeo", "ard", "zdf" };

public static bool RememberHeight { get; set; } = true;
public static bool RememberPosition { get; set; }
public static bool DebugMode { get; set; }
public static bool IsStartedFromTerminal { get; } = Environment.GetEnvironmentVariable("_started_from_console") == "yes";
public static bool RememberVolume { get; set; }
public static bool AutoLoadFolder { get; set; } = true;
public static bool ThemedMenu { get; set; }

public static int StartThreshold { get; set; } = 1500;

public static float MinimumAspectRatio { get; set; } = 1.3f;

public static bool IsDarkMode {
get => (DarkMode == "system" && Sys.IsDarkTheme) || DarkMode == "always";
}
Expand Down Expand Up @@ -103,7 +107,7 @@ public static void UnknownModule(string path)

public static bool ProcessProperty(string name, string value)
{
switch (name) // return true instead of break!
switch (name)
{
case "remember-position": RememberPosition = value == "yes"; return true;
case "start-size": RememberHeight = value == "previous"; return true;
Expand All @@ -114,10 +118,10 @@ public static bool ProcessProperty(string name, string value)
case "light-color": LightColor = value.Trim('\'', '"'); return true;
case "url-whitelist": UrlWhitelist = value.Split(' ', ',', ';'); return true;
case "remember-volume": RememberVolume = value == "yes"; return true;
case "start-threshold":
int.TryParse(value, out int result);
StartThreshold = result;
return true;
case "start-threshold": StartThreshold = value.Int(); return true;
case "minimum-aspect-ratio": MinimumAspectRatio = value.Float(); return true;
case "auto-load-folder": AutoLoadFolder = value == "yes"; return true;
case "themed-menu": ThemedMenu = value == "yes"; return true;
}
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions mpv.net/Misc/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static void ShowInfo()
{
fileSize = new FileInfo(path).Length;

if (App.AudioTypes.Contains(PathHelp.GetShortExtension(path)))
if (App.AudioTypes.Contains(path.ShortExt()))
{
using (MediaInfo mediaInfo = new MediaInfo(path))
{
Expand All @@ -111,21 +111,21 @@ public static void ShowInfo()
if (date != "") text += "Year: " + date + "\n";
if (duration != "") text += "Length: " + duration + "\n";
text += "Size: " + mediaInfo.GetInfo(MediaInfoStreamKind.General, "FileSize/String") + "\n";
text += "Type: " + PathHelp.GetShortExtension(path).ToUpper();
text += "Type: " + path.ShortExt().ToUpper();

mp.commandv("show-text", text, "5000");
return;
}
}
else if (App.ImageTypes.Contains(PathHelp.GetShortExtension(path)))
else if (App.ImageTypes.Contains(path.ShortExt()))
{
using (MediaInfo mediaInfo = new MediaInfo(path))
{
text =
"Width: " + mediaInfo.GetInfo(MediaInfoStreamKind.Image, "Width") + "\n" +
"Height: " + mediaInfo.GetInfo(MediaInfoStreamKind.Image, "Height") + "\n" +
"Size: " + mediaInfo.GetInfo(MediaInfoStreamKind.General, "FileSize/String") + "\n" +
"Type: " + PathHelp.GetShortExtension(path).ToUpper();
"Type: " + path.ShortExt().ToUpper();

mp.commandv("show-text", text, "5000");
return;
Expand All @@ -138,7 +138,7 @@ public static void ShowInfo()
string videoFormat = mp.get_property_string("video-format").ToUpper();
string audioCodec = mp.get_property_string("audio-codec-name").ToUpper();

text = PathHelp.GetFileName(path) + "\n" +
text = path.FileName() + "\n" +
FormatTime(position.TotalMinutes) + ":" +
FormatTime(position.Seconds) + " / " +
FormatTime(duration2.TotalMinutes) + ":" +
Expand Down
32 changes: 32 additions & 0 deletions mpv.net/Misc/ExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Globalization;
using System.IO;

public static class Extensions
{
public static string FileName(this string path)
{
if (string.IsNullOrEmpty(path)) return "";
int index = path.LastIndexOf('\\');
if (index > -1) return path.Substring(index + 1);
index = path.LastIndexOf('/');
if (index > -1) return path.Substring(index + 1);
return path;
}

public static string ShortExt(this string path)
{
return Path.GetExtension(path).ToLower().TrimStart('.');
}

public static int Int(this string value)
{
int.TryParse(value, out int result);
return result;
}

public static float Float(this string value)
{
float.TryParse(value.Replace(",", "."), NumberStyles.Float, CultureInfo.InvariantCulture, out float result);
return result;
}
}
15 changes: 0 additions & 15 deletions mpv.net/Misc/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,20 +294,5 @@ public static bool IsPosDifferent(Point screenPos)
public class PathHelp
{
public static string StartupPath { get; } = Application.StartupPath + "\\";

public static string GetFileName(string path)
{
if (string.IsNullOrEmpty(path)) return "";
int index = path.LastIndexOf('\\');
if (index > -1) return path.Substring(index + 1);
index = path.LastIndexOf('/');
if (index > -1) return path.Substring(index + 1);
return path;
}

public static string GetShortExtension(string path)
{
return Path.GetExtension(path).ToLower().TrimStart('.');
}
}
}
6 changes: 3 additions & 3 deletions mpv.net/Resources/mpvConfToml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,17 @@ help = "Specify the OSD font size. See sub-font-size for details. Default: 55"
[[settings]]
name = "autofit"
filter = "Screen"
help = "<int> Initial window height in percent. Default: 50%"
help = "<int> Initial window height in percent. Default: 50"

[[settings]]
name = "autofit-smaller"
filter = "Screen"
help = "<int> Minimum window height in percent. Default: 40%"
help = "<int> Minimum window height in percent. Default: 40"

[[settings]]
name = "autofit-larger"
filter = "Screen"
help = "<int> Maximum window height in percent. Default: 75%"
help = "<int> Maximum window height in percent. Default: 75"

[[settings]]
name = "screenshot-directory"
Expand Down
66 changes: 44 additions & 22 deletions mpv.net/Resources/mpvNetConfToml.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
[[settings]]
name = "dark-mode"
default = "always"
filter = "General"
help = "Enables a dark theme. (mpv.net specific setting)"
options = [{ name = "always" },
{ name = "system" , help = "Available on Windows 10 or higher" },
{ name = "never" }]

[[settings]]
name = "dark-color"
type = "color"
filter = "General"
help = "Theme color used in dark-mode. Leave empty to use OS theme. (mpv.net specific setting)"

[[settings]]
name = "light-color"
type = "color"
filter = "General"
help = "Theme color used when dark-mode is disabled. Leave empty to use OS theme. (mpv.net specific setting)"

[[settings]]
name = "url-whitelist"
filter = "General"
type = "string"
help = "Whitelist setting to monitor the clipboard for URLs to play. (mpv.net specific setting)\n\nDefault: tube vimeo ard zdf"
help = "Whitelist setting to monitor the clipboard for URLs to play. (mpv.net specific setting)\n\nDefault: tube vimeo ard zdf\n\nHow to start mpv.net directly from Google Chrome is described in the manual:"
url = "https://github.com/stax76/mpv.net/blob/master/Manual.md#chrome-extension"

[[settings]]
name = "process-instance"
Expand Down Expand Up @@ -55,6 +35,11 @@ name = "start-threshold"
filter = "Screen"
help = "Threshold in milliseconds to wait for libmpv returning the video resolution before the window is shown, otherwise default dimensions are used as defined by autofit and start-size. (mpv.net specific setting) Default: 1500"

[[settings]]
name = "minimum-aspect-ratio"
filter = "Screen"
help = "<float> Minimum aspect ratio for the window. Default: 1.3"

[[settings]]
name = "remember-position"
default = "no"
Expand All @@ -68,5 +53,42 @@ name = "remember-volume"
default = "no"
filter = "Audio"
help = "Save volume and mute on exit and restore it on start. (mpv.net specific setting)"
options = [{ name = "yes" },
{ name = "no" }]

[[settings]]
name = "auto-load-folder"
default = "yes"
filter = "Playback"
help = "For single files automatically load the entire directory into the playlist. (mpv.net specific setting)"
options = [{ name = "yes" },
{ name = "no" }]

[[settings]]
name = "dark-mode"
default = "always"
filter = "UI"
help = "Enables a dark theme. (mpv.net specific setting)"
options = [{ name = "always" },
{ name = "system" , help = "Available on Windows 10 or higher" },
{ name = "never" }]

[[settings]]
name = "dark-color"
type = "color"
filter = "UI"
help = "Theme color used in dark-mode. Leave empty to use OS theme. (mpv.net specific setting)"

[[settings]]
name = "light-color"
type = "color"
filter = "UI"
help = "Theme color used when dark-mode is disabled. Leave empty to use OS theme. (mpv.net specific setting)"

[[settings]]
name = "themed-menu"
default = "no"
filter = "UI"
help = "Follow theme color in context menu. (mpv.net specific setting)"
options = [{ name = "yes" },
{ name = "no" }]
4 changes: 2 additions & 2 deletions mpv.net/WPF/ConfWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:WPF="clr-namespace:WPF"
mc:Ignorable="d"
Height="500" Width="700" Loaded="ConfWindow1_Loaded" ShowInTaskbar="False"
Height="530" Width="700" Loaded="ConfWindow1_Loaded" ShowInTaskbar="False"
WindowStartupLocation="CenterScreen" Title="Config Editor">
<Grid>
<Grid.RowDefinitions>
Expand All @@ -21,7 +21,7 @@
<StackPanel x:Name="MainStackPanel"></StackPanel>
</ScrollViewer>
<StackPanel Margin="20,0,0,0" Grid.Row="1">
<ListBox x:Name="FilterListBox" ItemsSource="{Binding FilterStrings}" BorderThickness="0" SelectionChanged="ListBox_SelectionChanged" Foreground="{x:Static WPF:WPF.ThemeBrush}" Background="{Binding Path=Background, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}">
<ListBox x:Name="FilterListBox" ItemsSource="{Binding FilterStrings}" BorderThickness="0" SelectionChanged="FilterListBox_SelectionChanged" Foreground="{x:Static WPF:WPF.ThemeBrush}" Background="{Binding Path=Background, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" FontSize="16" />
Expand Down
2 changes: 1 addition & 1 deletion mpv.net/WPF/ConfWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private void ConfWindow1_Loaded(object sender, RoutedEventArgs e)
i.Update();
}

private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
private void FilterListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
SearchControl.Text = e.AddedItems[0].ToString() + ":";
Expand Down
4 changes: 3 additions & 1 deletion mpv.net/WPF/EverythingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,11 @@ void Search(string searchtext)
Everything_SetRequestFlags(EVERYTHING_REQUEST_FILE_NAME | EVERYTHING_REQUEST_PATH);
Everything_SetSort(EVERYTHING_SORT_SIZE_DESCENDING);
Everything_Query(true);

for (i = 0; i < Everything_GetNumResults(); i++)
{
Everything_GetResultFullPathName(i, buf, bufsize);
string ext = PathHelp.GetShortExtension(buf.ToString());
string ext = buf.ToString().ShortExt();

if (App.AudioTypes.Contains(ext) || App.VideoTypes.Contains(ext) ||
App.ImageTypes.Contains(ext))
Expand All @@ -148,6 +149,7 @@ void Search(string searchtext)

if (items.Count > 100) break;
}

Application.Current.Dispatcher.Invoke(() => {
ListView.ItemsSource = items;
SelectFirst();
Expand Down
Loading

0 comments on commit d90025e

Please sign in to comment.