This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Lastfm script not fully working

Support & discussion of released scripts, and announcements of new releases.
Post Reply
G
Gordon
Voice
Posts: 35
Joined: Wed Apr 04, 2007 11:45 am

Lastfm script not fully working

Post by Gordon »

Could someone look at this and eventually fix it? (Problem with 'top track')
(Gordon) !lastfm metallica
(b0t) [last.fm] metallica -> listeners: 839,286
(b0t) [last.fm] top track (last week): n/a
(b0t) [last.fm] top track (last six months): n/a

Code: Select all

# 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.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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.
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

I do not know why people do not look in the archive, this script is VERY easy to find (and it includes author contact information).
M
MellowB
Voice
Posts: 24
Joined: Wed Jan 23, 2008 6:02 am
Location: Germany
Contact:

Post by MellowB »

DragnLord wrote:I do not know why people do not look in the archive, this script is VERY easy to find (and it includes author contact information).
But thats a completely different script.
On the keyboard of life, always keep one finger on the ESC key.
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

MellowB wrote:
DragnLord wrote:I do not know why people do not look in the archive, this script is VERY easy to find (and it includes author contact information).
But thats a completely different script.
... 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.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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 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.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

G
Gordon
Voice
Posts: 35
Joined: Wed Apr 04, 2007 11:45 am

Post by Gordon »

Very nice.

Good work!
M
MellowB
Voice
Posts: 24
Joined: Wed Jan 23, 2008 6:02 am
Location: Germany
Contact:

Post by MellowB »

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.
Post Reply