From 448add600b08139c2190288ab04ae6159f985506 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Thu, 28 Mar 2019 02:04:55 +0100 Subject: [PATCH] - --- README.md | 94 +++-------------------------------- scripts/fullscreen.cs | 16 ++++++ scripts/seek-show-position.js | 31 ++++++++++++ scripts/seek.ps1 | 2 + wiki/scripting.md | 0 5 files changed, 55 insertions(+), 88 deletions(-) create mode 100644 scripts/fullscreen.cs create mode 100644 scripts/seek-show-position.js create mode 100644 scripts/seek.ps1 create mode 100644 wiki/scripting.md diff --git a/README.md b/README.md index 694e32d..ed666ed 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,12 @@ Table of contents ------- - [Features](#features) -- [Screenshots](#Screenshots) +- [Screenshots](#screenshots) - [Context Menu](#context-menu) - [Settings](#settings) -- [C# Scripting](#cs-scripting) -- [Python Scripting](#python-scripting) -- [PowerShell Scripting](#powershell-scripting) -- [Support](#Support) -- [Changelog](#changelog) +- [Scripting](#scripting) +- [Support](#support) +- [Changelog](#Changelog) ### Features @@ -52,89 +50,9 @@ if it's missing mpv.net generates it with the following defaults: https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/mpv.conf.txt -### C# Scripting +### Scripting -A simple C# script located at: -``` -C:\Users\username\AppData\Roaming\mpv\scripts\fullscreen.cs -``` -or -``` -startup\scripts\fullscreen.cs -``` -``` -using mpvnet; - -class Script -{ - public Script() - { - var fs = mp.get_property_string("fullscreen"); - mp.commandv("show-text", "fullscreen: " + fs); - mp.observe_property_bool("fullscreen", FullscreenChange); - } - - void FullscreenChange(bool val) - { - mp.commandv("show-text", "fullscreen: " + val.ToString()); - } -} -``` - -### Python Scripting - -A simple Python script located at: -``` -C:\Users\user\AppData\Roaming\mpv\scripts\seek-show-position.py -``` -or -``` -startup\scripts\seek-show-position.py -``` -``` -# when seeking displays position and -# duration like so: 70:00 / 80:00 -# which is different from mpv which -# uses 01:10:00 / 01:20:00 - -import math - -def seek(): - mp.commandv('show-text', - format(mp.get_property_number("time-pos")) + " / " + format(mp.get_property_number("duration"))) - -def format(f): - sec = round(f) - - if sec < 0: - sec = 0 - - pos_min_floor = math.floor(sec / 60) - sec_rest = sec - pos_min_floor * 60 - return add_zero(pos_min_floor) + ":" + add_zero(sec_rest) - -def add_zero(val): - val = round(val) - return "" + str(int(val)) if (val > 9) else "0" + str(int(val)) - -mp.register_event("seek", seek) # or use: mp.Seek += seek -``` - -### PowerShell Scripting - -A simple PowerShell script located at: -``` -C:\Users\user\AppData\Roaming\mpv\scripts\seek.ps1 -``` -or -``` -startup\scripts\seek.ps1 -``` -``` -$position = [mp]::get_property_number("time-pos"); -[mp]::commandv("show-text", $position.ToString() + " seconds") -``` -Please note that PowerShell don't allow assigning to events and mpv.net uses as workaround a matching script filename, a list of available events can be found in the mpv manual or in the file mp.cs in the mpv.net source code. +https://github.com/stax76/mpv.net/wiki/Scripting-using-C%23,-Python,-JavaScript,-Lua-or-PowerShell ### Support diff --git a/scripts/fullscreen.cs b/scripts/fullscreen.cs new file mode 100644 index 0000000..94e6506 --- /dev/null +++ b/scripts/fullscreen.cs @@ -0,0 +1,16 @@ +using mpvnet; + +class Script +{ + public Script() + { + var fs = mp.get_property_string("fullscreen"); + mp.commandv("show-text", "fullscreen: " + fs); + mp.observe_property_bool("fullscreen", FullscreenChange); + } + + void FullscreenChange(bool val) + { + mp.commandv("show-text", "fullscreen: " + val.ToString()); + } +} \ No newline at end of file diff --git a/scripts/seek-show-position.js b/scripts/seek-show-position.js new file mode 100644 index 0000000..b6d89e3 --- /dev/null +++ b/scripts/seek-show-position.js @@ -0,0 +1,31 @@ +// when seeking displays position and +// duration like so: 70:00 / 80:00 +// which is different from mpv which +// uses 01:10:00 / 01:20:00 + +function add_zero(val) +{ + val = Math.round(val); + return val > 9 ? "" + val : "0" + val; +} + +function format(val) +{ + var sec = Math.round(val); + + if (sec < 0) + sec = 0; + + pos_min_floor = Math.floor(sec / 60); + sec_rest = sec - pos_min_floor * 60; + return add_zero(pos_min_floor) + ":" + add_zero(sec_rest); +} + +function on_seek(_) +{ + mp.commandv("show-text", + format(mp.get_property_number("time-pos")) + " / " + + format(mp.get_property_number("duration"))); +} + +mp.register_event("seek", on_seek); \ No newline at end of file diff --git a/scripts/seek.ps1 b/scripts/seek.ps1 new file mode 100644 index 0000000..f3b4203 --- /dev/null +++ b/scripts/seek.ps1 @@ -0,0 +1,2 @@ +$position = [mp]::get_property_number("time-pos"); +[mp]::commandv("show-text", $position.ToString() + " seconds") \ No newline at end of file diff --git a/wiki/scripting.md b/wiki/scripting.md new file mode 100644 index 0000000..e69de29