开发者

Returning different images through PHP

There's a status indicator code for AIM which returns two different images depending on your status (on/offline) which was done in PHP and with the AIM API.

<img src="http://big.oscar.aol.com/USERNAME?on_url=ON_IMAGE&off_url=OFF_IMAGE">

I was looking for a Last.fm widget that shows JUST the album cover I'm listening to or the last album I listened to, but couldn't fin开发者_运维问答d it.

How do I go along making it using PHP and the Last.fm API.


isn't http://www.lastfm.pl/api/show?service=290 enough? Simply parse XML you got as response, and use data extracted from "image" tags.


Well as I see it and will do it probably in python: You have the user user.getRecentTracks, where you can get:

<recenttracks user="RJ" page="1" perPage="10" totalPages="3019">
  <track nowplaying="true">
    <artist mbid="2f9ecbed-27be-40e6-abca-6de49d50299e">Aretha Franklin</artist>
    <name>Sisters Are Doing It For Themselves</name>
    <mbid/>
    <album mbid=""/>
    <url>www.last.fm/music/Aretha+Franklin/_/Sisters+Are+Doing+It+For+Themselves</url>
    <date uts="1213031819">9 Jun 2008, 17:16</date>
    <streamable>1</streamable>
  </track>
  ...
</recenttracks>

Then you have the api call artist.getInfo (the same as album.getInfo), where you can get:

<artist>
  <name>Cher</name>
  <mbid>bfcc6d75-a6a5-4bc6-8282-47aec8531818</mbid>
  <url>http://www.last.fm/music/Cher</url>
  <image size="small">http://userserve-ak.last.fm/serve/50/285717.jpg</image>
  <image size="medium">http://userserve-ak.last.fm/serve/85/285717.jpg</image>
  <image size="large">http://userserve-ak.last.fm/serve/160/285717.jpg</image>
  <streamable>1</streamable>

You'll need only an XML parse to get the images (or just use RegEx). Calling the API you can make with curl request:

For the user info: e.g.: http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=rj&api_key=b25b959554ed76058ac220b7b2e0a026

For the Album Info you can get the Idea witch is in the examples in the link you provided.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜