# last.fm check v1.0 by casn_
#
# checks last.fm for listeners and top track on a given
# artist name. since the listeners are higher on a serious and
# (kinda) famous musicians (on last.fm are mostly music entusiasts9
# are higher, you get a rating capability like imdb for movies.
#
# requirements:
# o lynx
#
#
# just config below and let's go ;<
#
# your trigger
set last(trig) "!lastfm"
# path to your lynx dump file
set last(dump) "/home/luser/eggdrop/lynx.dump"
# chan to use
set last(chan) "#a-lame-chan"
# actual last.fm url to use (don't touch it!)
set last(url) "http://www.last.fm/music/"
# output line start
set last(lay) "\002\[\002last\002.\002fm\002\]\002 "
#########################################################################
bind pub - $last(trig) last_get
set last(debug) 0
proc last_get {nick host hand chan arg} {
global last
putlog "last.fm script triggered"
if {$chan != $last(chan)} {return}
if {[string length $arg] < 1} {
puthelp "PRIVMSG $chan :usage: !lastfm <artist>"
}
set state 0
if {$last(debug) == 1} {putlog "state == 0"}
set listeners "n/a"
set top_week "n/a"
set top_six "n/a"
set suburl [string map {" " "%20"} $arg]
exec lynx --dump $last(url)$suburl > $last(dump)
set fp [open $last(dump) r]
while {![eof $fp]} {
gets $fp line
if {[string match *listeners* $line]} {
set listeners [lindex $line 0]
}
if {$state == 1 && [lindex $line 0] == "1"} {
regexp -indices {(?i)\]} $line location
set top_week [string range $line [expr [lindex $location 0] + 1] end]
set state 2
if {$last(debug) == 1} {putlog "state == 2"}
}
if {[string match "*Top Tracks (last week)*" $line] && $state == 0} {
set state 1
if {$last(debug) == 1} {putlog "state == 1"}
}
if {$state == 3 && [lindex $line 0] == "1"} {
regexp -indices {(?i)\]} $line location
set top_six [string range $line [expr [lindex $location 0] + 1] end]
set state 4
if {$last(debug) == 1} {putlog "state == 4"}
}
if {[string match "*Top Tracks (last six months)*" $line] && $state == 2} {
set state 3
if {$last(debug) == 1} {putlog "state == 3"}
}
}
close $fp
if {$listeners == "n/a"} {
puthelp "PRIVMSG $chan :$last(lay)[string tolower $arg] \002->\002 \0034not found\003\002.\002"
return
}
puthelp "PRIVMSG $chan :$last(lay)[string tolower $arg] \002->\002 listeners: $listeners"
puthelp "PRIVMSG $chan :$last(lay)top track \002(\002last week\002):\002 [string tolower $top_week]"
puthelp "PRIVMSG $chan :$last(lay)top track \002(\002last six months\002):\002 [string tolower $top_six]"
}
putlog "last.fm check by casn_ started."
Last edited by Gordon on Tue Mar 11, 2008 8:48 am, edited 1 time in total.
Easier to re-write it (and use package http, instead of the external lynx binary) and proper regexp's. I'll put it on my todo list. If I get a spurt of ambition I might write it by the weekend.
I only found 1 other lastfm script for "Somafm" in the egghelp archives, so yeah I guess I'll throw this little script together, it's simple and seems somewhat useful.
DragnLord wrote:
... and when someone rewrites the script you posted, you think it will still be the same script?
If the one you have does not work, try another.
You are not making much sense there, sorry.
rosc2112 wrote:http://www.egghelp.org/cgi-bin/tcl_arch ... ad&id=1375 is a nicely written script, but it's for looking up users, not artists.. It also no longer works, afaict, because the url within the script is no longer valid.
I posted a working and updated version of that last.fm script here in the forums, just a few topics down.
On the keyboard of life, always keep one finger on the ESC key.