Author Topic: URL/Last.fm script  (Read 6149 times)

regisdc

  • Guest
URL/Last.fm script
« on: November 21, 2008, 10:44:37 PM »
I want to make a script to retrieve the currently playing song, or last played song from Last.fm.

If you see this link you'll see that it gives back an XML file.

http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=rj&api_key=b25b959554ed76058ac220b7b2e0a026

Anyone willing to help, point out how to do it??  I tried with the vbs style scripts and kept getting nothing back.

DarkStar

  • Full Member
  • ***
  • Posts: 135
  • Scripts for Praise
    • CorpseCorp
Re: URL/Last.fm script
« Reply #1 on: November 22, 2008, 10:55:41 AM »
This should get you started. It retrieves the page and processes it for the artist and song name. The parsing is a little hacked together but it works. If you have any questions feel free to ask; If I get some more free  time I might work on it more.

Code: [Select]
Dim http

Set http = CreateObject("Microsoft.XmlHttp")
url = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=rj&api_key=b25b959554ed76058ac220b7b2e0a026"
http.onreadystatechange = getRef("ProcessData")
http.open "GET", url, True
http.send



Function ProcessData()
if http.readyState = 4 then
    if http.status = 200 then
        response = http.responsetext
        response = Mid(response,instr(response,"<artist"))
        artist = Mid(response,instr(response,">")+1)
        artist = Left(artist,instr(artist,"</artist>")-1)
        response = Mid(response,instr(response,"<name"))
        name = Mid(response,instr(response,">")+1)
        name = Left(name,instr(name,"</name>")-1)
        SendCommand "/echo " & artist & " -- " & name
    end if
end if
End Function
This message brought to you by the Wonderful Wizard of Oz.

regisdc

  • Guest
Re: URL/Last.fm script
« Reply #2 on: November 22, 2008, 01:08:43 PM »
Cheers, it did get me started.

One thing though, is they response text doesn't seem to get updated when the page changes.

I've tried nulling the http object in the bottom of processes to no effect.

It's like the http object is being kept.

DarkStar

  • Full Member
  • ***
  • Posts: 135
  • Scripts for Praise
    • CorpseCorp
Re: URL/Last.fm script
« Reply #3 on: November 22, 2008, 08:33:40 PM »
Checking the xml file, it has not changed since I worked on it this morning.
This message brought to you by the Wonderful Wizard of Oz.

regisdc

  • Guest
Re: URL/Last.fm script
« Reply #4 on: November 22, 2008, 09:57:18 PM »
Checking the xml file, it has not changed since I worked on it this morning.

Try change user (rj) to psycik which is me.

That has changed, but by keeping icechat open , it seems to read xml from cache, rather than from site..

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: URL/Last.fm script
« Reply #5 on: November 23, 2008, 02:35:20 PM »
Usually, sending a random key=(randomvaluehere) as another part of the url will make it get the value, instead of reading it from cache.
The IceChat God

raylu

  • Guest
Re: URL/Last.fm script
« Reply #6 on: April 10, 2009, 12:35:18 PM »
You have entirely defeated the purpose of XML. It should be easy for you to parse because of the strict XML rules.

http://www.xtremevbtalk.com/showthread.php?t=288032