forked from dlnetworks/twittercast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shoutcast_v2.php
112 lines (85 loc) · 2.83 KB
/
shoutcast_v2.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
<?php
include 'EpiCurl.php';
include 'EpiOAuth.php';
include 'EpiTwitter.php';
// Consumer key token
$consumer_key = 'xxxxxxxxxxxxxxxxxxxxxx';
// Consumer secret token
$consumer_secret = 'xxxxxxxxxxxxxxxxxxxx';
// Access Token
$token = 'xxxxxxxxxxxxxxxxxxxxx';
// Access Token Secret
$secret= 'xxxxxxxxxxxxxxxxxxxxx';
// Page refresh time in seconds. 0 for none. (only used if updating via browser)
$refresh = "60";
// URL to your Shoutcast server, including port (no http://)
$server = "127.0.0.1:8000";
// Admin password for your Shoutcast server
$password = "changemenow";
// END CONFIGURATION
$twitterObj = new EpiTwitter($consumer_key, $consumer_secret, $token, $secret);
$twitterObjUnAuth = new EpiTwitter($consumer_key, $consumer_secret);
// opens the xml and puts it to a variable for processing
$mysession = curl_init();
curl_setopt($mysession, CURLOPT_URL, "http://$server/admin.cgi?sid=1&mode=viewxml");
curl_setopt($mysession, CURLOPT_HEADER, false);
curl_setopt($mysession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($mysession, CURLOPT_POST, false);
curl_setopt($mysession, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($mysession, CURLOPT_USERPWD, "admin:$password");
curl_setopt($mysession, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($mysession, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$xml = curl_exec($mysession);
curl_close($mysession);
// replace dodgy character encoding data from xml
$xml = str_replace("***x27;", "'", $xml);
$xml = str_replace("'", "'", $xml);
$xml = str_replace(">", ">", $xml);
$tweet = "";
$listeners = "0";
$current_song = "";
// functions for parsing xml data
function startElement($parser, $name, $attrs) {
global $curTag;
$curTag .= "^$name";
}
function endElement($parser, $name) {
global $curTag;
$caret_pos = strrpos($curTag, '^');
$curTag = substr($curTag, 0, $caret_pos);
}
// translate XML data into usable variables
function characterData($parser, $data) {
global $curTag;
// add more variables here to get more info from XML
global $listeners;
global $current_song;
// check your XML stream from sc_serv for the tags available to you
// im just using current listeners and current song title
if ($curTag == "^SHOUTCASTSERVER^CURRENTLISTENERS") {
$listeners = $data;
}
if ($curTag == "^SHOUTCASTSERVER^SONGTITLE") {
$current_song = $data;
}
}
// control for parsing xml data
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
xml_parse($xml_parser, $xml);
xml_parser_free($xml_parser);
if ($refresh != "0")
{
print "<meta http-equiv=\"refresh\" content=\"$refresh\">\n";
}
print "<title>$current_song</title>";
?>
<center>
<?php
// print "$tweet";
print "$current_song";
// tweet that shit
$twitterObj->post('/statuses/update.json', array('status' => $current_song));
?>
</center>