Last.fm Now Playing (Utilizing Last.fm's API)
Platform: mIRC
Published Sep 15, 2011
Updated Sep 15, 2011
This is initially a request by AnaBotNowYourGone who says the script made by tv3636 has ceased to work.
I figure I'd give it a rewrite using last.fm's API to fetch users' now playing song info.
The script will output the trigger as an action text, which is inspired by tv3636's.
I've decided to submit this as a public snippet, because I've found out that the API key is nothing private.
A former last.fm employee name jr has posted it everywhere at last.fm's method instructions.
The script supports both PM and Channel.
Quote
<Jethro> @lastfm jr
* bot jr isn't playing music right now!
<Jethro> .lastfm fadfjkhadksfj
* Bot No user with that name was found!
<Jethro> !lastfm fireninjaxxx
* Bot Last.fm_NP : ♩♪♫ Leftöver Crack - Burn Them Prisons ♩♫♬
You can use any of the !,@, and . trigger prefix to command the script.
It also acknowledges self-trigger using the command:
will output as an echo.
on $*:text:/[!.@]lastfm( |$)/iS:*:{
.ignore -cpu3 $nick 2
$np($strip($2))
}
alias -l lastfm {
return $replace($1,>,>,<,<,&,&)
}
on *:sockread:lastfm*:{
tokenize 96 $sock($sockname).mark
var %lf = $sockname
if ($sockerr) {
$2 $me is having difficulty reading the data from last.fm!
halt
}
sockread &lastfm
if ($regex([ [ $4 ] ],/<error code="6">(.*)</error></lfm>)) {
$2 $+($regml(1),!)
halt
}
elseif (nowplaying !isin [ [ $4 ] ]) {
$2 $1 isn't playing music right now!
sockclose %lf
}
else {
$2 Last.fm_NP : $+($chr(9833),$chr(9834),$chr(9835)) $+($chr(2),$&
$lastfm($gettok($gettok([ [ $4 ] ],6,62),1,60)),$chr(2)) - $+($chr(2),$&
$lastfm($gettok($gettok([ [ $4 ] ],8,62),1,60)),$chr(2)) $&
$+($chr(9833),$chr(9835),$chr(9836))
sockclose %lf
}
}
on *:sockopen:lastfm*:{
tokenize 96 $sock($sockname).mark
if ($sockerr) {
$2 $me is having difficulty connecting to lastfm's website!
halt
}
$5 GET $+(/2.0/?method=user.getrecenttracks&user=,$1,&api_key=,$3) HTTP/1.1
$5 Host: $sock($sockname).addr
$5 Connection: close
$5
}
alias np {
if (!$1) {
.notice $iif($isid,$nick,$me) Please enter a user name! e.g. /np <UserName>
halt
}
var %lastfm $+(lastfm,$r(1,9999),$ticks,$network,$cid)
$+(sock,$iif($sock(%lastfm),close,open)) %lastfm ws.audioscrobbler.com 80
sockmark %lastfm $+($1,`,$iif($isid,.describe $iif(#,#,$nick),echo -at *),`,b25b959$&
$+ 554ed76058ac220b7b2e0a026,`,$!bvar(&lastfm,1-).text,`,sockwrite -nt %lastfm)
}
The API key (public) that was listed here has been deprecated.
You have to sign up for an API key from last.fm to get this script to work again. Just letting you know so you can edit the script a little and maybe put a note in the description.