Skip to content

Instantly share code, notes, and snippets.

@kellbot
Last active September 14, 2020 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellbot/f8b479c83a686e531a6d4cffa8342862 to your computer and use it in GitHub Desktop.
Save kellbot/f8b479c83a686e531a6d4cffa8342862 to your computer and use it in GitHub Desktop.
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