Skip to content

Instantly share code, notes, and snippets.

@kellbot

kellbot/jukebox.sh Secret

Last active Sep 14, 2020
Embed
What would you like to do?
Fork of Helen 侯-Sandí's Jukebox script
#!/bin/bash
# Update songs list
echo "Updating song list"
curl -s -S https://gist.githubusercontent.com/kellbot/29304e3b18d2c93258b6a205328bb784/raw/gistfile1.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
# Special case for power down
if [[ "10#$ID" -eq "10#0002009068" ]]; then
sudo service mopidy stop
sudo shutdown -h now
exit
fi
# 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=$( cat songs.txt | grep "^${ID}*" | sed 's/.*\s\(.*\)\s\/\/.*/\1/' )
if [[ -z "$URI" ]]; then
continue
fi
mpc stop -q && mpc clear -q && mpc add "$URI" && mpc play
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment