Compare commits

...

2 Commits

Author SHA1 Message Date
63f86aa8e4 Add comments in function get_mb_id. 2024-10-04 20:25:22 -04:00
c7faeb6bc8 get_mb_id now taking artist name as input variable.
The function can now be fed an artist name to be placed in the
MusicBrainz query string. This will allow it to be used in a loop in the
future.
2024-10-04 14:16:04 -04:00

View File

@ -4,9 +4,10 @@
#include <stdlib.h>
#include <unistd.h>
#define version_str "1.0"
#define conf_file "config.ini"
#define mb_url \
"https://musicbrainz.org/ws/2/artist?query=artist:\"Slayer\"&fmt=json"
"https://musicbrainz.org/ws/2/artist?query=artist:\"%s\"&fmt=json"
const char *get_conf_str(char set_key[]) {
const char *prog_conf = malloc(10 * sizeof(char));
@ -65,21 +66,28 @@ void print_conf(const char m_dir[], const int mb_conf,
}
}
const char *get_mb_id() {
const char *get_mb_id(char *artist_name) {
int response_code;
const char *mb_id;
CURL *curl;
CURLcode res;
char *buffer;
long res_len;
char mb_url_full[100];
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, mb_url);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "get_artist_art.py/1.0");
/*Make the artist name URL safe.*/
char *artist_name_esc = curl_easy_escape(curl, artist_name, 0);
printf("%s", artist_name_esc);
/*Format the MB URL to insert the Artist name for the query.*/
snprintf(mb_url_full, sizeof(mb_url_full), mb_url, artist_name_esc);
printf("%s\n", mb_url_full);
curl_easy_setopt(curl, CURLOPT_URL, mb_url_full);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "get_artist_art.py/1.0");
res = curl_easy_perform(curl);
@ -133,7 +141,7 @@ int main(int argc, char **argv) {
}
}
get_mb_id();
get_mb_id("The Beatles");
return EXIT_SUCCESS;
}