npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mpv-ipc

v0.1.3

Published

MPV (https://mpv.io) IPC interface library

Downloads

11

Readme

mpv-ipc.js

This is a simple, mostly dumb, client for mpv's IPC interface. It translates any method calls into IPC commands for mpv according to the following rules:

  • Explicitly implemented commands like observeProperty() (see commands below);
  • IPC-only commands as listed in the IPC interface documentation (such as clientName() -> client_name);
  • Methods starting with on or off are translated into event handler addition/deletion for their corresponding dash-case events;
  • Methods starting with get, set, observe, toggle/cycle, adjust/add, scale/multiply are translated into their corresponding get_property, set_property, observe_property, cycle, add and multiply commands with the property translated to dash-case;
  • Finally, the entire command is translated into dash-case and attempted as an IPC input-style command.

The IPC interface is fully asynchronous and every command (except for event handler registration) returns a Promise. On success, resolve() is called with the result data and on failure reject() is called with the error message from mpv.

Explicit commands

  • MPVClient(socketPath): create a client communicating with the IPC socket on socketPath;
  • MPVClient.on(event, handler): register an event handler for raw IPC event event;
  • MPVClient.off(event, handler): unregister an event handler for raw IPC event event;
  • MPVClient.command(...args): send raw command over IPC interface (equivalent to socket.write(JSON.stringify({command: args})));
  • MPVClient.observeProperty(property, handler): observe changes for the given property and invoke handler with the new value once it changes;
  • MPVClient.play(): alias for MPVClient.setPause(false);
  • MPVClient.pause(): alias for MPVClient.setPause(true);
  • MPVClient.resume(): alias for MPVClient.setPause(false);
  • MPVClient.mute(): alias for MPVClient.setMute(true);
  • MPVClient.unmute(): alias for MPVClient.setMute(false);
  • MPVClient.loop(): alias for MPVClient.setLoop(n < 0 ? "inf" : n);

Magic-less usage

If all the method translation magic is too much for you, and you'd just like to use the explicit commands above only (save for the aliases and observeProperty), you can instantiate a BasicMPVClient instead of MPVClient, which will omit all the magic translations.

Example

let mpv = require('mpv-ipc');
let player = new mpv.MPVClient('/tmp/mpv.sock');

/** Basic IPC commands */

player.getProperty('volume').then(v => console.log('Volume: ' + v));
/* or: */
player.getVolume().then(v => console.log('Volume: ' + v));

player.adjustVolume(5); /* raise volume by 5 */

player.observeProperty('media-title', t => console.log('Title changed: ' + t));
/* or: */
player.observeMediaTitle(t => console.log('Title changed: ' + t));

player.on('end-file', e => console.log('File ended.'));
/* or: */
player.onEndFile(e => console.log('File ended.'));

/** Making use of the input interface (https://github.com/mpv-player/mpv/blob/master/DOCS/man/input.rst) */

/* As every function just returns a promise, you can use the async/await functionality for cleaner access,
 * especially if you want to wait for events. */
async function f(player) {
    await player.loadfile('/Users/you/Downloads/not-an-anime-episode.mkv');
    await player.seek(420, 'absolute');
    await player.screenshotToFile('/Users/you/Pictures/lewd-scene.png', 'video');
}

License

mpv-ipc.js is released under the 0BSD license:

Copyright (C) 2018 by Shiz <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN 
NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.