-
Notifications
You must be signed in to change notification settings - Fork 0
/
spoti.php
78 lines (62 loc) · 2.36 KB
/
spoti.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
76
77
78
<!DOCTYPE html>
<head>
</head>
<body style="background-image: url('ipod2.png');background-repeat: no-repeat;background-color:black">
<?php
// Account & API Account Information
$user = "CENSORED"; // <---- Your username goes here
$key = "CENSORED"; //<-- Your API key goes here
// The URL of the request to API Service
$url = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=$user&api_key=$key&format=json";
// Enable Shortening
$short_titles = true;
// Setup cURL for request
$ch = curl_init( $url );
$options = array(
CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $options);
// Execute cURL
$json = curl_exec($ch);
curl_close($ch);
$data = json_decode($json,true);
$last = $data['recenttracks']['track'][0];
if (isset($last['@attr']['nowplaying'])) {
$output = "" . $last['name'] . ' by ' . $last['artist']['#text'] . " on Spotify";
if ($short_titles) {
$output = sTrim($output);
}
$itsout = trim($output);
echo "<p style='color:black;position: absolute;top: 50px;left:45px;width:145px;font-family: Arial, Helvetica, sans-serif'>Now playing: </p>";
echo "<p style='color:black;position: absolute;top: 70px;left:45px;width:145px;font-family: Arial, Helvetica, sans-serif'><marquee>" . $itsout ."</p></marquee></body></html>";
} else {
$played = $last['date']['uts']; $now = time();
$diff = abs($now - $played);
$hours = intval(intval($diff) / 3600);
$minutes = intval(($diff / 60) % 60);
if (!empty($hours)) {
if ($hours > 24)
$time = "Over a day ago";
else
$time = $hours . " hours and " . $minutes . " minutes ago";
} else
$time = $minutes . " minutes ago";
$output = "Currently not listening :P";
if ($short_titles) {
$output = sTrim($output);
}
$itsout = trim($output);
echo "<p style='color:black;position: absolute;top: 60px;left:45px;width:145px;font-family: Arial, Helvetica, sans-serif'><marquee>" . $itsout ."</p></marquee></body></html>";
}
exit();
function sTrim($output) {
$output = preg_replace("/- Live/i", "", $output);
$output = preg_replace("/- Album Version Explicit/i", "", $output);
$output = preg_replace("/- Explicit Album Version/i", "", $output);
$output = preg_replace("/- Explicit Version/i", "", $output);
$output = preg_replace("/- Album Version/i", "", $output);
$output = preg_replace("/\\[(.*?)\]/i", "", $output);
$output = preg_replace("/\\((.*?)\)/i", "", $output);
return $output;
}
?>