VLC player Command Runner

If you don't care how and why it was written, skip down to the section Installation

Origin story

Initially, I wanted to talk directly to Home Assistant from within VLC player, but that turned out to be quite complicated. (By the way, if you are living in the German-speaking regions, don't get mislead by the site vlc.de which gives you the player and some "Updater" you probably don't want.)

Why was it so complicated? VLC player allows you to write extensions in LUA to modify the way the player behaves. But that's about it, there is the possibility, but the documentation on the HOW is quite lacking. Thanks to a great StackOverflow answer by approxiblue, I figured out which capability I need and which methods will be called by the player.

The next issue was the lacking http support. You can have raw tcp transport, but you would have to implement the HTTP implementation yourself. You could try to load the lua module socket.http, but that relies on the module being installed on the system. So I've changed the design of the extension and no longer aim to talk directly to the Home Assistant instance but call scripts when the playback is started, paused or stopped. And those scripts can use curl or httpie or whatever client one prefers. As an extra, you can do other stuff as well, when playback starts, like killing your SIP phone application, so you are not disturbed during the movie and start it again after you finished watching.

Installation

  1. Download the command-runner.lua from here
  2. Place the file in the lua extensions directory on your machine, you might have to create the directories if they are missing. The path is verified for Linux only, path might be incorrect on other OS:
    1. Linux: ~/.local/share/vlc/lua/extensions/
    2. Windows: %APPDATA%\vlc\lua\extensions\
    3. Mac OS: /Users/%your_name%/Library/Application Support/org.videolan.vlc/lua/extensions/
  3. Start VLC player and click Tools > Plugins and extensions. You should see the extension in the tab Active extensions

Configuration

You can either copy the example file from the GitHub Gist above or just enable the plugin once, it will then create an empty configuration. To see in which path it was created, you can click Tools > Messages, set verbosity to 2 (debug) and enable the extension with View > Command runner. The messages window will then show a message like Config file is missing, empty config file generated at <path>.

For the configuration, keep these things in mind:

That could look like this:

on_play_commands=/bin/kill_linphone,/bin/dimm_lights
on_pause_commands=/bin/lights_on_dimm
on_stop_commands=/bin/lights_on_bright

Usage

To actually use the command runner, you have to activate the extension every time you start vlc by clicking View > Command runner and verify it was activated by checking if the checkbox in front of Command runner in the View dropdown is filled. Your commands should be executed when the playback state changes, you can see debug output in Tools > Messages by setting verbosity to 2 (debug) and filtering for [command runner].