Skip to content

Instantly share code, notes, and snippets.

@TheCodeArtist
Last active September 12, 2021 17:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TheCodeArtist/2f1b9fa68197e39ca9bc to your computer and use it in GitHub Desktop.
Save TheCodeArtist/2f1b9fa68197e39ca9bc to your computer and use it in GitHub Desktop.
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)
fprintf(stderr,
"curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* free the header list */
curl_slist_free_all(headers);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment