summaryrefslogtreecommitdiffstats
path: root/mpd-random-albums
blob: 50e6f79e1418726a326f36cd0813bde7f6c84d67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/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))