This repository has been archived by the owner on Mar 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshoutcast.class.php
executable file
·114 lines (103 loc) · 3.29 KB
/
shoutcast.class.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* A simple Class to get all needed Info's from an Shoutcast-Server
*
* @author Starflow <[email protected]>
* @version 1.0.0
*/
class shoutcast {
/**
* @var string IP of the SC-Server
* @access private
*/
private $ip;
/**
* @var int Port the SC-Server listens on
* @access private
*/
private $port;
/**
* @var string Password for the admin.cgi
* @access private
*/
private $pass;
/**
* @var string Complete URL to the XML-Data generated by the SC-Server
* @access private
*/
private $xmlURL;
/**
* @var string User for the admin.cgi
* @access private
*/
private $user = 'admin';
/**
* Constructor
* Creates an Shoutcast Object and initalises the Member Vars
*
* @param string $ip IP of the SC-Server
* @param string $port Port the SC-Server listens on
* @param string $pass Password for the admin.cgi
*/
public function __construct( $ip, $port, $pass ) {
$this->ip = $ip;
$this->port = $port;
$this->pass = $pass;
$this->xmlURL = 'http://' . $this->ip . ':' . $this->port . '/admin.cgi?mode=viewxml';
}
/**
* Returns the Stats from the Shoutcast XML as Array
* (Songhistory not included, use getShoutcastHistory() to get the Songhistory)
*
* @return array
*/
public function getShoutcastData() {
$xml = simplexml_load_string( $this->getXML() );
$array = get_object_vars( $xml );
unset( $array['SONGHISTORY'] );
foreach( $array as $key => $value ) {
if( is_object( $array[$key] ) && !empty( $array[$key] ) ) {
$array[$key] = get_object_vars( $array[$key] );
} elseif( empty( $array[$key] ) && $array[$key] !== '0' ) {
unset( $array[$key] );
}
}
return $array;
}
/**
* Returns the Songhistory from the given Shoutcastserver as Array
*
* @return array
*/
public function getShoutcastHistory() {
$xml = simplexml_load_string( $this->getXML() );
$history = $xml->SONGHISTORY;
$history = get_object_vars( $history );
foreach( $history['SONG'] as $key => $value ) {
if( is_object( $history['SONG'][$key] ) && !empty( $history['SONG'][$key] ) ) {
$history['SONG'][$key] = get_object_vars( $history['SONG'][$key] );
} elseif( empty( $history['SONG'][$key] ) && $history['SONG'][$key] !== '0' ) {
unset( $history['SONG'][$key] );
}
}
return $history['SONG'];
}
/**
* Gets the XML-Data generated by the Shoutcast Server
*
* @return string
* @access private
*/
private function getXML() {
$header = array(
'http' => array(
'header' => 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0' . "\r\n" .
'Authorization: Basic ' . base64_encode( $this->user . ':' . $this->pass ) . "\r\n",
),
);
$context = stream_context_create( $header );
$xml = file_get_contents( $this->xmlURL, false, $context );
return $xml;
}
}
?>