Skip to content

Commit 55cfb5f

Browse files
committed
Added working version of scraper
1 parent fe172a0 commit 55cfb5f

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

lastfmrss-working.php

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
require_once ('simple_html_dom.php');
4+
$user = '';
5+
if (isset($_GET['user'])) {
6+
$user = urlencode ($_GET['user']);
7+
}
8+
if (isset($_GET['loved'])) {
9+
$type = 'loved';
10+
$html = file_get_html("http://www.last.fm/user/{$user}/loved?page=1");
11+
} else {
12+
$type = 'played';
13+
$html = file_get_html("http://www.last.fm/user/{$user}/library?page=1");
14+
}
15+
16+
17+
// Start the output
18+
header("Content-Type: application/rss+xml");
19+
header("Content-type: text/xml; charset=utf-8");
20+
?>
21+
22+
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
23+
<channel>
24+
<lastBuildDate><?php echo gmdate(DATE_RFC822, time()) ?></lastBuildDate>
25+
<language>en</language>
26+
<title>Last.fm : <?php echo $user ?>’s <?php echo $type ?> tracks</title>
27+
<description>
28+
Last.fm : <?php echo $user ?>’s <?php echo $type ?> tracks
29+
</description>
30+
<link>http://www.last.fm/<?php echo $user ?></link>
31+
<ttl>960</ttl>
32+
<generator>splo.me</generator>
33+
<category>Personal</category>
34+
<?php
35+
36+
$i = 0;
37+
foreach($html->find('.js-focus-controls-container') as $row) {
38+
foreach($row->find('.chartlist-name') as $content) {
39+
$artist = $content->find('a',0)->plaintext;
40+
$title = $content->find('a',1)->plaintext;
41+
$link = $content->find('a',1)->href;
42+
43+
$desc = 'https://www.last.fm'. $link;
44+
$desc = '<a href="'.$desc.'">'.$artist.'</a>';
45+
46+
$track_html = file_get_html("http://www.last.fm/user/{$link}");
47+
$track_avatar = $track_html->find('.header-avatar-playlink');
48+
$cover = $track_avatar->find('img',0)->src;
49+
50+
}
51+
foreach($row->find('.chartlist-timestamp') as $timestamp) {
52+
$span = str_get_html(trim($timestamp->innertext)); // don't ask
53+
$span->find('span');
54+
$arr = (array)$span;
55+
$node = (array) $arr['nodes'][1];
56+
$da_time = ($node['attr']['title']);
57+
58+
$playdate = gmdate(DATE_RFC822, strtotime($da_time));
59+
}
60+
?>
61+
<item>
62+
<title><?php echo $artist.' - '.$title ?> </title>
63+
<pubDate><?php echo $playdate; ?></pubDate>
64+
<link>http://www.last.fm<?php echo $link ?></link>
65+
<guid isPermaLink="false"><?php echo $link ?></guid>
66+
<description><![CDATA[<?php echo $desc?>]]></description>
67+
<media:content
68+
xmlns:media="http://search.yahoo.com/mrss/"
69+
url="<?php echo $cover ?>"
70+
medium="image"
71+
type="image/jpeg"
72+
width="150"
73+
height="150" />
74+
</item>
75+
<?php
76+
$i++;
77+
}
78+
?>
79+
</channel>
80+
</rss>

0 commit comments

Comments
 (0)