Streaming Radio Internet di Ubuntu

Sebenarnya di Ubuntu sudah ada beberapa software radio streaming yang mumpuni dengan GUI yang friendly, misalnya Rhythmbox. Tapi kalau untuk mendengarkan radio, mungkin kita tidak memerlukan GUI yang memakan resources PC/Laptop tersebut. Menurut saya lebih asyik jika bisa dijalankan dari terminal dan radio berjalan di proses background.

Ternyata caranya mudah, sama dengan cara membuat Raspberry Pi sebagai radio internet. Lha wong sama-sama berbasis Ubuntu, hehehe…

Pertama kita install xmms dari terminal. Berikut caranya:

sudo apt-get install xmms2 xmms2-plugin-all

Kemudian kita bikin script radio. Script bisa di-copy paste dari Radio Script. Namun sebagai arsip saya copy paste di sini.

Pertama kita bikin file radio di /usr/local/bin dengan cara berikut ini di terminal:
sudo nano /usr/local/bin/radio

Setelah editor nano muncul, copy dan paste script berikut:


#!/bin/bash
#
# Radio station script for xmms2
# by
#
# Version 1.0.2
# 2013-03-12
# http://www.dronkert.net/misc/radio.html
#

# Variables
PLAYER=/usr/bin/xmms2
DBNAME=.radiodb
DBFILE=~/$DBNAME
DEFVOL=90
ADJVOL=5

# Error codes
declare -i ERR_OK=0
declare -i ERR_HELP=1
declare -i ERR_DBNOTFOUND=2
declare -i ERR_IDNOTFOUND=3

# Copy/redirect output to stderr
function StdErr () {
cat - 1>&2
}

# Help
if [[ "$1" == "help" || "$1" == "--help" || "$1" == "/help" || \
"$1" == "-h" || "$1" == "/h" || \
"$1" == "?" || "$1" == "-?" || "$1" == "/?" ]]; then
echo | StdErr
echo " Usage:" | StdErr
echo " - Which station is on? : radio" | StdErr
echo " - Tune to a station : radio " | StdErr
echo " - List all stations : radio list" | StdErr
echo " - Show or adjust volume : radio vol [ + | - | min | max | def | 0..100 ]" | StdErr
echo " - Mute or unmute : radio mute" | StdErr
echo " - Turn radio on or off : radio on | off" | StdErr
echo | StdErr
exit $ERR_HELP
fi

# Display current station/stream/volume if no argument
if [ -z "$1" ]; then
curvolume=$($PLAYER server volume | grep --colour=never -m 1 -oP '\d+')
curstream=$($PLAYER info | grep --colour=never -m 1 -F '[server] url = ' | grep --colour=never -oP '\S+$')
if [ -z "$curstream" ]; then
curstation="(no stream found)"
else
if [ -f $DBFILE ]; then
curstation=$(cat $DBFILE | grep --colour=never -m 1 -F "$curstream" | grep --colour=never -oP '^\S+')
if [ -z "$curstation" ]; then
curstation="(station not found)"
fi
else
curstation="(station database not found at \"$DBFILE\")"
fi
fi
echo
if [ ! -z "$curstation" ]; then
echo -n " Station : "
echo $curstation
fi
if [ ! -z "$curstream" ]; then
echo -n " Stream : "
echo $curstream
fi
if [ ! -z "$curvolume" ]; then
echo -n " Volume : "
echo $curvolume
fi
echo
exit $ERR_OK
fi

# List station IDs from station database
if [[ "$1" == "list" ]]; then
if [ -f $DBFILE ]; then
echo
echo " List of all stations:"
cat $DBFILE | grep --color=never -oP "^\S+" | sort | sed s/^/\\t/
echo
exit $ERR_OK
else
echo | StdErr
echo " Station database not found at \"$DBFILE\"" | StdErr
echo | StdErr
exit $ERR_DBNOTFOUND
fi
fi

# Turn radio on
if [[ "$1" == "on" ]]; then
# TODO: check if a radio stream is lined up
$PLAYER play
exit $ERR_OK
fi

# Turn radio off
if [[ "$1" == "off" ]]; then
$PLAYER stop
exit $ERR_OK
fi

# Display volume, optionally set or adjust or mute/unmute
if [[ "$1" == "vol" || "$1" == "mute" ]]; then
declare -i curvol=$($PLAYER server volume | grep --colour=never -m 1 -oP '\d+')
declare -i newvol=$curvol
declare -i minvol=0
declare -i maxvol=100
if [[ "$1" == "mute" || "$2" == "mute" ]]; then
if (( $curvol > $minvol )); then
newvol=$minvol
else
newvol=$DEFVOL
fi
else
if [ ! -z "$2" ]; then
if [[ "$2" == "min" ]]; then
newvol=$minvol
elif [[ "$2" == "max" ]]; then
newvol=$maxvol
elif [[ "$2" == "def" ]]; then
newvol=$DEFVOL
elif [[ "$2" == "+" ]]; then
(( newvol = $curvol + $ADJVOL ))
elif [[ "$2" == "-" ]]; then
(( newvol = $curvol - $ADJVOL ))
else
newvol="$2"
fi
if (( $newvol > $maxvol )); then
newvol=$maxvol
elif (( $newvol < $minvol )); then
newvol=$minvol
fi
fi
fi
if (( $newvol != $curvol )); then
$PLAYER server volume $newvol
curvol=$newvol
fi
echo
echo -n " Volume: "
echo $curvol
echo
exit $ERR_OK
fi

# Argument is a Station ID
# Escape argument for use with grep -P
# Is it really safe? Not sure. Couldn't make escaping ] work, for instance.
safe=$(echo "$1" | sed -e 's/\s*//g' | sed -e 's/[\[\\^$.*?"-]/\\/g')
[ -f $DBFILE ] && stream=$(cat $DBFILE | grep --color=never -m 1 -P "^$safe\s" | grep --color=never -oP '\S+$')

if [ -z "$stream" ]; then
echo | StdErr
echo " Station \"$1\" not found." | StdErr
echo " List stations : radio list" | StdErr
echo " Usage info : radio help" | StdErr
echo | StdErr
exit $ERR_IDNOTFOUND
fi

$PLAYER stop
$PLAYER playlist clear
$PLAYER server volume $DEFVOL
$PLAYER add $stream
$PLAYER play
exit $ERR_OK

Jangan lupa buat mode akses file radio tsb ke 755 supaya bisa diakses oleh semua user. Caranya:

sudo chmod 755 /usr/local/bin/radio

Setelah itu kita perlu buat file database stasiun radio supaya kita gampang mengaksesnya. Cara buatnya adalah dengan membuat file .radiodb di home directory. Berikut cara bikin untuk user yg aktif:

nano ~/.radiodb

Kemudian tambahkan URL streaming radio Prambors FM Jakarta berikut ini:

1 http://indo.masima.rastream.com/masima-pramborsjakarta

Jika sudah, maka cara menjalankannya sama dengan radio RPi kemarin, yaitu:

radio 1

Sudah keluar suaranya beluuuum? Cara ini kayaknya lebih hemat resources CPU dari pada harus streaming lewat http://radiopramborsfm.com/streaming. Untuk menambahkan stasiun radio lain tinggal menambahkan alamat streamingnya di file .radiodb.

Iklan

Tentang Emanuel Setio Dewo

Tumbuh, Berkembang, Berbuah...
Pos ini dipublikasikan di Personal dan tag , , . Tandai permalink.

Satu Balasan ke Streaming Radio Internet di Ubuntu

  1. Domain murah berkata:

    pusingnya bukan main pasti

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s