blob: 33f7b95a8b066af131fc07829bdfd411f4fa2ac4 (
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#!/bin/sh
printhelp() {
cat <<EOF
Usage: ${0##*/} [-v VOL] [PATHS...]
Play audio files in PATHS (or .) in random order
-h Print this help
-v VOL Play with volume VOL (default 100)
EOF
exit 0
}
printusage() {
printf 'Usage: %s [-v VOL] [PATHS...]\n' "${0##*/}"
exit 1
}
volume=100
while getopts hv: opt; do
case "$opt" in
h) printhelp ;;
v)
if printf %d "$OPTARG" >/dev/null 2>&1; then
volume="$OPTARG"
else
printf "%s: invalid number '%s'\n" "${0##*/}" "$OPTARG"
exit 1
fi
;;
?) printusage ;;
esac
done
shift $((OPTIND-1))
if [ $# -lt 1 ]; then
# set -- "$(. "${XDG_CONFIG_HOME:-"$HOME"/.config}/user-dirs.dirs" && printf '%s' "$XDG_MUSIC_DIR")"
set -- .
fi
prev1=
prev2=
while true; do
file="$(find -L "$@" -type f \( -name '*.m4a' -o -name '*.opus' \) ! -path "$prev1" ! -path "$prev2" -exec shuf -n1 -e '{}' +)"
prev1="$prev2"
prev2="$file"
printf 'Playing %s\n' "${file#$dir/}"
mpv --volume="$volume" "$file"
done
|