Skip to content

Instantly share code, notes, and snippets.

@dayt0n
Created April 2, 2016 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dayt0n/5f5fc6da10a024dd176bcaedd7445e21 to your computer and use it in GitHub Desktop.
Save dayt0n/5f5fc6da10a024dd176bcaedd7445e21 to your computer and use it in GitHub Desktop.
Downloads audio from https://clyp.it/
/* clypDownloader - downloads music from clyp.it
*
* compile with: gcc clypDownloader.c -o clypDownloader -lcurl
*
* made by dayt0n
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
char* addVars(char *s1, char *s2)
{
char *result = malloc(strlen(s1)+strlen(s2)+1);
strcpy(result, s1);
strcat(result, s2);
return result;
}
void downloadFile(const char* url, const char* file_name)
{
CURL* easyhandle = curl_easy_init();
curl_easy_setopt( easyhandle, CURLOPT_URL, url ) ;
FILE* file = fopen( file_name, "w");
curl_easy_setopt( easyhandle, CURLOPT_WRITEDATA, file) ;
curl_easy_perform( easyhandle );
curl_easy_cleanup( easyhandle );
fclose(file);
}
int main(int argc, char* argv[]) {
if (argc == 1) {
printf("usage: %s [URL] [outfile]\n",argv[0]);
exit(0);
}
char* songName = strrchr(argv[1],'/');
songName++;
char* downloadURLFirst = addVars("https://a.clyp.it/",songName);
char* downloadURL = addVars(downloadURLFirst,".mp3");
char* output = addVars(argv[2],".mp3");
printf("Downloading %s as %s\n",songName,output);
downloadFile(downloadURL,output);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment