-
Notifications
You must be signed in to change notification settings - Fork 1
/
komerz.php
46 lines (31 loc) · 1.14 KB
/
komerz.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
<?php
include_once("YMC/Virus/Song.php");
date_default_timezone_set("Europe/Berlin");
$stations = [
'virus' => '66815fe2-9008-4853-80a5-f9caaffdf3a9',
'srf3' => 'dd0fa1ba-4ff6-4e1a-ab74-d7e49057d96f',
'srf1' => '69e8ac16-4327-4af4-b873-fd5cd6e895a7'
];
$dataPoints = [];
foreach ($stations as $stationName => $id) {
$dataPoints[$stationName] = getDataForChannel($id);
}
echo json_encode($dataPoints);
function getDataForChannel($channelId) {
$songinfoUrl = 'http://ws.srf.ch/songlog/log/channel/'.$channelId.'?fromDate='.str_replace('+02:00', '', date('c', time() - 17200)).'&toDate='.str_replace('+02:00', '', date('c')).'&page.size=1000';
$xml = simplexml_load_file($songinfoUrl);
$songs = [];
foreach ($xml->Songlog as $songlog) {
$song = new \YMC\Virus\Song();
$song->setTitle((string) $songlog->Song->title);
$song->setArtist((string) $songlog->Artist->name);
$metadata = $song->getMetadata();
if ($metadata['spotify']['popularity'] > 0) {
$songs[] = $metadata;
}
if (count($songs) > 5) {
break;
}
}
return $songs;
}