-
-
Save clickwir/1b71cedbacddddf06f955359e3fb09f6 to your computer and use it in GitHub Desktop.
Random MOD player
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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