-
Notifications
You must be signed in to change notification settings - Fork 2
/
spotiproxy.php
executable file
·51 lines (37 loc) · 1.48 KB
/
spotiproxy.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
<?php
$aRaw = file('http://ws.spotify.com/search/1/track?q='.urlencode($_GET['q']));
$oXml = simplexml_load_string(implode('', $aRaw));
$aData = (array) $oXml;
$returnData = array();
$country = geoip_country_code_by_name($_SERVER['REMOTE_ADDR']);
if (isset($aData['track']) && $aData['track']) {
if (is_array($aData['track'])) {
$aTracks = $aData['track'];
} else {
$aTracks = array($aData['track']);
}
foreach ($aTracks as $track) {
$aTerritories = explode(' ', (string) $track->album->availability->territories);
if (in_array($country, $aTerritories)){
$aArtist = $track->artist;
$artistName = '';
if ($track->artist->count() > 1) {
$aArtists = array();
foreach ($track->artist as $artist) {
$aArtists []= $artist->name;
}
$artistName = implode(', ', $aArtists);
} else {
$artistName = $track->artist->name;
}
$returnData = array(
'uri' => (string) $track['href'],
'name' => (string) $track->name,
'artist' => (string) $artistName,
'length' => (int) $track->length,
);
break;
}
}
}
echo $_GET['callback'].'('.json_encode($returnData).');';