[Tool/Web/Other] ShoutCast API
#1

THIS TOPIC IS OUTDATED, YOU SHOULD READ THE OFFICIAL SHOUTCAST API FROM THEIR WEBSITE





note:
Since 05/22/2013 the API domain has changed from brazucas-dev.com to brazucas-server.com.
Since the end of 2014 the API domain example is offline.



ShoutCast API allow server owners to search for online stations using the a_http include to send a request to the API page and save the output into a file, then use it to display the stations to the players.

Requirements
- dini or json
- a_http include

What can I do with it?
You can do, for example, an Stations Searcher, here is a video (download link of this filterscript can be find at the end of this post)

http://www.youtube.com/watch?v=Qyi3VqSNBas

How to use
you can use the API from http://brazucas-server.com/ShoutCastAPI.php or download the PHP source and host it by yourself.

the usage is simple, there are a few variables that you have to send by GET method to the API page.

show - Which fields you want to show separated by "|"
  • Listeners - number of current listeners
  • Name - Station name
  • ID - Station ID
  • Format - Music format (MP3, AAC, etc)
  • Bitrate - Current bitrate of the station
  • CurrentTrack - Current music playing at the station
  • Genre - Station genre
  • IsRadionomy - * Not currently documented
  • IceUrl - * Not currently documented
  • IsPlaying - * Not currently documented
Usage: show=ID|Listeners|Name|CurrentTrack (http://brazucas-server.com/ShoutCast...e|CurrentTrack)
Default Value: ID|Format|Bitrate|CurrentTrack|Genre|IsRadionomy|I ceUrl|IsPlaying

count - Number of stations founded

Usage: count=20 (http://brazucas-server.com/ShoutCastAPI.php?count=20)
Default Value: 10
Warning: An very large output of the API can crash your server (HTTP function limitation)

* Warning: Field option is currently deprecated and will not work with R2 release.
field - Field that you want to order by your request.
  • Same fields of "show" variable.
Usage: field=listeners (http://brazucas-server.com/ShoutCast...ield=listeners)
Default Value: listeners

* Warning: Order option is currently deprecated and will not work with R2 release.
order - Order your request ascending or descending way.
  • asc - Ascending
  • desc - Descending
Usage: order=asc (http://brazucas-server.com/ShoutCastAPI.php?order=asc)
Default Value: desc

format - Which format you want to use the output.
  • dini
  • json
Usage: format=json (http://brazucas-server.com/ShoutCastAPI.php?format=json)
Default Value: dini

station - Search stations by given text.

Usage: station=text (http://brazucas-server.com/ShoutCast...tation=dubstep)

Request examples
http://brazucas-server.com/ShoutCast...tation=dubstep
  • Will return the two dubstep stations.
http://brazucas-server.com/ShoutCastAPI.php?count=30
  • Will return the current 30 most popular stations.
Getting Stream URL
Since version R2 you can get the station stream url from two ways:

http://localhost/shoutcast.php?stati...7&getStreamUrl
Output:
Код:
"http://173.245.94.220:80/;?icy=http"
  • Will return the stream url as string.
http://localhost/shoutcast.php?count=2&streamUrl
Output:
Код:
s0streamUrl=http://173.245.94.220:80/;?icy=http
s0ID=914897
s0Name=idobi Radio: New. Music. Unfiltered. idobi.com
s0Format=audio/mpeg
s0Bitrate=128
  • Or you can just add the request parameter "streamUrl" in all your requests to the API.
  • Note that "streamUrl" field will be added to the response data.
  • Warning: Requests will be VERY SLOW with "streamUrl" enabled, so be sure you are using a threaded request on your gamemode.
Return data
The structure of the return data looks like this;

Код:
s0ID=914897
s0Name=idobi Radio: New. Music. Unfiltered. idobi.com
s0CurrentTrack=The Baby Grand - Note to Self
s0Listeners=15940
s1ID=175821
s1Name=COOLfahrenheit 93
s1CurrentTrack=Alarm9 -
s1Listeners=5270
s2ID=166835
s2Name=Alex Jones - Infowars.com
s2CurrentTrack=Monday Show Replay - Hr 3
s2Listeners=3550
s3ID=472491
s3Name=COOLfahrenheit 93
s3CurrentTrack=Alarm9 -
s3Listeners=3467
s4ID=637835
s4Name=BlackBeats.FM - finest in blackbeats - powered by surfmusik.de
s4CurrentTrack=
s4Listeners=2996
s5ID=169446
s5Name=Antena1 - SP 94 7 FM
s5CurrentTrack=Antena1 - SP 94 7 FM
s5Listeners=2477
s6ID=132317
s6Name=COOLfahrenheit 93
s6CurrentTrack=Alarm9 -
s6Listeners=2331
s7ID=102286
s7Name=Adom 106.3FM Powered by Mediagh
s7CurrentTrack=
s7Listeners=2168
s8ID=709809
s8Name=ABC Lounge
s8CurrentTrack=Bebel Gilberto - Samba Da Benção
s8Listeners=1844
s9ID=220986
s9Name=COOLcelsius 91.5
s9CurrentTrack=Justin Timberlake - Mirrors
s9Listeners=1611
count=10
where "count" is the number of stations returned.

In-game usage
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/top5stations", cmdtext, true, 9) == 0) {
        HTTP(playerid, HTTP_GET, "brazucas-server.com/ShoutCastAPI.php?show=Name|Listeners&count=5", "", "ShoutCastAPIResponse");

        return 1;
    }
   
    return 0;
}

forward ShoutCastAPIResponse(index, response_code, data[]);
public ShoutCastAPIResponse(index, response_code, data[]) {
    new output[100];
    new key[15];
   
    new File:temp = fopen("ShoutCastAPIOutput.txt", io_write);
    if(temp) {
        fwrite(temp, data);
        fclose(temp);
    }
   
    for(new i = 0; i < dini_Int("ShoutCastAPIOutput.txt", "count"); ++i) {
        format(key, sizeof(key), "s%dName", i);         format(output, sizeof(output), "Station name: %s", dini_Get("ShoutCastAPIOutput.txt", key));
        format(key, sizeof(key), "s%dListeners", i);    format(output, sizeof(output), "%s,listeners: %d", output, dini_Int("ShoutCastAPIOutput.txt", key));
       
        SendClientMessageToAll(0xFF0000FF, output);
    }
    return 1;
}
- Download "In-game fully example" at download section to see an better usage of the API.

Download
- PHP API Source- In-game fully example * currently not working, if you're having trouble implementing the API you can ask me for help via PM

Changelog
  • - R2 release [04/08/2014]
    • Shoutcast.com has updated their website workflow, so urls and request fields has been changed a LOT, Shoutcast API has been rewriten almost from scratch, older versions WILL NOT work anymore.
  • - R1-1 release [02/06/2012]
    • - Fixed bugs related to "playing now" and "name" fields.
Known bugs (not fixed yet)
  • - There are no bugs to fix yet.
Reply
#2

That's cool
Reply
#3

seems that you are the only who liked it, haha.
Reply
#4

Good work
Reply
#5

OM G OMG
i have been trying to make something liek that since year :O
THXX again FOR IT :O
will it be able to retrievve song name? right?
Reply
#6

Quote:
Originally Posted by Niko_boy
Посмотреть сообщение
OM G OMG
i have been trying to make something liek that since year :O
THXX again FOR IT :O
will it be able to retrievve song name? right?
yep, "nowplaying" is the field who holds the song name playing on the radio.

http://brazucas-dev.com/ShoutCastAPI...ame|nowplaying
Reply
#7

Great Job
Reply
#8

update
R1-1 version released.
Reply
#9

oh thanks you again for this bug fix release

EDITfftopic _> wow the online object viewr its too awesome :O ty again :'_
Reply
#10

update (if anyone still use it)
The API domain has been changed to brazucas-server.com, so to access it just use http://www.brazucas-server.com/ShoutCastAPI.php.

brazucas-dev.com are still working as well, but I don't know for how long.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)