@gmt4 mpvc logbook

Star Follow @gmt4 Download Watch Issue Sponsor


Logbook Entries


The logbook below is just that, a log of notes as I use and work on mpvc. Entries are chronologically ordered with oldest first, and, attempt to be self-contained focused on a certain functionality/topic, to the extent that it is possible.

On playing URLs, 30 Mar 2022

What got me started on using mpvc is being able to play URLs. This is the cause to start writing what you are reading now (this repo at https://github.com/gmt4/mpvc/). As in

On securing mpv socket location, 14 Nov 2022

One thing that bothers me when using mpvc, is that most programs performing ipc on mpv socket, just leave the socket at /tmp/mpvsocket. A better default location for the mpv socket is $HOME/.config/mpvc/mpvsocket.

On load/save functionality, 18 Nov 2022

A thing that I'd like to be able to do is to perform mpvc load/save of the playlist, and, be able of manipulating the playlist using standard Unix commands eg. grep. The easiest way that comes to mind, is something a la: mpvc save | grep -v artist | mpvc load, this enables to filter out an artist, and drop all the songs by this artist.

On persistent mpv startup, 20 Nov 2022

One particular feature where improvement could be done mpvc -a audio.opus, when mpv finishes playing audio.opus, mpv terminates, and, the current playlist is lost. This happens as mpv is started with --idle=once. A solution for this is to start mpv separately with --idle=yes. A shortcut for this is to run `mpvc --mpv` that does exactly this, after this the mpv instance can be manipulated with mpvc, and does not terminate once mpv finishes playing.

On a minimal mpvc-tui, 03 Dec 2022

One thing I keep doing a lot, is typing mpvc status and mpvc -i, to check the mpv playlist and status. To this end I've quickly hacked a minimal TUI named mpvc-tui, that continuously shows the mpvc playlist and status. In addition, while in mpvc-tui you can Control+C, to get a mpvc prompt to run quick mpvc commands, like: prev, next, pause, toggle, seek, volume, etc.

On using the mpvc-tui prompt, 13 Dec 2022

As explained above, mpvc-tui does three things: 1) display status, 2) display playlist, 3) prompt the user for interaction. Once we hit Control+C, and land on the user prompt, the following can be done:

  1. run mpvc commands starting with "mpvc". This allows for manipulating the mpv/mpvc status. The commands run with "mpvc" have QUIETFLAG=true set, to not clutter the mpvc-tui.
  2. run shell commands internally starting with "!". This allows for commands that manipulate mpvc-tui program, such as changing the working directory, with cd/pwd. This also allows for starting your favorite editor to configure the mpvc-tui look and feel with: "!$EDITOR $MPVC_CONFIG".
  3. run shell commands externally starting with "!!". This allows for running commands on a separate shell. This gives room for more complex commands, like starting alsamixer to manipulate audio levels, change outputs with `pactl(1)`, etc.
  4. quit the mpvc-tui, by typing quit, exit, or "q".
When using the mpvc-tui prompt for some time, one notices that there's a lot of repetition of commands. To address repetition, one solution is to use a history file of past commands, and completion of commands and filenames. This can be achieved using `rlwrap(1)` in one shot mode that becomes a life-saver. Now, you get a more comfortable prompt, where TAB completion works on commands and filenames, as well as Control+R to repeat previous commands in the history file.

On using the mpvc-tui -x launcher, 14 Dec 2022

Another nifty detail of mpvc-tui, is that it can be quickly spawn from the WM launcher by using mpvc-tui -x, then type a few mpvc commands to setup music, and close it. Or it can be started on the current terminal with `mpvc-tui` and left running as a long running program, and get back to it when needed.

On managing playlists with mpvc autoload/autosave, 15 Dec 2022

When using mpc(1), playlists can be managed using the mpc load/save/lsplaylists commands. In addition to load/save, mpvc adds the autoload/autosave commands:

The above enables to arrange a playlist, and once we are happy with it, save it with `mpvc autosave playlist.m3u`, later, we can replay it again with: `mpvc autoload playlist.m3u`.

On customizing mpvc-tui look and feel, 16 Dec 2022

While using mpvc-tui, one ends up wanting to configure the minimal look and feel that mpvc-tui provides. To this end the file mpvc.conf under $XDG_CONFIG_HOME/mpvc/ provides a place to overwrite the default settings of mpvc-tui.

Show HN: mpvc-tui – A minimal mpc-like CLI and TUI for controlling mpv, 16 Dec 2022

We are on "Show HN"! https://news.ycombinator.com/item?id=34013149

On issuing direct JSON IPC commands to mpv, 17 Dec 2022

That one is easy, for that purpose mpvc cmd args sends the { "command": args } to the JSON IPC, use mpvc cmdr args to send the command, and retrieve the JSON IPC response. Some usage examples to test are:

Note, audio filter commands above are lifted from https://github.com/mpv-player/mpv/issues/6210.

On playing music from streaming services as youtube and co., 19 Dec 2022

Mpv already plays URLs (both video and audio) from streaming platforms as youtube. So the one thing missing is to be able to search, select, and enqueue music from these services. This is provided by mpvc-fzf -s/-p, that does:

  1. Query the Invidious API and return a list of URLs
  2. Use fzf -m to select from the search results.
  3. Use mpvc load to enqueue the selected songs into the mpv playlist.
Some usage examples of the above are: Note, that you can use this command from inside mpvc-tui too, by hitting Control+C and then typing "!mpvc-fzf -p rolling stones"

On subscribing and receiving mpv events, 21 Dec 2022

Mpv IPC JSON socket allows receiving the media events generated by the running mpv instance. Subscribing to the mpv events can be done using the command: mpvc idleloop, by default events appear on standard output for a separate program to consume and react them. Some usage examples of the above are:

The mpvc-tui -n uses mpvc idleloop to raise desktop notifications, as shown above.

On using mpv together with the fzf fuzzy finder, 27 Dec 2022

I discovered fzf while adding support for selecting and playing YT videos #logbook-20221219, so I'm quite a newbie on fzf. Still I've been playing with fzf+mpvc to get them working together. So far I've focused on 4 points:

This is still on a very preliminary state, but it's amazing what fzf can do, and so far, seems to fit very well with mpvc.

On using mpv together with the fzf fuzzy finder, 12 Jan 2023

Continuing on the topic of using fzf with mpv, I’ve decided to split the code into three scripts:

I think it’s clear/simpler this way, as the mpvc-tui was getting more and more fzf functionality, that was unrelated to the TUI. This breaks some things, as for example, uses of mpvc-tui -[lfFspP] that now have become mpvc-fzf -[lfFspP].

On controlling multiple remotely running mpv instances, 19 Jan 2023

A work in progress update, in no particular order, but, mostly focused on using mpvc to control a remote box (Raspberry Pi) acting as an audio/media center:

This goes together with other related command as: mpvc cmd/sockcmd/repl/get/set/cycle.

On stashing mpv media player state to restore later, 19 Feb 2023

Something experimental I've been testing lately is using: mpvc stash command to save the currently playing state, to be restored later. The commands implemented by mpvc stash [list|show|push|drop|apply] are inspired by git-stash(1):

This is different from mpvc load/save that only loads/saves the playlist, as mpvc stash saves the current playing settings including: playlist-pos, playback-time, volume, mute, pause, etc. together with the playlist.

CSS, RSS & casts updates on the gmt4.github.io/mpvc site, 31 Mar 2023

A few things have been going on since last entry, some effort focused on getting a “decent” site (this HTML thing you’re reading right now @ gmt4.github.io/mpvc ) where its easy keep track of whats going on. This effort has :

Keep posted.

Introducing mpvc-equalizer: a basic mpv equalizer for the CLI, 25 Apr 2023

This entry introduces mpvc-equalizer a Linear Phase 15-Bands Equalizer for the CLI/shell based on the firequalizer15.lua mpv-script. The basic operations that are available in mpvc-equalizer are:

An example of the `mpvc-equalizer` to set equalizer values for classical music:

 mpvc-equalizer preset
 mpvc-equalizer preset classical | mpvc-equalizer load
 mpvc-equalizer bars
 mpvc-equalizer reset

On applying ffmpeg AV filters using the MPV JSON IPC, 2 June 2023

Continuing with the topic of the previous post about mpvc-equalizer, one reason for starting mpvc, was to ease was to managing audio from the CLI. In that sense mpv integrates well with ffmpeg to apply AV filters. However you've to, either start mpv specifying the ffmpeg cli flags for the AV-filters, or add keyboard shortcuts into the input.conf to be triggedred during runtime.

Instead of that, for quickly testing combinations of filters, I was looking for something more CLI oriented: apply the filters using the MPV JSON IPC. That's what happens under the hood when a command mpvc-cmdr af ... is run, for example:

# start adding a rubberband filter
mpvc cmdr af toggle "@rubberband:lavfi=[rubberband=pitch=1:tempo=1]"
# Change the AV filter is easy, rerun the command with the changes
mpvc cmdr af toggle "@rubberband:lavfi=[rubberband=pitch=0.98:tempo=1]"
# Removing the filter is as expected
mpvc cmdr af remove "@rubberband:lavfi=[rubberband=pitch=0.98:tempo=1]"
# Another option is toggling the AV filters on and off with
mpvc cmdr af toggle "@rubberband:lavfi=[rubberband=pitch=0.98:tempo=1]"

# The same goes for what filters are currently applied
mpvc getr af | jq

# Clearing all the current af filters
mpvc setr af ''

# Useful debuging af filters errors: lower/raise verbosity
mpvc setr msg-level all=error
mpvc setr msg-level all=warn
mpvc setr msg-level all=info

# Some af filters
mpvc cmdr af toggle "@afade:lavfi=[afade=t=in:ss=0:d=15]"
mpvc cmdr af toggle "@flanger:lavfi=[flanger=delay=1]"
mpvc cmdr af toggle "@tremolo:lavfi=[tremolo]"
mpvc cmdr af toggle "@vibrato:lavfi=[vibrato]"
mpvc cmdr af toggle "@apulsator:lavfi=[apulsator]"
mpvc cmdr af toggle "@aphaser:lavfi=[aphaser]"
mpvc cmdr af toggle "@aecho:lavfi=[aecho=in_gain=0.9:out_gain=0.9:delays=1:decays=0.9]"

# Some vf filters
mpvc cmdr vf toggle "@life:lavfi=[life]"
mpvc cmdr vf toggle "@showvolume:lavfi=[showvolume]"
mpvc cmdr vf toggle "@showwaves:lavfi=[showwaves]"
mpvc cmdr vf toggle "@showspectrum:lavfi=[showspectrum]"
mpvc cmdr vf toggle "@avectorscope:lavfi=[avectorscope]"

Introducing mpvc-web: a mpvc-tui like hack for the web/browser, 21 July 2023

A few things have been going on lately, among them, the most recent has been adding mpvc-web that is just a quick hack to control a running mpv instance from when no mpvc cli is available, a typical example is when you just have a phone or tablet with no cli. To this I resorted to mimic mpvc-tui interface but making it available through HTTP using python3 -m http.server. This seems to work fine for simple things like toggling music on and off, moving to next/prev entry in the playlist, and raising/lowering volume. Check extras/mpvc-web for more, and you are warned: this is a ugly hack.

As a minor thing I've started aliasing mpvc commands that I use frequently to their "m" counterparts in bash, not perfect, but handy enough, and saves some typing:

$ grep mpvc ~/.bashrc
    alias m="mpvc"
    alias mh="alias | grep mpvc"
    alias mi="mpvc -i"
    alias mI="mpvc -I"
    alias ma="mpvc-autostart"
    alias mc="mpvc-chapter"
    alias mci="mpvc chapter-list"
    alias mcn="mpvc chapter-list-nr"
    alias mcI="mpvc chapter-list-full"
    alias me="mpvc-equalizer"
    alias mtt="mpvc-tui"
    alias mm="mpvc-mpris"
    alias mw="mpvc-web"
    alias mff="mpvc-fzf"       # fzf on mpvc
    alias mffa="mpvc-fzf -a"   # fzf on mpvc stash-list
    alias mffb="mpvc-fzf -b"   # fzf on mpvc ytdl-archive URL
    alias mffB="mpvc-fzf -B"   # get on mpvc ytdl-archive URL
    alias mffc="mpvc-fzf -c"   # fzf on mpvc chapter-list
    alias mffd="mpvc-fzf -d"   # fzf on -d /path/to/music/
    alias mffe="mpvc-fzf -e"   # fzf on mpvc-equalizer
    alias mfff="mpvc-fzf -f"   # fzf on mpvc play-list
    alias mffg="mpvc-fzf -g"   # fzf get/fetch ytid URL to ytdl-archive
    alias mffG="mpvc-fzf -G"   # bis
    alias mffl="mpvc-fzf -l"   # fzf over local files
    alias mffo="mpvc-fzf -o"   # fzf search and return first ytid URL
    alias mffp="mpvc-fzf -p"   # fzf search and add ytid URLs from Invidious
    alias xargn="xargs -n1"    # xargn mpvc cmd
    rseq() { seq "$@" | tac; } # rseq | xargn mpvc cmd

Check the Now Playing @ now/ that builds upon mpvc-tui scrobbling code to generate a simple list of the most played media. The Anti EP by Autechre has raised to the top position.

Introducing mpvc-autostart: automatic start/stop based on presence, 15 Sep 2023

A simple need to have some background music automatically playing while I'm near the device where mpvc is running, lets say, in media center mode, and, pausing the audio when I'm away. A solution for this was to write a small script in extras/mpvc-autostart that periodically pings an IP (for example your phone LAN IP, or alternatively detecting the presence of a Bluetooth device you carry with yourself), then, if the presence of the device is detected, the audio is resumed, otherwise, the audio is paused.

For an example of its usage, just run PERIOD=300 NCHECK=3 mpvc-autostart -i where must be replaced by the LAN IP of your phone. The listing below show the output mpvc-autostart doing periodic pings at 300 sec (5 minutes) intervals. When NCHECK=3 consecutive ping checks fail to detect the device, the audio is paused (pause=true). As soon as one ping check succeeds, the audio is resumed (pause=false). This means that each 300 * 3 seconds (15 minutes) the audio can be paused, and in 5 minutes resumed. Personally I prefer to raise NCHECKS=6, to have about 30 minutes of audio without pauses, anyway, the parameters are there for catter for your needs, just play with them.

user@box mpvc $ PERIOD=300 NCHECK=3 mpvc-autostart -i
# mpvc-autostart mpvc pingscan PERIOD=300 NCHECK=3
# 2023-09-15T19:26+00:00 mpvc-autostart PERIOD=300 NCHECK=6 pause=false c=0 n=0
# 2023-09-15T19:31+00:00 mpvc-autostart PERIOD=300 NCHECK=6 pause=false c=0 n=-1
# 2023-09-15T19:36+00:00 mpvc-autostart PERIOD=300 NCHECK=6 pause=false c=0 n=-2
# 2023-09-15T19:42+00:00 mpvc-autostart PERIOD=300 NCHECK=6 pause=false c=0 n=-3
# 2023-09-15T19:47+00:00 mpvc-autostart PERIOD=300 NCHECK=6 pause=true  c=0 n=0
# 2023-09-15T19:52+00:00 mpvc-autostart PERIOD=300 NCHECK=6 pause=false c=59 n=0 64 bytes from icmp_seq=1 ttl=64 time=104 ms

This approach has some limitations, lets say, sometimes you want to fully disable mpvc-autostart for a time, because:

  1. Disable mpvc-autostart from resuming audio, because you want to concentrate and don't want music messing around.
    Solution: just use the phone to access mpvc-web and set mpvc vol 0 for a time.
  2. Disable mpvc-autostart from pausing audio, because your phone disables wifi, so the audio gets paused when you don't want.
    Solution: as explained above playing with PERIOD and NCHECK parameters, increase the time without pauses, for example NCHECK=6 or NCHECK=12 will pause audio when the device is not seen for 30 or 60 minutes, respectively.

On mpvc usage patterns for playing music/videos, 16 Sep 2023

This entry aims to provide a comprehensive view of the usage patterns of mpvc. Several of the usage patterns have been already covered in the previous entries of the logbook, like: searching online media, manipulating the playlist or playing state, or, using mpvc-stash(1) for storing/replaying the mpv playing state. This entry focuses on combining the previous individual usages into an overall usage pattern for using mpvc for listening music, viewing videos,podcasts, etc. for this mpvc has to carry the following tasks:

Some of the above usage patterns are shown in the asciinerama cast at mpvc casts and captures a video of a live session using mpvc commands to search and play online media and manage the playlist, so probably is worth watching to show the workings. Note that, as always, this is only a personal take on mpvc usage patterns at a point in time, that will probably evolve, and is limited to a personal take on this topic, since others can have completely different usage patterns.

On observing mpv property changes, 26 Oct 2023

Recently basic support for mpvc observe landed on mpvc, to observe mpv property changes. This can be used as show below to watch for volume changes:

$ mpvc observe volume | awk '/property-change/'

On the security of mpvc-web, 17 Nov 2023

Besides the standard fixes, new functionality, and, performance improvements to the core functionality of mpvc, a few tools under extras/ have also received additional attention.

One of the tools is extras/mpvc-web, that as said before, is just "mpvc-tui for the web", that is, a web interface for managing mpvc from a browser, when no terminal is available, this fits a common usage, for example when you are at home, away from the computer, with the phone or tablet at hand and want to manage music playing through mpvc, this is where mpvc-web shines.

However, mpvc-web was and continues being a hack, which is good for development purposes and my current usage, but that also means that security-wise some decisions are questionable in a home LAN, since uses plain HTTP, without authentication nor HTTPS security, and allows running mpvc shell commands as your user!!, that are controlled by making HTTP requests coming the home LAN. So this has been irking me for a time, to a point I was using it less, and, last I've come to a compromise solution that think easily addresses the limitations in authentication and HTTPS security.

The solution has been to change the defaults: so now mpvc-web runs by default on localhost, and, a new option: `MPVC_WEB_SSL_ENABLE=1 mpvc-web` setups a `stunnel(1)` HTTPS connection, this allows to address the HTTPS security part. Next, to address the authentication part, `stunnel(1)` provides peer certificate verification, so using the new option `MPVC_WEB_SSL_ENABLE=1 MPVC_WEB_SSL_VERIFY=2 mpvc-web` only clients that provide a valid peer certificate can connect to mpvc-web.

So, now the following alternatives are available, ordered from less to more secure:

  1. For local purposes, just run mpvc-web that defaults to `localhost` with: `mpvc-web`.
  2. If its safe running plain HTTP on the home LAN, then use: `MPVC_WEB_HOST=0 mpvc-web`.
  3. Otherwise, if its not safe for running plain HTTP on the LAN, then use: `MPVC_WEB_HOST=0 MPVC_WEB_SSL_ENABLE=1 mpvc-web` to require HTTPS.
  4. If additionally, the environment can get attacks from malicious users, then require the use of peer certificates, therefore, limiting access only to those clients/peers that have present valid `stunnel(1)` certificate with: `MPVC_WEB_HOST=0 MPVC_WEB_SSL_ENABLE=1 MPVC_WEB_SSL_VERIFY=2 mpvc-web`

The latter means that the `mpvc-web.p12` peer certificates have to be installed in the client phones/browsers to access mpvc-web from the network, however, is easily accomplished in modern browsers that allow easy import of P12 certs.

So with this security issue addressed, I can keep on using and improving mpvc-web.

On http-streaming media using mpvc-web, 16 Jan 2024

A few changes have been going on extras/mpvc-web , latest changes add the option MPVC_WEB_ARCHIVE_ENABLE to serve the mpvc ytdl-archive/ dir over HTTP/S

Yeah, that's hacky and a kludge, but its also quite handy. As it means that the full archive can be reachable from the LAN over HTTP/S, so if mpvc is running on an central audio/media center, then besides controlling with mpvc-web, you can also easily fetch the archive media files over HTTP/S to share/store them to mobile devices like laptop/tablet/phone.

This also means that you can play that media from a separate device running mpvc, like a laptop, by adding files from the ytdl-archive URL, to browse the ytdl-archive using fzf use mpvc-fzf -b "", this by default queries https://localhost:8443/ytdl-archive/, use mpvc-fzf -b https://your-mediacenter:8443/ytdl-archive/ or any other URL to query other archives.

Stay tuned

On MPRIS support, 14 Feb 2024

MPRIS stands for Media Player Remote Interfacing Specification and its a handy thing to have, as WM have builtin support this to programmatically control media players, meaning that keyboard Media keys work directly for controlling Media players.

Check mpv-mpris for docs/setup, below is a quick setup:

mkdir -p ~/.config/mpv/scripts
curl -fsSL -o ~/.config/mpv/scripts/mpris.so https://github.com/hoyon/mpv-mpris/releases/download/1.0/mpris.so
Then, start a new instance of mpv player that loads `mpris.so`
Check that mpv speaks MPRIS by running `mpvc-mpris status`, or get playerctl

On support UNIXes besides GNU/Linux: BSD and MacOS, 1 Mar 2024

Well, been "moving fast & breaking things" lately (there'll be more breakage to come), yet the goal is achieved, and, now this thing (mpvc) runs on FreeBSD and MacOS. I consider them to be working, and, usable but rought, since are not UNIXes that I do not run regularly.

Introducing mpvc-chapter: helper for managing chapters, 5 Apr 2024

Mpv does a great job on handling chapters, however, sometimes you end up wanting to modify chapters to existing media, or media that lacks chapters. This is the purpose of mpvc-chapter: managing chapter-files. Long story short, basically this boils down to keeping chapter-file under $HOME/.config/mpvc/chapters/. mpvc-chapter -h shows the available cmds:

PS: Although the title says "Introducing mpvc-chapter", it has been present for a long time, it was just an small auxiliar command, missing documentation, the above lines addresses this.

Introducing mpvc-osd: interfacing mpvc with a 4x20 USB LCD, 5 May 2024

While mpvc was playing `The Number 4` from Khruangbin's EP `The Infamous Bill` decided it would be fun to interface mpvc with a USB LCD on the Raspberry PI that acts as a jukebox, so each time a track starts output what's playing now for some seconds, and then poweroff the LCD. Turned out nice and easy by using mpvc-tui -S scrobbling code, and masaging the output to pipe it to the USB LCD for presentation. For the record the output from mpvc-tui is:

    mpvc-tui -S 'echo $(date +"T%H:%M") $(mpvc -f "[%status%] #%position%/%playlistlength% %time% %artist% - %title% - %path%")' 'false'
And this is how it looks: mpvc-osd usblcd

Last-Modified: Sunday, 5 May 2024 by gmt4 Powered by #HTML 🧡 💚 💙