-
Notifications
You must be signed in to change notification settings - Fork 0
/
microGranny
executable file
·83 lines (76 loc) · 1.9 KB
/
microGranny
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
set -o nounset -o pipefail -o errexit
UUID=6137-6233
SUDO=
ACTION=list
PLAYER=${PLAYER-mpv}
while getopts "pluS-U:h" OPT; do
case $OPT in
S) SUDO=sudo ;;
l) ACTION=list ;;
p) ACTION=play ;;
u) ACTION=upload ;;
h) ACTION=usage ;;
U) UUID=$OPTARG ;;
-) break ;;
?) exit 2 ;;
esac
done
shift $((OPTIND-1))
TMP=$(mktemp -d)
MNT=$TMP/mnt
cleanup() {
if test -d "$MNT" && findmnt --noheadings "$MNT" &> /dev/null; then
sync
$SUDO umount "$MNT"
fi
rm -rf "$TMP"
}
trap 'cleanup' EXIT
do_mount() {
mkdir -p "$MNT"
$SUDO mount "/dev/disk/by-uuid/$UUID" "$MNT"
}
if [ "$ACTION" = "list" ]; then
do_mount
ls -l "$MNT"
elif [ "$ACTION" = "play" ]; then
do_mount
dialog --separate-output --checklist "Playlist" 25 80 5 \
$(find "$MNT" -iname "*.wav" -exec basename "{}" \; | sed 's,^\(.*\)$,'"$MNT"'/\1 \1 off,') \
2>"$TMP/playlist"
cat "$TMP/playlist"
$PLAYER --playlist="$TMP/playlist"
elif [ "$ACTION" = "upload" ]; then
do_mount
for i in "$@"; do
PRE=$TMP/$(basename "$i").pre.flac
POST=$TMP/$(basename "$i").post.wav
ffmpeg -i "$i" "$PRE"
sox "$PRE" -b 16 "$POST" channels 1 rate 22050 norm
$PLAYER "$POST"
read -rp "Yay or nay? " POST_CHOICE
case "$POST_CHOICE" in
y|Y)
ls "$MNT"
read -rp "Name? " BASENAME
$SUDO cp -v "$POST" "$MNT/$BASENAME.wav"
;;
esac
done
elif [ "$ACTION" = "usage" ]; then
cat <<EOF 1>&2
$(basename "$0") [OPTION]... [SAMPLE]...
actions:
-l list files on SD-card (default)
-p play sample
-u encode and upload SAMPLE:s
-h show this message
options:
-u UUID set the UUID of the SD-card
-S use sudo
EOF
else
echo "unsupported action: $ACTION" 2>&1
exit 1
fi