Wikia

Music Player Daemon Community Wiki

Hack:bashfm

Talk0
520pages on
this wiki

Last fm streaming client for the busybox shell

source: http://www.last.fm/group/LastBASH/forum/43627/_/236797

preparations: lynx and egrep are needed

alternative solution: http://files.viharpander.dk/bash/mc/mcf

adapted version for openwrt based router: last.fm for la fonera2

nano /usr/local/root/.bashfm

username=SECRET
password=SECRET
mediaplayer="mpc add"


Here follows the fmstart script:

#!/usr/bin/bash

# "fmstart" starts playing last.fm radio. "fmstart"
# should be used before any other bashfm commands are
# given. It obtains the username, password, and
# mediaplayer from the ".bashfm" file. If the password
# present in the file as plain text, it will be md5
# encoded and the plain text version will be removed.
# It then logs in into Last.fm, obtains the audio
# stream URL, and launches the media player. "fmstart"
# takes no command arguments.

username=`grep "^username=" ~/.bashfm`
username=`expr "$username" : 'username=\(.*\)'`

password=`grep "^password=" ~/.bashfm`
password=`expr "$password" : 'password=\(.*\)'`
password=`echo -n "$password" | sed -e 's/[ ]*$//'`

mediaplayer=`grep "^mediaplayer=" ~/.bashfm`
mediaplayer=`expr "$mediaplayer" : 'mediaplayer=\(.*\)'`
mediaplayer=`echo -n "$mediaplayer" | tr '\' '/'`

if [ ! -z "$password" ]
   then
 passwordmd5=`echo -n $password | md5sum`
 passwordmd5=`expr "$passwordmd5" : '\([0-9A-Fa-f]*\)\.*'`
else
 passwordmd5=`grep "^passwordmd5=" ~/.bashfm`
 passwordmd5=`expr "$passwordmd5" : 'passwordmd5=\(.*\)'`
fi

echo 'username='$username > ~/.bashfm
echo 'password=' >> ~/.bashfm
echo 'mediaplayer='"$mediaplayer" >> ~/.bashfm

echo 'passwordmd5='$passwordmd5 >> ~/.bashfm

login_url='http://ws.audioscrobbler.com/radio/handshake.php?'
login_url="$login_url"'version=1.1.1&platform=linux&username='
login_url="$login_url"$username'&passwordmd5='$passwordmd5
login_url="$login_url"'&debug=0&partner='

echo "login_url=$login_url" >> ~/.bashfm

lynx -source "$login_url" >> ~/.bashfm
echo >> ~/.bashfm

stream_url=`grep "^stream_url=" ~/.bashfm`
stream_url=`expr "$stream_url" : 'stream_url=\(.*\)'`

"$mediaplayer" "$stream_url" &

Here follows the "fmtag" script

#!/usr/bin/bash

# "fmtag" plays the music corresponding to the tag given
# as command argument. The tag needs to be quoted when
# it contains spaces.
#
# Example:
# fmtag 'netlabel'

tag=`echo $1 | sed 's/ /%20/g'`

session=`grep "^session=" ~/.bashfm`
session=`expr "$session" : 'session=\(.*\)'`

tuning_url='http://ws.audioscrobbler.com/radio/adjust.php?'
tuning_url="$tuning_url"'session='$session'&url=lastfm://'
tuning_url="$tuning_url"'globaltags/'$tag'&debug=0'

lynx -source "$tuning_url" > /dev/null

Here follows the "fmart" script.

#!/usr/bin/bash

# "fmart" plays the radio station corresponding to a
# certain artist. It takes the artist's name as command
# line argument. Use quotes when the artist's name
# contains spaces.
#
# Example:
# fmart 'jahcoozi'
 
artist=`echo $1 | sed 's/ /%20/g'`

session=`grep "^session= ~/.bashfm"`
session=`expr "$session" : 'session=\(.*\)'`

tuning_url='http://ws.audioscrobbler.com/radio/adjust.php?'
tuning_url="$tuning_url"'session='$session'&url=lastfm://artist/'
tuning_url="$tuning_url"$artist'/similarartists&debug=0'

lynx -source "$tuning_url" > /dev/null


Here follows the "fmbor" script.

#!/usr/bin/bash

# "fmbor" plays your neighbourhood radio. "fmbor" takes
# no command line arguments.

username=`grep "^username=" ~/.bashfm`
username=`expr "$username" : 'username=\(.*\)'`

session=`grep "^session=" ~/.bashfm`
session=`expr "$session" : 'session=\(.*\)'`

tuning_url='http://ws.audioscrobbler.com/radio/adjust.php?'
tuning_url="$tuning_url"'session='$session'&url=lastfm://user/'
tuning_url="$tuning_url"$username'/neighbours&debug=0'

lynx -source "$tuning_url" > /dev/null


Here follows the "fminfo" script

#!/usr/bin/bash

# "fminfo" returns the name of the artist, name
# of the song and name of the album of the music
# that is currently playing. "fminfo" takes no
# command line arguments.

session=`grep "^session=" ~/.bashfm`
session=`expr "$session" : 'session=\(.*\)'`

info_url='http://ws.audioscrobbler.com/radio/np.php?'
info_url="$info_url"'session='$session'&debug=0'

lynx -source "$info_url" | egrep '(^artist=|^track=|^album=)'

Here follows the "fmskip" script

#!/usr/bin/bash

# "fmskip" skips the song that is currently playing.
# It takes no command line arguments.

session=`grep "^session=" ~/.bashfm`
session=`expr "$session" : 'session=\(.*\)'`

skip_url='http://ws.audioscrobbler.com/radio/control.php?'
skip_url="$skip_url"'session='$session'&command=skip&debug=0'

lynx -source "$skip_url"
echo


Here follows the "fmlove" script

#!/usr/bin/bash

# "fmlove" adds the song that is currently playing to
# the list of loved songs. "fmlove" takes no command
# line arguments.

session=`grep "^session=" ~/.bashfm`
session=`expr "$session" : 'session=\(.*\)'`

love_url='http://ws.audioscrobbler.com/radio/control.php?'
love_url="$love_url"'session='$session'&command=love&debug=0'

lynx -source "$love_url"
echo

Here follows the "fmban" script

#!/usr/bin/bash

# "fmban" bans the current song from your radio. "fmban"
# takes no command line arguments.

session=`grep "^session=" ~/.bashfm`
session=`expr "$session" : 'session=\(.*\)'`

ban_url='http://ws.audioscrobbler.com/radio/control.php?'
ban_url="$ban_url"'session='$session'&command=ban&debug=0'

lynx -source "$ban_url"
echo

Around Wikia's network

Random Wiki