-
Notifications
You must be signed in to change notification settings - Fork 4
/
jukebox.sh
35 lines (26 loc) · 864 Bytes
/
jukebox.sh
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
#!/bin/bash
# Update songs list
echo "Updating song list"
curl -s -S https://raw.githubusercontent.com/helen/swipe-jukebox/master/songs.txt > songs.txt
echo "Jukebox started!"
while read -ep "Swipe: " INPUT; do
# Swipe input contains track delimiters, let's extract just the first number and use it
read -a ID <<< "${INPUT//[^0-9]/ }"
# No number found, bail
if [[ -z "$ID" ]]; then
continue
fi
# Trim leading zeros so it doesn't think this is octal or whatever
ID=$( echo $ID | sed 's/^0*//' )
# Special case for a toggle card - I hope there are never 1000 plastic cards floating around my house
if [[ "$ID" -eq "999" ]]; then
mpc toggle
continue
fi
# Grab the appropriate line from the song list
URI=$( sed "${ID}q;d" songs.txt )
if [[ -z "$URI" ]]; then
continue
fi
mpc stop -q && mpc clear -q && mpc add "$URI" && mpc play
done