Image works, and looks okay. Added more output.
This commit is contained in:
parent
b0e34a58ea
commit
5a0ffa95fe
3 changed files with 51 additions and 20 deletions
|
|
@ -169,11 +169,12 @@ static void render_and_print_image(unsigned char *data, int width, int height,
|
||||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == -1) {
|
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == -1) {
|
||||||
strerror_r(errno, err_buf, sizeof err_buf);
|
strerror_r(errno, err_buf, sizeof err_buf);
|
||||||
std::cerr << "Couldn't get terminal dimensions: " << err_buf << std::endl;
|
std::cerr << "Couldn't get terminal dimensions: " << err_buf << std::endl;
|
||||||
} else {
|
|
||||||
max_width = w.ws_col * 4;
|
|
||||||
max_height = w.ws_row * 8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Maybe make this configuratble, but quality suffers at smaller sizes.
|
||||||
|
max_width = w.ws_col * 4;
|
||||||
|
max_height = w.ws_row * 8;
|
||||||
|
|
||||||
unsigned char *output_data = data;
|
unsigned char *output_data = data;
|
||||||
int output_width = width;
|
int output_width = width;
|
||||||
int output_height = height;
|
int output_height = height;
|
||||||
|
|
|
||||||
|
|
@ -36,4 +36,4 @@ exe = executable(
|
||||||
install : true,
|
install : true,
|
||||||
)
|
)
|
||||||
|
|
||||||
test('basic', exe)
|
test('basic', exe, args : [ '-k', 'API_KEY', 'Jack Frost' ])
|
||||||
|
|
|
||||||
44
omdb.c
44
omdb.c
|
|
@ -17,18 +17,18 @@
|
||||||
#define PROJECT_NAME "omdb"
|
#define PROJECT_NAME "omdb"
|
||||||
|
|
||||||
const char *TITLE_LOOKUP_KEYS[] = {
|
const char *TITLE_LOOKUP_KEYS[] = {
|
||||||
"Actors", "Awards", "BoxOffice", "Country", "DVD", "Director",
|
"Actors", "Awards", "BoxOffice", "Country", "DVD",
|
||||||
"Genre", "Language", "Metascore", "Plot", "Production",
|
"Director", "Genre", "Language", "Metascore", "Plot",
|
||||||
"Rated", "Ratings", "Released", "Response", "Runtime", "Title",
|
"Production", "Rated", "Ratings", "Released", "Response",
|
||||||
"Type", "Website", "Writer", "Year", "imdbID", "imdbRating",
|
"Runtime", "Title", "Type", "Website", "Writer",
|
||||||
"imdbVotes", NULL};
|
"Year", "imdbID", "imdbRating", "imdbVotes", NULL};
|
||||||
|
|
||||||
/* Default to plain output. */
|
/* Default to plain output. */
|
||||||
static enum _output_format {
|
static enum _output_format {
|
||||||
OUTPUT_JSON,
|
OUTPUT_JSON,
|
||||||
OUTPUT_PLAIN,
|
OUTPUT_PLAIN,
|
||||||
OUTPUT_FANCY
|
OUTPUT_FANCY
|
||||||
} output_format = OUTPUT_PLAIN;
|
} output_format = OUTPUT_FANCY;
|
||||||
|
|
||||||
static struct option opts[] = {{"api-key", required_argument, NULL, 'k'},
|
static struct option opts[] = {{"api-key", required_argument, NULL, 'k'},
|
||||||
{"id", no_argument, NULL, 'i'},
|
{"id", no_argument, NULL, 'i'},
|
||||||
|
|
@ -125,6 +125,28 @@ int verify_title_fields(const cJSON *restrict json) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int print_ratings(const cJSON *restrict ratings_obj) {
|
||||||
|
cJSON *rating = NULL;
|
||||||
|
|
||||||
|
if ((ratings_obj == NULL) || !cJSON_IsArray(ratings_obj)) {
|
||||||
|
fputs("Ratings either doesn't exist, or can't be parsed.", stderr);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_ArrayForEach(rating, ratings_obj) {
|
||||||
|
cJSON *r_source = cJSON_GetObjectItem(rating, "Source");
|
||||||
|
cJSON *r_rating = cJSON_GetObjectItem(rating, "Value");
|
||||||
|
|
||||||
|
if ((r_source == NULL) || (r_rating == NULL))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
fprintf(stderr, "Rated %s by %s\n", r_rating->valuestring,
|
||||||
|
r_source->valuestring);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Print some title information in plain text. */
|
/* Print some title information in plain text. */
|
||||||
int print_title_plain(const cJSON *restrict json) {
|
int print_title_plain(const cJSON *restrict json) {
|
||||||
if (verify_title_fields(json) != 0)
|
if (verify_title_fields(json) != 0)
|
||||||
|
|
@ -137,6 +159,14 @@ int print_title_plain(const cJSON *restrict json) {
|
||||||
printf("%s [%s]\n", title->valuestring, rated->valuestring);
|
printf("%s [%s]\n", title->valuestring, rated->valuestring);
|
||||||
printf("Released on %s\n", released->valuestring);
|
printf("Released on %s\n", released->valuestring);
|
||||||
|
|
||||||
|
print_ratings(cJSON_GetObjectItem(json, "Ratings"));
|
||||||
|
|
||||||
|
cJSON *plot = cJSON_GetObjectItem(json, "Plot");
|
||||||
|
printf("\n%s\n", plot->valuestring);
|
||||||
|
|
||||||
|
cJSON *actors = cJSON_GetObjectItem(json, "Actors");
|
||||||
|
printf("\nStarring %s\n", actors->valuestring);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -190,7 +220,7 @@ int handle_response(struct response *restrict resp) {
|
||||||
break;
|
break;
|
||||||
case OUTPUT_FANCY:
|
case OUTPUT_FANCY:
|
||||||
/* Just print_title + image planned here for now */
|
/* Just print_title + image planned here for now */
|
||||||
print_title_plain(json);
|
print_title_fancy(json);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue