Skip to content

Instantly share code, notes, and snippets.

@TheCodeArtist TheCodeArtist/listencast.c Secret
Last active Jan 3, 2018

What would you like to do?
Listencast is a simple shoutcast client that connects to any shoutcast server and logs the audio stream data to stdout. Requires libcurl.
/* listencast.c
* A simple shoutcast client that
* - Connects to any shoutcast server and
* - Logs the audio stream data to stdout
* Date 12-02-2013
* Requires libcurl
* $> sudo apt-get install libcurl4-gnutls-dev
* Building listencast.c
* $> gcc listencast.c -o listencast -lcurl
* Running listencast
* $> ./listencast <ip-addr>:<port> > <test.file>
* Attempts to connect to the shoutcast server
* running at <ip-addr> on port <port>. If successful
* then writes the audio stream into the file <test.file>
#include <curl/curl.h>
int main(int argc, char* argv[])
CURL *curl;
CURLcode res;
/* URL of the radio-station in <ip-addr>:<port> format */
char * webaddr = argv[1];
/* init to NULL is important */
struct curl_slist *headers=NULL;
/* Comment the following line to request a pure
* audio stream WITHOUT any periodic channel-info or
* now-playing info embedded in the stream.
headers = curl_slist_append(headers, "Icy-MetaData:1");
/* Obtain a curl object handle */
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, webaddr);
/* pass our list of custom made headers */
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Ideally code following this line is NEVER executed
* as the radio station will reply with a continuous
* never-ending infinite encoded audio stream.
/* Check for errors */
if(res != CURLE_OK)
"curl_easy_perform() failed: %s\n",
/* free the header list */
/* always cleanup */
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.