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.> @lastfm jr
It also acknowledges self-trigger using the command:
/np <username>
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)
}
Is there a version of this script that broadcasts the song playing in the current irc channel with /np, but doesn't have the public commands? (Like the irssi script here: https://github.com/irssi/scripts.irssi.org/blob/gh-pages/scripts/lastfm.pl)
@HerbTarlek
I made some small modifications to this script for someone as a request you can find it here http://pastebin.com/hmTu6eKs
For the script by hxck you can find it here http://pastebin.com/HC10yAay
chachin, http://www.hawkee.com/snippet/9077/
I tried to base it around the perl version (Play count, loved track, ability to compare users.)
chachin, locate and change this part:
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
}
to this:
else {
$2 Last.fm_NP : $+($chr(2),$&
$lastfm($gettok($gettok([ [ $4 ] ],6,62),1,60)),$chr(2)) - $+($chr(2),$&
$lastfm($gettok($gettok([ [ $4 ] ],8,62),1,60)),$chr(2))
sockclose %lf
}
guys why not make something like this:
.np [17|7:11:47am] 'FightingNavyman' is now playing: Anthrax - Spreading The Disease - Madhouse [playcount 6x] (thrash metal, metal, heavy metal, speed metal) [04:19] [17|7:11:58am] .compare winston_manswallow [17|7:11:59am] 'FightingNavyman' vs 'heroinhero115': 93.5% - Common artists include: Bassnectar, deadmau5, Foo Fighters, Skrillex, Daft Punk OH and this script works awsome 10/10
@DarkGamer120 and @Jethro
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.