Created
September 20, 2011 20:14
-
-
Save abozhilov/1230188 to your computer and use it in GitHub Desktop.
Radio player
This file contains 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
#!/bin/bash | |
#Name: Radio player | |
#Author: Asen Bozhilov | |
#Version: 1.0.0 | |
#License: MIT | |
#Available radio streams | |
RADIO_NAMES=( | |
"Дарик Радио" | |
"Радио 1" | |
"Радио 1 Рок" | |
"БГ Радио" | |
"Радио Вероника" | |
"Радио Веселина" | |
"Радио Витоша" | |
"Радио Energy" | |
"Радио N-Joy" | |
"Радио Z-Rock" | |
"Радио City" | |
"Радио Star FM" | |
"Радио FM+" | |
"Радио Fresh!" | |
"Тангра Мега Рок" | |
"I Hate Mondays Radio" | |
"Радио Реакция" | |
"Pro FM Rock" | |
"Радио Melody" | |
"Радио Романтика" | |
"Радио Татковина" | |
"Радио ФСБ" | |
"Pro FM Rhythm and Blues" | |
"Pro FM Black" | |
"Black Side" | |
"Pro FM Chillout" | |
"Pro FM Love" | |
"Pro FM Oldies" | |
"Pro FM Gold" | |
) | |
RADIO_STREAM=( | |
"http://mp3.orbitel.bg:8000/darik.m3u" | |
"http://80.72.68.217/radio1.ogg.m3u" | |
"http://80.72.68.217/radio1rock.ogg.m3u" | |
"http://80.72.68.217/bgradio.ogg.m3u" | |
"http://80.72.68.217/veronika.ogg.m3u" | |
"http://193.108.24.18:8000/veselina.m3u" | |
"http://193.108.24.18:8000/vitosha.m3u" | |
"http://80.72.68.217/nrj.ogg.m3u" | |
"http://pulsar.atlantis.bg:8000/njoy.ogg.m3u" | |
"http://pulsar.atlantis.bg:8000/zrock.ogg.m3u" | |
"http://62.204.145.218:8000/city64.m3u" | |
"http://pulsar.atlantis.bg:8000/inforadio.ogg.m3u" | |
"http://pulsar.atlantis.bg:8000/fmplus.ogg.m3u" | |
"http://193.108.24.21:8000/fresh.m3u" | |
"http://stream-bg-01.radiotangra.com:8000/Tangra-high.m3u" | |
"http://77.70.53.35:8000/listen.pls" | |
"http://stream.reakcia.net/live.m3u" | |
"http://live.profm.bg:8000/rock.mp3.m3u" | |
"http://193.108.24.21:8000/melody.ogg.m3u" | |
"http://89.190.212.173:8000/listen.pls" | |
"http://67.205.111.204:8000/bg.m3u" | |
"http://91.121.91.172:8557/listen.pls" | |
"http://live.profm.bg:8000/blues.mp3.m3u" | |
"http://live.profm.bg:8000/black.mp3.m3u" | |
"http://88.213.199.204:8070/listen.pls" | |
"http://live.profm.bg:8000/chillout.mp3.m3u" | |
"http://live.profm.bg:8000/love.mp3.m3u" | |
"http://live.profm.bg:8000/oldies.mp3.m3u" | |
"http://live.profm.bg:8000/gold.mp3.m3u" | |
) | |
GENRE_LABELS=( | |
"News" | |
"Rock & Metal" | |
"Pop" | |
"Retro" | |
"Pop Folk" | |
"Sport" | |
"BG music" | |
"Chill Out" | |
"Black & Rhythm and Blues" | |
) | |
#Map radios in genres | |
NEWS=(0 12) | |
ROCK=(2 9 14 15 16 17) | |
POP=(6 7 8 10 11 13) | |
RETRO=(1 18 27 28) | |
POPFOLK=(4 5 19) | |
SPORT=() | |
BGMUSIC=(3 20 21) | |
CHILLOUT=(25 26) | |
BLACK=(22 23 24) | |
#Error codes | |
OUT_OF_RANGE=1 | |
INVALID_ARGUMENT=2 | |
function getGenre { | |
if [ "$1" -eq "0" ] | |
then | |
genre=(${NEWS[@]}) | |
elif [ "$1" -eq "1" ] | |
then | |
genre=(${ROCK[@]}) | |
elif [ "$1" -eq "2" ] | |
then | |
genre=(${POP[@]}) | |
elif [ "$1" -eq "3" ] | |
then | |
genre=(${RETRO[@]}) | |
elif [ "$1" -eq "4" ] | |
then | |
genre=(${POPFOLK[@]}) | |
elif [ "$1" -eq "5" ] | |
then | |
genre=(${SPORT[@]}) | |
elif [ "$1" -eq "6" ] | |
then | |
genre=(${BGMUSIC[@]}) | |
elif [ "$1" -eq "7" ] | |
then | |
genre=(${CHILLOUT[@]}) | |
elif [ "$1" -eq "8" ] | |
then | |
genre=(${BLACK[@]}) | |
else | |
echo "Unknown genre" | |
fi | |
} | |
#Print help | |
if [ -z "$1" -o "$1" = "-h" -o "$1" = "--help" ] | |
then | |
echo "Usage: ./radio [OPTION]... [RADIO INDEX]... | |
Radio script is intended to play an online radio streaming. It requires mplayer. | |
-l List of available radios | |
-p Play radio from list | |
-g Set genre from the list. The list of genres | |
can be seen with -l option. The list of radios | |
in specific genre is available by -l after you have | |
set the genre. | |
Examples: | |
./radio -g -l - list the genres | |
./radio -g 0 -l - list the radios in specific genre | |
./radio -g 0 -p 0 - play the first radio in choisen genre | |
-h, --help Prints this help"; | |
#Print the list of radios | |
elif [ "$1" = "-l" ] | |
then | |
i=0 | |
while [ "$i" -lt "${#RADIO_NAMES[*]}" ] | |
do | |
echo $i "-" ${RADIO_NAMES[$i]} | |
((i++)) | |
done | |
#Play choisen radio | |
elif [ "$1" = "-p" ] | |
then | |
if [ -n "${RADIO_STREAM[$2]}" ] | |
then | |
mplayer -playlist ${RADIO_STREAM[$2]} | |
exit $? | |
else | |
echo "Out of range. Please see the list of available radios." | |
exit $OUT_OF_RANGE | |
fi | |
#By Genres | |
elif [ "$1" = "-g" ] | |
then | |
#List the genres | |
if [ "$2" = "-l" ] | |
then | |
i=0 | |
while [ "$i" -lt "${#GENRE_LABELS[*]}" ] | |
do | |
echo $i "-" ${GENRE_LABELS[$i]} | |
((i++)) | |
done | |
elif [[ $2 =~ ^[0-9]+$ ]] | |
then | |
if [ "$2" -ge "0" -a "$2" -lt "${#GENRE_LABELS[*]}" ] | |
then | |
#get radios by genre and store them in `genre` array | |
getGenre $2 | |
if [ -z "$3" -o "$3" = "-l" ] | |
then | |
echo "================================" | |
echo ${GENRE_LABELS[$2]} | |
echo "================================" | |
i=0 | |
while [ "$i" -lt "${#genre[*]}" ] | |
do | |
echo $i "-" ${RADIO_NAMES[${genre[$i]}]} | |
((i++)) | |
done | |
elif [ "$3" = "-p" ] | |
then | |
if [ -n "${genre[$4]}" ] | |
then | |
mplayer -playlist ${RADIO_STREAM[${genre[$4]}]} | |
exit $? | |
else | |
echo "Out of range. Please see the list of available radios in that genre." | |
exit $OUT_OF_RANGE | |
fi | |
else | |
echo "Use ./radio -h for help" | |
exit $INVALID_ARGUMENT | |
fi | |
else | |
echo "Out of range. Please see the list of available genres." | |
exit $OUT_OF_RANGE | |
fi | |
else | |
echo "Use ./radio -h for help" | |
exit $INVALID_ARGUMENT | |
fi | |
else | |
echo "Use ./radio -h for help" | |
exit $INVALID_ARGUMENT | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment