-
Notifications
You must be signed in to change notification settings - Fork 1
/
p3_playlists.php
45 lines (34 loc) · 1.26 KB
/
p3_playlists.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
<?php
#header("Content-type:application/json");
include("cache.php");
include("phpquery/phpQuery.php");
date_default_timezone_set('UTC');
$base_url = "http://sverigesradio.se/sida/latlista.aspx?programid=164&date=";
$date = date("Y-m-d");
$json = array();
$current_index = 0;
/* main loop for playlists */
for($i=0; $i <= 30; $i++) {
$date = date("Y-m-d", strtotime("-". $i ." day"));
$doc = $base_url . $date;
$content = cache_get_contents($doc);
phpQuery::newDocument($content)->find(".songlist");
foreach(pq("tbody tr") as $tr) {
if(pq($tr)->hasClass("expand-container")) {
$json[$current_index] = new stdClass; // How the fuck do you do a object the easiest way??
$json[$current_index]->time = $time = pq("td.time", $tr)->text();
$json[$current_index]->artist = trim(pq("span.artist", $tr)->text());
$json[$current_index]->song = trim(pq("span.title", $tr)->text());
$json[$current_index]->date = $date;
} else {
$json[$current_index]->composerinfo = str_replace("Kompositör: ", "", pq("span.composerinfo", $tr)->text());
$json[$current_index]->spotifylink = pq("a.spotify", $tr)->attr("href");
$current_index++;
}
/* dev purpuse: prints the first 40 */
if($current_index==40) {
echo json_encode($json);
exit;
}
}
}