Skip to content

Instantly share code, notes, and snippets.

@clickwir
Forked from orhun/cool.sh
Last active April 10, 2021 20:18
Show Gist options
  • Save clickwir/1b71cedbacddddf06f955359e3fb09f6 to your computer and use it in GitHub Desktop.
Save clickwir/1b71cedbacddddf06f955359e3fb09f6 to your computer and use it in GitHub Desktop.
Random MOD player
#!/usr/bin/env bash
# Get a random music file from modarchive.org and play it.
# Uses VLC. Many other players could work too.
# Check for needed programs. Exit if they are not found.
#if ! which xmp > /dev/null; then echo "xmp not installed. Try: apt install xmp"; exit 1; fi
if ! which vlc > /dev/null; then echo "VLC not installed. Try: apt install vlc"; exit 1; fi
if ! which curl > /dev/null; then echo "curl not installed. Try: apt install curl"; exit 1; fi
# Check if the user wants a specific module
if [ -z $1 ]; then
number=$(shuf -i 1-189573 -n 1)
else
number=$1
fi
tmp=$(mktemp /tmp/${number}.XXXXXXXXXX.mod)
printf "Trying to get https://modarchive.org/jsplayer.php?moduleid=$number \n"
# Go get the file so we can check for 404. VLC can play them directly, but it's handling of 404's is less graceful
if curl https://modarchive.org/jsplayer.php?moduleid=${number} > ${tmp} ; then
if grep "404 Not Found" ${tmp}; then
printf "Download worked, but file is just a 404. Try again!\n"
exit 1
else
# Finally, let's play!
printf "Got $tmp \nPlaying ... \n"
cvlc --play-and-exit ${tmp}
rm ${tmp}
fi
else
printf "curl failed. Sorry.\n"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment