Adds functionality to use command line switches.

The program will now accept the following switches:
-p to print the values stored in the config file.
-s NOT IMPLIMENTED YET. Will be used later to search for a given artist.
This commit is contained in:
20xd6 2024-10-04 11:09:17 -04:00
parent 5e88e7c2c3
commit 39c6a1bcc1

View File

@ -1,8 +1,11 @@
#include <libconfig.h>
#include <unistd.h>
#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>
#define conf_file "config.ini"
#define mb_url "https://musicbrainz.org/ws/2/artist?query=artist:\"Slayer\"&fmt=json"
const char *get_conf_str(char set_key[10]) {
const char *prog_conf = malloc(10 * sizeof(char));
@ -40,7 +43,7 @@ int get_conf_int(char set_key[10]) {
return 1;
}
setting = config_lookup(&cfg, set_key);
setting = config_lookup(&cfg, set_key);
set_int = config_setting_get_int(setting);
config_destroy(&cfg);
@ -61,15 +64,70 @@ void print_conf(const char m_dir[20], const int mb_conf,
}
}
int main() {
int mb_conf;
const char* get_mb_id(){
int response_code;
const char *mb_id;
CURL *curl;
CURLcode res;
char *buffer;
long res_len;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, mb_url);
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed with error: %s\n", curl_easy_strerror(res));
return "1";
}
curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &res_len);
buffer = malloc(res_len);
res = curl_easy_recv(curl, buffer, res_len, 0);
if(res != CURLE_OK){
fprintf(stderr, "curl_easy_recv() failed with error: %s\n", curl_easy_strerror(res));
return "1";
}
printf("Response body: %s\n", buffer);
free(buffer);
curl_easy_cleanup(curl);
}
return mb_id;
}
int main(int argc, char **argv) {
int mb_conf, opt;
const char *m_dir, *ftv_api_key;
m_dir = get_conf_str("dir");
mb_conf = get_conf_int("confidence");
ftv_api_key = get_conf_str("api_key");
print_conf(m_dir, mb_conf, ftv_api_key);
while ((opt = getopt(argc, argv, "ps:")) != -1){
switch (opt) {
case 'p':
print_conf(m_dir, mb_conf, ftv_api_key);
break;
default:
printf("So long and thanks for all the fish.\n");
break;
}
}
return EXIT_SUCCESS;
}