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.
This commit is contained in:
20xd6 2024-10-04 14:16:04 -04:00
parent 6189a8b17f
commit c7faeb6bc8

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,20 +66,26 @@ 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);
char *artist_name_esc = curl_easy_escape(curl, artist_name, 0);
printf("%s", artist_name_esc);
snprintf(mb_url_full, sizeof(mb_url_full), mb_url, artist_name_esc);
// snprintf(mb_url_full, sizeof(mb_url_full), "%s", curl_easy_escape(curl, mb_url_full, 0));
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 +140,7 @@ int main(int argc, char **argv) {
}
}
get_mb_id();
get_mb_id("The Beatles");
return EXIT_SUCCESS;
}