forked from coissac/moOdeCDPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoodecdplayer
executable file
·65 lines (64 loc) · 1.87 KB
/
moodecdplayer
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
#!/usr/bin/env bash
version='moodecdplyer v0.3 (for Raspi B rev 1 256MB), pb'
MPC="/usr/bin/mpc"
optspec=":vh-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
-)
case "${OPTARG}" in
insert)
name="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
n_tracks="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
echo "$0 Doing option: '--${OPTARG}', values: '${name}' '${n_tracks}'" >&2;
$MPC clear
for i in $(/usr/bin/seq 1 ${n_tracks}); do
$MPC add cdda://dev/${name}/${i}
done
$MPC play 1
#/usr/local/bin/moodeengupdate
exit 0
;;
eject)
name="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
echo "$0 Doing option: '--${OPTARG}', value: '${name}'" >&2;
counter=0
while [ "`$MPC -f '%file%' current | /bin/grep cdda://dev/sr0/`" != "" ]; do
$MPC stop > /dev/null
sleep 1
# If we eject the cd before mpd (v0.35.5-1moode3) stops using it, mpd hangs!
((counter++))
if (( $counter > 5 )); then
# I hate waiting
/lib/udev/cdrom_id --eject-media /dev/$name > /dev/null
systemctl stop mpd
# Will be restarted by moode!
fi
done
$MPC -f "%position% %file%" playlist | /bin/grep cdda://dev/${name}/ | /usr/bin/awk '{print $1}' | $MPC del
/lib/udev/cdrom_id --eject-media /dev/$name > /dev/null
/usr/local/bin/moodeengupdate
exit 0
;;
*)
if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" = ":" ]; then
echo "Unknown option --${OPTARG}" >&2
fi
;;
esac;;
v)
echo $version >&2
exit 0
;;
h)
echo $version >&2
echo "usage: $0 [-h|--insert <device-name (e.g. 'sr0')> <number-of-tracks>|--eject <device-name>]" >&2
exit 2
;;
*)
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
echo "Non-option argument: '-${OPTARG}'" >&2
fi
;;
esac
done
$0 -h