forked from splorp/lastfm-rss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lastfmrss.php
75 lines (64 loc) · 2.03 KB
/
lastfmrss.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
// http://simplehtmldom.sourceforge.net/
require_once ('simple_html_dom.php');
// Optionally set the default Last.fm username and real name
$user = '';
if (isset($_GET['user'])) {
$user = urlencode ($_GET['user']);
}
// Grab the HTML for the tracks
if (isset($_GET['loved'])) {
$type = 'loved';
$html = file_get_html("http://www.last.fm/user/{$user}/loved?page=1");
} else {
$type = 'played';
$html = file_get_html("http://www.last.fm/user/{$user}/library?page=1");
}
// Start the output
header("Content-Type: application/rss+xml");
header("Content-type: text/xml; charset=utf-8");
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<lastBuildDate><?php echo gmdate(DATE_RFC822, time()) ?></lastBuildDate>
<language>en</language>
<title>Last.fm : <?php echo $user ?> just <?php echo $type ?></title>
<description>
Last.fm : <?php echo $user ?> just <?php echo $type ?>
</description>
<link>http://www.last.fm/user/<?php echo $user ?></link>
<ttl>960</ttl>
<generator>splo.me</generator>
<category>Personal</category>
<?php
$i = 0;
foreach($html->find('.js-focus-controls-container') as $row) {
foreach($row->find('.chartlist-name') as $content) {
$artist = $content->find('a',0)->plaintext;
$title = $content->find('a',1)->plaintext;
$link = $content->find('a',1)->href;
$desc = 'https://www.last.fm'. $link;
$desc = '<a href="'.$desc.'">'.$artist.'</a>';
}
foreach($row->find('.chartlist-timestamp') as $timestamp) {
$span = str_get_html(trim($timestamp->innertext)); // don't ask
$span->find('span');
$arr = (array)$span;
$node = (array) $arr['nodes'][1];
$da_time = ($node['attr']['title']);
$playdate = gmdate(DATE_RFC822, strtotime($da_time));
}
?>
<item>
<title><?php echo $artist.' — '.$title ?> </title>
<pubDate><?php echo $playdate; ?></pubDate>
<link>http://www.last.fm<?php echo $link ?></link>
<guid isPermaLink="false"><?php echo $link ?></guid>
<description><![CDATA[<?php echo $desc?>]]></description>
</item>
<?php
$i++;
}
?>
</channel>
</rss>