dotfiles/mpd/usr/bin/mpd-random-albums
Tom Willemse c454bde37c [mpd] Lispify the MPD query
Write a small DSL for converting a simple lisp expression to an MPD query
format. This turns, for example:

    (and (= artist "Katatonia") (= album "Last Fair Deal Gone Down"))

Into:

    ((artist == "Katatonia") AND (album == "Last Fair Deal Gone Down"))

The expressions inside ‘query’ are quasi-quoted, so that variable substitution
is possible.
2022-03-03 01:08:16 -08:00

25 lines
786 B
Scheme
Executable file

#!/usr/bin/env sh
# -*- mode: scheme; -*-
IFS=" "
exec scsh -ll mpd.scm -o mpd -s "$0" "$@"
!#
(define (randomize-all-albums)
(for-each (lambda (album)
(run (mpc findadd album ,album)))
(run/strings (pipe (mpc list album)
(shuf)))))
(define (randomize-albums-by-artist artist)
(for-each (lambda (album)
(run (mpc findadd ,(query (and (= artist ,artist)
(= album ,album))))))
(run/strings (pipe (mpc list album ,(query (= artist ,artist)))
(shuf)))))
(run (mpc clear)
(> /dev/null))
(if (> (length command-line-arguments) 0)
(randomize-albums-by-artist (car command-line-arguments))
(randomize-all-albums))