Http Response to shoutcast - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Http Response to shoutcast (
/showthread.php?tid=262262)
Http Response to shoutcast -
ZxPwn420 - 17.06.2011
So I figured that since SHOUTcast displays it's stats in the form of a HTML file, i'd be able to grab the contents of it using the Http request function recently implemented to display the currently playing song using a command.
SHOUTcast outputs it's stats here: http://<IP>:<PORT>/7.html
However, on trying this out, I get the response code 7 which is HTTP_ERROR_MALFORMED_RESPONSE.
Any ideas?
Re: Http Response to shoutcast -
KoczkaHUN - 17.06.2011
You must make an error somewhere, try to do this (you can do it with telnet, too):
(replace Server: and host and port with the shoutcast server's details)
Quote:
C:\Documents and Settings\user>ncat radio.xyz.com 8048
GET /7.html HTTP/1.1
User-Agent: Mozilla/5.0 (Compatible: lolscript 0.1)
Server: radio.xyz.com
|
You have to get an answer like this:
Quote:
HTTP/1.0 200 OK
content-type:text/html
<HTML><meta http-equiv="Pragma" content="no-cache"></head><body>76,1,225,3000,76
,128,Artist - Music</body></html>
|
If you get this answer, check your use of the HTTP library.
Re: Http Response to shoutcast -
ZxPwn420 - 19.06.2011
Thanks for the advice. I've setup pretty much everything now, all I need to do is parse the numbers after each ',' character to retrieve current listeners, current bitrate and current song playing.
EDIT:
Finally, got everything working!
pawn Код:
forward StreamHttpResponse(playerid, response_code, data[]);
enum STREAMDATA
{
CURRENTLISTENERS,
STREAMSTATUS,
PEAKLISTENERS,
MAXLISTENERS,
UNIQUELISTENERS,
BITRATE,
SONGTITLE[32]
}
...
if(strcmp(cmd, "/radiostatus", true) == 0)
{
HTTP(playerid, HTTP_GET, "PHP SCRIPT THAT GRABS 7.HTML", "", "StreamHttpResponse");
return 1;
}
...
public StreamHttpResponse(playerid, response_code, data[])
{
new buffer[128];
if(response_code == 200)
{
new stream[STREAMDATA];
strdel(data, 0, 3);
sscanf(data, "p<,>e<iiiiiis[32]>", stream);
SendClientMessage(playerid, COLOR_RED, "Radio Status");
SendClientMessage(playerid, COLOR_RED, "============");
format(buffer, sizeof(buffer), "Listeners: %d of %d (at %dkbps)", stream[UNIQUELISTENERS], stream[MAXLISTENERS], stream[BITRATE]);
SendClientMessage(playerid, COLOR_GREEN, buffer);
format(buffer, sizeof(buffer), "Current Song: %s", stream[SONGTITLE]);
SendClientMessage(playerid, COLOR_GREEN, buffer);
}
else
{
SendClientMessage(playerid, COLOR_RED, "[Error] The radio must be down or there is a temporary error!");
}
}
Works flawlessly.
Re: Http Response to shoutcast -
KoczkaHUN - 19.06.2011
nice work!