dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

mpvq (1345B)


      1 #!/bin/sh
      2 # Queue one or more files in mpv
      3 if ! [ -S "$HOME"/.cache/mpv/input ]; then
      4     mkfifo "$HOME"/.cache/mpv/input
      5 fi
      6 
      7 # queue the video
      8 play() {
      9   if pgrep -f MPV-Q > /dev/null; then
     10     # TODO: unfortunate dependency on `nc`, try to find a way to send text to socket without dependencies
     11     printf "loadfile \"%s\" append-play\n" "$1" | nc -U "$HOME"/.cache/mpv/input
     12     terminal-notifier -title "Video queued" -message "Added to queue successfully" -group "mpv" 1>/dev/null 2>&1
     13   else
     14     terminal-notifier -title "Playing video" -message "MPV is launching..." -group "mpv" 1>/dev/null 2>&1
     15     # This converts FIFO to a domain socket
     16     setsid -f mpv --idle=yes --volume=50 --no-terminal --x11-name=MPV-Q --input-ipc-server="$HOME"/.cache/mpv/input --log-file="$HOME"/.cache/mpv/mpv.log --player-operation-mode=pseudo-gui "$1"
     17   fi
     18 }
     19 
     20 # link archive
     21 arc(){
     22   [ -d "$HOME/.cache/mpv" ] || mkdir -p "$HOME/.cache/mpv"
     23   title=$(youtube-dl --ignore-config --get-title "$1" 2>/dev/null)
     24   printf "%b\n" "$title\t$1" >> "$HOME/.cache/mpv/linkarchive"
     25 }
     26 
     27 if ! [ -t 0 ]; then
     28   while read -r l; do
     29     entered_read=1
     30     play "$l"
     31     arc "$l" &
     32   done
     33   [ -n "$entered_read" ] && exit 0
     34 fi
     35 
     36 [ $# -eq 0 ] && printf "Links expected as arguments or stdin; none provided.\n" && exit 1
     37 for l in "$@"; do
     38   play "$l"
     39   arc "$1" &
     40 done
     41 exit 0