-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsong getter icecast kiti direct dynamic
160 lines (139 loc) · 3.73 KB
/
song getter icecast kiti direct dynamic
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
string url = "";
string baseURL = "";
string gMount = "";
key requestid;
//integer VERBOSE = TRUE;
integer VERBOSE = FALSE;
string left(string src, string divider) {
integer index = llSubStringIndex( src, divider );
if(~index)
return llDeleteSubString( src, index, -1);
return src;
}
//string value = left("Colour=Brown", "="); //value == "Colour"
string right(string src, string divider) {
integer index = llSubStringIndex( src, divider );
if(~index)
return llDeleteSubString( src, 0, index + llStringLength(divider) - 1);
return src;
}
//string value = right("Colour=Brown", "="); //value == "Brown"
string remove_HTML_tags(string source)
{
integer is_HTML = FALSE;
string output;
string characterInSource;
integer index;
do
{
characterInSource = llGetSubString(source, index, index);
if (characterInSource == "<")
// {
is_HTML = TRUE;
// }
if (!is_HTML && characterInSource != "\n")
// {
output += characterInSource;
// }
if (characterInSource == ">")
// {
is_HTML = FALSE;
// }
}
while (++index < llStringLength(source));
return
output;
}
string removeMountFromParcelURL(string url)
{
baseURL=url;
if (VERBOSE)
llSay (0, baseURL);
baseURL = right(baseURL,"://");
if (VERBOSE)
llSay (0, baseURL);
baseURL = left(baseURL,"/");
if (VERBOSE)
llSay (0, baseURL);
baseURL = "http://" + baseURL;
if (VERBOSE)
llSay (0, baseURL);
return (baseURL);
}
string getMountFromParcelURL(string url)
{
gMount=url;
if (VERBOSE)
llSay (0, gMount);
gMount = right(gMount,"://");
if (VERBOSE)
llSay (0, gMount);
gMount = right(gMount,"/");
if (VERBOSE)
llSay (0, gMount);
gMount = "/" + gMount;
if (VERBOSE)
llSay (0, gMount);
return (gMount);
}
default
{
on_rez(integer olat)
{
llResetScript();
}
state_entry()
{
url = llGetParcelMusicURL();
baseURL = removeMountFromParcelURL(url);
//baseURL = removeMountFromParcelURL(url);
gMount = getMountFromParcelURL(url);
if (VERBOSE)
llSay (0, "state_entry: " + baseURL);
requestid = llHTTPRequest(baseURL,[HTTP_BODY_MAXLENGTH,8192],"");
llSetTimerEvent(60);
}
http_response(key request_id, integer status, list metadata, string body)
{
string delimiter="Current Song:";
string final_delimiter=" Support";
if (requestid == requestid)
{
// llSetText("Stream" + body,<1,1,1>,1);
if (VERBOSE)
llSay(0, "http_response: " + body);
integer index = llSubStringIndex(body,"Current Song");
if(index == -1)
{
if (VERBOSE)
llSay(0,"Current Song was not found in the string");
}
else
{
if (VERBOSE)
llSay(0,"Current Song was found in the string.");
body = remove_HTML_tags(body);
body = right(body, gMount);
body = right(body, delimiter);
body = left(body, "Mount Point");
body = left(body, final_delimiter);
if (VERBOSE)
llSay(0,body);
llSetText(body,<1,1,1>,1);
}
}
}
timer()
{
if(url == llGetParcelMusicURL())
{
if (VERBOSE)
llSay (0, "timer: " + baseURL);
requestid = llHTTPRequest(baseURL,[HTTP_BODY_MAXLENGTH,8192],"");
}
else
{
llDie();
}
}
}