Created
April 2, 2016 04:15
-
-
Save dayt0n/5f5fc6da10a024dd176bcaedd7445e21 to your computer and use it in GitHub Desktop.
Downloads audio from https://clyp.it/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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