Compare commits
4 Commits
accept_swi
...
63f86aa8e4
| Author | SHA1 | Date | |
|---|---|---|---|
| 63f86aa8e4 | |||
| c7faeb6bc8 | |||
| 6189a8b17f | |||
| 9530bb9190 |
@@ -1,13 +1,15 @@
|
|||||||
#include <libconfig.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
#include <libconfig.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define version_str "1.0"
|
||||||
#define conf_file "config.ini"
|
#define conf_file "config.ini"
|
||||||
#define mb_url "https://musicbrainz.org/ws/2/artist?query=artist:\"Slayer\"&fmt=json"
|
#define mb_url \
|
||||||
|
"https://musicbrainz.org/ws/2/artist?query=artist:\"%s\"&fmt=json"
|
||||||
|
|
||||||
const char *get_conf_str(char set_key[10]) {
|
const char *get_conf_str(char set_key[]) {
|
||||||
const char *prog_conf = malloc(10 * sizeof(char));
|
const char *prog_conf = malloc(10 * sizeof(char));
|
||||||
config_t cfg;
|
config_t cfg;
|
||||||
config_setting_t *setting;
|
config_setting_t *setting;
|
||||||
@@ -29,7 +31,7 @@ const char *get_conf_str(char set_key[10]) {
|
|||||||
return prog_conf;
|
return prog_conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_conf_int(char set_key[10]) {
|
int get_conf_int(char set_key[]) {
|
||||||
int set_int;
|
int set_int;
|
||||||
config_t cfg;
|
config_t cfg;
|
||||||
config_setting_t *setting;
|
config_setting_t *setting;
|
||||||
@@ -51,7 +53,7 @@ int get_conf_int(char set_key[10]) {
|
|||||||
return set_int;
|
return set_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_conf(const char m_dir[20], const int mb_conf,
|
void print_conf(const char m_dir[], const int mb_conf,
|
||||||
const char ftv_api_key[32]) {
|
const char ftv_api_key[32]) {
|
||||||
if (m_dir != NULL) {
|
if (m_dir != NULL) {
|
||||||
printf("The music directory is: %s\n", m_dir);
|
printf("The music directory is: %s\n", m_dir);
|
||||||
@@ -64,25 +66,34 @@ void print_conf(const char m_dir[20], const int mb_conf,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* get_mb_id(){
|
const char *get_mb_id(char *artist_name) {
|
||||||
int response_code;
|
int response_code;
|
||||||
const char *mb_id;
|
const char *mb_id;
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
long res_len;
|
long res_len;
|
||||||
|
char mb_url_full[100];
|
||||||
|
|
||||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||||
|
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
|
|
||||||
if (curl) {
|
if (curl) {
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, mb_url);
|
/*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);
|
res = curl_easy_perform(curl);
|
||||||
|
|
||||||
if (res != CURLE_OK) {
|
if (res != CURLE_OK) {
|
||||||
fprintf(stderr, "curl_easy_perform() failed with error: %s\n", curl_easy_strerror(res));
|
fprintf(stderr, "curl_easy_perform() failed with error: %s\n",
|
||||||
|
curl_easy_strerror(res));
|
||||||
return "1";
|
return "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,8 +103,9 @@ const char* get_mb_id(){
|
|||||||
|
|
||||||
res = curl_easy_recv(curl, buffer, res_len, 0);
|
res = curl_easy_recv(curl, buffer, res_len, 0);
|
||||||
|
|
||||||
if(res != CURLE_OK){
|
if (res != CURLE_OK) {
|
||||||
fprintf(stderr, "curl_easy_recv() failed with error: %s\n", curl_easy_strerror(res));
|
fprintf(stderr, "curl_easy_recv() failed with error: %s\n",
|
||||||
|
curl_easy_strerror(res));
|
||||||
return "1";
|
return "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,12 +116,9 @@ const char* get_mb_id(){
|
|||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return mb_id;
|
return mb_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int mb_conf, opt;
|
int mb_conf, opt;
|
||||||
const char *m_dir, *ftv_api_key;
|
const char *m_dir, *ftv_api_key;
|
||||||
@@ -118,16 +127,21 @@ int main(int argc, char **argv) {
|
|||||||
mb_conf = get_conf_int("confidence");
|
mb_conf = get_conf_int("confidence");
|
||||||
ftv_api_key = get_conf_str("api_key");
|
ftv_api_key = get_conf_str("api_key");
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "ps:")) != -1){
|
while ((opt = getopt(argc, argv, "ps:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'p':
|
case 'p':
|
||||||
print_conf(m_dir, mb_conf, ftv_api_key);
|
print_conf(m_dir, mb_conf, ftv_api_key);
|
||||||
break;
|
break;
|
||||||
|
case 's':
|
||||||
|
printf("This doesn't do anything yet but you searched for %s\n", optarg);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
printf("So long and thanks for all the fish.\n");
|
printf("So long and thanks for all the fish.\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_mb_id("The Beatles");
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user