markhuge

Queue Media in mpv

Published by Mark on

I consume all my video (and a lot of my audio) through mpv. I used to queue up media in mpv using taskspooler, but that lacks the ability to go back to a previous video. The native playlist functionality solves this problem, so I decided to use that. The easiest way I could see to do this was leveraging the FIFO command input option in mpv.

I kill and create the fifo whenever I start X by adding this line to my .xinitrc:

# FIFO for mpv queue
rm -f /tmp/mp_pipe && mkfifo /tmp/mp_pipe

I have a few different helper scripts in my ~/bin/:

mmq - start or append to an mpv queue

#!/usr/bin/env bash

MPVPIPE=/tmp/mp_pipe

# See if MPV is already running
if [ -z "$(pidof mpv)" ]; then
  # mpv is not running
  /usr/bin/mpv --no-terminal --input-file="${MPVPIPE}" "${1}" & disown

  # Wait for mpv to be up before moving on to adding anything else to playlist
  while [ -z "$(pidof mpv)" ]; do
    sleep 1
  done

else
  # mpv is running, so add stuff to playlist
  echo "loadfile \"${1}\" append-play" >>  "${MPVPIPE}"
fi

mmf - use fzf to find and enqueue media to mpv

#!/usr/bin/env bash

videos=( "$(/usr/bin/find "${PWD}" -type f -not \( -name "*txt" -o -name "*sfv" \) | /usr/bin/fzf -e -m --bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all)" )

IFS=$'\n'
for video in ${videos[@]}; do $HOME/bin/mmq "$video"; done
unset IFS

mmr - Like mmf but with recently modified files

#!/usr/bin/env bash

videos=( "$(/usr/bin/find "${PWD}" -type f -mtime 0 -not \( -name "*txt" -o -name "*sfv" \) | /usr/bin/fzf -e -m --bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all)" )

IFS=$'\n'
for video in ${videos[@]}; do $HOME/bin/mmq "$video"; done
unset IFS