A last.fm profile poller I wrote after seeing "Last.fm Now Playing (Utilizing Last.fm's API)" by none other than Jethro (thanks for the inspiration, dude!).
The bot displays basic user info and if their currently playing anything.
Configuration: None.
Syntax: !lastfm
Example result: Dustin Sabecky (dsabecky) has scrobbled 11033 tracks and is currently listening to "Turbulence" by Catherine.
; !lastfm trigger
on *:text:!lastfm*:#: {
if (!$2) { msg $nick Syntax: !lastfm <username> }
else { set %fm.user $2 | set %fm.chan $chan | fm_con }
}
; user info connection
alias fm_con { set %fm.count | sockopen lfm ws.audioscrobbler.com 80 | sockopen lfm_np ws.audioscrobbler.com 80 }
; regex XML code
alias fm_s { var %q,%w $regsub($1-,/(<[^>]+>)/g,$null,%q) | return %q }
; announce results
alias fm_ann {
if (%fm.rname) { msg %fm.chan %fm.rname ( $+ %fm.name $+ ) has scrobbled %fm.pc tracks $iif(%fm.np == 1, and is currently listening to $qt(%fm.track) by %fm.art, and is not currently listening to anything) $+ . }
else { msg %fm.chan %fm.name has scrobbled %fm.pc tracks $iif(%fm.np == 1, and is currently listening to $qt(%fm.track) by %fm.art, and is not currently listening to anything) $+ . }
unset %fm.*
}
; sending API requests
on *:sockopen:lfm: {
sockwrite -nt lfm GET /2.0/?method=user.getinfo&user= $+ %fm.user $+ &api_key=b25b959554ed76058ac220b7b2e0a026 HTTP/1.1
sockwrite -nt lfm User-Agent: Mozilla/5.0
sockwrite -nt lfm Host: ws.audioscrobbler.com
sockwrite -nt lfm Accept: text/xml,application/xml,application/xhtml+xml,text/html
sockwrite -nt lfm $crlf
}
on *:sockopen:lfm_np: {
sockwrite -nt lfm_np GET /2.0/?method=user.getrecenttracks&user= $+ %fm.user $+ &api_key=b25b959554ed76058ac220b7b2e0a026 HTTP/1.1
sockwrite -nt lfm_np User-Agent: Mozilla/5.0
sockwrite -nt lfm_np Host: ws.audioscrobbler.com
sockwrite -nt lfm_np Accept: text/xml,application/xml,application/xhtml+xml,text/html
sockwrite -nt lfm_np $crlf
}
; read API results
on *:sockread:lfm: {
if ($sockerr) { msg %fm.chan Sorry, I encountered an error. | unset %fm.* | sockclose lfm }
sockread %fmxml
if (<name> isin %fmxml) { set %fm.name $fm_s(%fmxml) }
if (<realname> isin %fmxml) { set %fm.rname $fm_s(%fmxml) }
if (<playcount> isin %fmxml) { set %fm.pc $fm_s(%fmxml) }
if (<error isin %fmxml) { msg %fm.chan I can't find that username. | unset %fmxml | unset %fm.* | sockclose lfm }
}
on *:sockread:lfm_np: {
if ($sockerr) { msg %fm.chan Sorry, I encountered an error. | unset %fm.* | sockclose lfm_np }
sockread %npxml
if (<track now isin %npxml) { set %fm.np 1 }
if (<artist isin %npxml) && (%fm.artl != 1) { set %fm.artl 1 | set %fm.art $fm_s(%npxml) }
if (<name> isin %npxml) && (%fm.trackl != 1) { set %fm.trackl 1 | set %fm.track $fm_s(%npxml) }
}
; when socket gets closed, if both are closed, read output
on *:sockclose:lfm: {
inc %fm.count
unset %fmxml
if (%fm.count == 2) { fm_ann }
}
on *:sockclose:lfm_np: {
inc %fm.count
unset %npxml
if (%fm.count == 2) { fm_ann }
}
I made a snippet using Last.fm's API here at: http://www.hawkee.com/snippet/8984/
I like the script, even though it doesn't update the information like it should. I ran it through a test and this is the result:
(Tue/01:59:44 PM) <%umadbro> [Last.FM] Chris (BluntKthx) has scrobbled 522 tracks and is currently listening to "Equinox" by Sonny.
(Tue/01:59:56 PM) » (%umadbro) Stupid thing..
(Tue/02:00:00 PM) » (%umadbro) I'm not listening to that..
(Tue/02:00:05 PM) <%umadbro> [Last.FM] Chris (BluntKthx) has scrobbled 523 tracks and is currently listening to "Empire" by Roksonix.
(Tue/02:01:53 PM) <%umadbro> [Last.FM] Chris (BluntKthx) has scrobbled 522 tracks and is currently listening to "Equinox" by Sonny.
(Tue/02:04:40 PM) » (%umadbro) .lastfm
(Tue/02:04:41 PM) <%umadbro> [Last.FM] Chris (BluntKthx) has scrobbled 524 tracks and is currently listening to "No Introduction" by Ransom.
(Tue/02:04:45 PM) » (%umadbro) .lastfm
(Tue/02:04:45 PM) <%umadbro> [Last.FM] BluntKthx has scrobbled 522 tracks and is currently listening to "No Introduction" by Ransom.
As you can see, it kept changing the number of songs I've scrobbled from 522 to 523 then 524 then back to 522. It also kept losing my "real name" as seen in the last line. Also, it wasn't changing the song name like it should. >.<
Overall, good work. :)
It is a program on the computer. I was just informed tonight that one of our dj's and a friend of his built the site, so asked him to imbed the webplayer code into the website. I did post what I found on the site that I am using to run auto dj and am hoping that someone can help me with it so that I can plug it into my bumIRC bot and it will then show dj$nick Artist-Song.
Sorry to be so vague Sunny and hope what little bit I explained helps.
carm
@Carmellia, Post your request in the mIRC snippet request forums. It will attract more attention and will likely render a response faster than notifying just Jethro_ and myself.
Found here: http://www.hawkee.com/phpBB2/viewforum.php?f=9
If you use a hash table, that sort of defeats the purpose of sockmark's availability. The only good thing about hash table is that you can sockread it into a binary variable and refer to the info with the -b switch. It's useful when you have a massive amount of data to be fetched.
P.S. jaytea may have a say on this if he figures what I figure is incorrect.