xml van lastfm uitlezen
http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=digimuse&api_key=b25b959554ed76058ac220b7b2e0a026 wel meest recente resultaten geeft.
Ik vermoed iets met caching mijn server? Maar hoe krijg ik dat weg? Geprobeerd met flush en unset maar geen resultaat.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php include_once("includes/config.php");
$user = ($_GET["user"]);
$xml = simplexml_load_file('http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user='.$user.'&api_key=b25b959554ed76058ac220b7b2e0a026&limit=6');
foreach($xml->xpath('recenttracks/track/artist') as $artist)
{
$arti= array($artist);
}
$art=$arti[0];
$query = "SELECT * FROM spo_links WHERE artist='$art' AND broken<2";
$result = mysql_query($query);
$row= mysql_fetch_object($result);
if (mysql_num_rows($result)== 1){
include_once("toplink2.php");
}
else {
include_once("submitlink.php");
}
?>
$user = ($_GET["user"]);
$xml = simplexml_load_file('http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user='.$user.'&api_key=b25b959554ed76058ac220b7b2e0a026&limit=6');
foreach($xml->xpath('recenttracks/track/artist') as $artist)
{
$arti= array($artist);
}
$art=$arti[0];
$query = "SELECT * FROM spo_links WHERE artist='$art' AND broken<2";
$result = mysql_query($query);
$row= mysql_fetch_object($result);
if (mysql_num_rows($result)== 1){
include_once("toplink2.php");
}
else {
include_once("submitlink.php");
}
?>
Toevoeging op 14/08/2011 10:28:42:
Ik zit op het verkeerde spoor zie ik nu. Het gaat fout met de array. Ik moet de xpath expressie zo aanpassen dat hij de track zoekt met het attribuut "nowplaying->true".
Dat wordt nog even puzzelen. Mocht iemand met meer xpath ervaring hem snel zien, dit is de XML
Code (php)
1
SimpleXMLElement Object ( [@attributes] => Array ( [status] => ok ) [recenttracks] => SimpleXMLElement Object ( [@attributes] => Array ( [user] => Digimuse [page] => 1 [perPage] => 10 [totalPages] => 1311 [total] => 13109 ) [track] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [nowplaying] => true ) [artist] => Noodweer (S&D) [name] => Alles Voor Het Geld [streamable] => 0 [mbid] => SimpleXMLElement Object ( ) [album] => SimpleXMLElement Object ( [@attributes] => Array ( [mbid] => ) ) [url] => http://www.last.fm/music/Noodweer%2B%2528S%2526D%2529/_/Alles+Voor+Het+Geld [image] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [size] => small ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [size] => medium ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [size] => large ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [size] => extralarge ) ) ) ) [1] => SimpleXMLElement Object ( [artist] => Kraak & Smaak [name] => Call Up To Heaven [streamable] => 0 [mbid] => SimpleXMLElement Object ( ) [album] => Electric Hustle [url] => http://www.last.fm/music/Kraak%2B%2526%2BSmaak/_/Call+Up+To+Heaven [image] => Array ( [0] => http://userserve-ak.last.fm/serve/34s/61105043.jpg [1] => http://userserve-ak.last.fm/serve/64s/61105043.jpg [2] => http://userserve-ak.last.fm/serve/126/61105043.jpg [3] => http://userserve-ak.last.fm/serve/300x300/61105043.jpg ) [date] => 14 Aug 2011, 07:03 ) [2] => SimpleXMLElement Object ( [artist] => The Galacticos [name] => Aunt Mary [streamable] => 1 [mbid] => SimpleXMLElement Object ( ) [album] => Paint The Town Rad [url] => http://www.last.fm/music/The+Galacticos/_/Aunt+Mary [image] => Array ( [0] => http://userserve-ak.last.fm/serve/34s/58422949.jpg [1] => http://userserve-ak.last.fm/serve/64s/58422949.jpg [2] => http://userserve-ak.last.fm/serve/126/58422949.jpg [3] => http://userserve-ak.last.fm/serve/300x300/58422949.jpg ) [date] => 14 Aug 2011, 07:00 ) [3] => SimpleXMLElement Object ( [artist] => Cee Lo Green [name] => Fuck You [streamable] => 0 [mbid] => SimpleXMLElement Object ( ) [album] => SimpleXMLElement Object ( [@attributes] => Array ( [mbid] => ) ) [url] => http://www.last.fm/music/Cee+Lo+Green/_/Fuck+You [image] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [size] => small ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [size] => medium ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [size] => large ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [size] => extralarge ) ) ) [date] => 13 Aug 2011, 20:23 )
Toevoeging op 14/08/2011 11:37:29:
Puzzle opgelost: $xml->xpath('//track[@nowplaying="true"]/artist')
Gewijzigd op 14/08/2011 11:38:27 door Hans Handgraaf
Er zijn nog geen reacties op dit bericht.