blob: 67c4de9bded5880d8f186478e6ae89cb0a36b1ed (
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
52
53
54
|
#!/bin/sh
printhelp() {
cat <<EOF
Usage: ${0##*/} [-v VOL] [DIR]
Play audio files in DIR (or .) in random order
-h Print this help
-v VOL Play with volume VOL (default 100)
EOF
exit 0
}
printusage() {
printf 'Usage: %s [-v volume] [path]\n' "${0##*/}"
exit 1
}
volume=100
while getopts hv: opt; do
case "$opt" in
h) printhelp ;;
v)
if printf %d "$OPTARG" 2>&1 >/dev/null; then
volume="$OPTARG"
else
printf "%s: invalid number '%s'\n" "${0##*/}" "$OPTARG"
exit 1
fi
;;
?) printusage ;;
esac
done
shift $((OPTIND-1))
if [ $# -gt 1 ]; then
printusage
elif [ $# -eq 1 ]; then
dir="$1"
else
dir="$(. "${XDG_CONFIG_HOME:-"$HOME"/.config}/user-dirs.dirs" && printf '%s' "$XDG_MUSIC_DIR")"
fi
prev1=
prev2=
while true; do
file="$(find -L "$dir" -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
|