diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2019-03-12 00:12:42 +0200 |
---|---|---|
committer | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2019-09-11 21:08:04 +0300 |
commit | fea39b5a6b3bb8b4104b6300340dc5c8b5df2bff (patch) | |
tree | 7ccf4d6b0bd188a00e3159c4bce346e23a74a74f /player/javascript | |
parent | 5b5f77690064a1fb602e5b97e935bec65f60eb0d (diff) | |
download | mpv-fea39b5a6b3bb8b4104b6300340dc5c8b5df2bff.tar.bz2 mpv-fea39b5a6b3bb8b4104b6300340dc5c8b5df2bff.tar.xz |
js: reimplement subprocess using the subprocess command (match 548ef078)
Semantics changes are the same as at 548ef078 .
Also, the previous C implementation returnd a string for the `stdout`
value, but stdout of the subprocess command is MPV_FORMAT_BYTE_ARRAY
which js previously didn't support, so support it too (at pushnode)
by returning it as a string - the same as the lua code does.
Diffstat (limited to 'player/javascript')
-rw-r--r-- | player/javascript/defaults.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/player/javascript/defaults.js b/player/javascript/defaults.js index cd67a7a2e8..a44e9bb7b2 100644 --- a/player/javascript/defaults.js +++ b/player/javascript/defaults.js @@ -538,6 +538,20 @@ mp.osd_message = function osd_message(text, duration) { mp.commandv("show_text", text, Math.round(1000 * (duration || -1))); } +mp.utils.subprocess = function subprocess(t) { + var cmd = { name: "subprocess", capture_stdout: true }; + var new_names = { cancellable: "playback_only", max_size: "capture_size" }; + for (var k in t) + cmd[new_names[k] || k] = t[k]; + + var rv = mp.command_native(cmd); + if (mp.last_error()) /* typically on missing/incorrect args */ + rv = { error_string: mp.last_error(), status: -1 }; + if (rv.error_string) + rv.error = rv.error_string; + return rv; +} + // ----- dump: like print, but expands objects/arrays recursively ----- function replacer(k, v) { var t = typeof v; |