Sunday, May 6, 2012

Playing Radio Stream with Bash Script

Small bash script I wrote to play radio streams trough mplayer. It shows a simple radio list where one can choose the radio stream to be played.
I wrote this a long time ago and it has still some thing written in spanish but it is cery simple and you will find it pretty straight forward.


radio.sh
#!/bin/bash

#Emisoras

SER="http://194.169.201.177:8085/liveser.mp3"
AWESOME80="http://uplink.duplexfx.com:8000"
LITE80="http://uplink.duplexfx.com:8040"
HAIRBAND="http://uplink.duplexfx.com:8014"
THEHEART="http://uplink.duplexfx.com:8006"
BEATLES="http://uplink.duplexfx.com:8062"
GOODTIMEOLDIES="http://uplink.duplexfx.com:8046"
CLASSICALGUITAR="http://uplink.duplexfx.com:8020"

#Comprobar mplayer instalado
PLAYER=$(which mplayer 2> /dev/null)
if [ -z "$PLAYER" ]; then
    printf "Instala mplayer!\n"
    exit 1
fi

DIALOG=$(which dialog 2> /dev/null)
if [ -z "$DIALOG" ]; then
    printf "Instala dialog!\n"
    exit 1
fi

#Terminar con mplayer
killall 2> /dev/null "$PLAYER"

#Seleccionar emisora
EMISORA=$($DIALOG --stdout --title "Radio" --radiolist "Emisoras" 0 0 0 "Cadena SER" "" ON "Awesome 
80's" "" OFF "Lite 80's" "" OFF "80's Hairband" "" OFF "The Heart" "" OFF "Beatles" "" OFF "Good 
Time Oldies" "" OFF "Classical Guitar" "" OFF)

clear

case $EMISORA in
    "Cadena SER")
        printf "Playing Cadena SER\n"
        "$PLAYER" 2>/dev/null "$SER" ;;
    "Awesome 80's")
        printf "Playing Awesone 80's\n"
        "$PLAYER" 2>/dev/null "$AWESOME80" ;;
    "Lite 80's")
        printf "Playing Lite 80's\n"
        "$PLAYER" 2>/dev/null "$LITE80" ;;
    "80's Hairband")
        printf "Playing 80's Hairband\n"
        "$PLAYER" 2>/dev/null "$HAIRBAND" ;;
    "The Heart")
        printf "Playing The Heart\n"
        "$PLAYER" 2>/dev/null "$THEHEART" ;;
    "Beatles")
        printf "Playing Beatles\n"
        "$PLAYER" 2>/dev/null "$BEATLES" ;;
    "Good Time Oldies")
        printf "Playing Good Time Oldies\n"
        "$PLAYER" 2>/dev/null "$GOODTIMEOLDIES" ;;
    "Classical Guitar")
        printf "Playing Classical Guitar\n"
        "$PLAYER" 2>/dev/null "$CLASSICALGUITAR" ;;
    *)
        printf "No se ha encontrado la emisora.\n" ;;
esac

exit 0
Running the script:

No comments:

Post a Comment