Added search by id support
This commit is contained in:
parent
15657f7ba6
commit
1d70031472
2 changed files with 30 additions and 9 deletions
15
meson.build
15
meson.build
|
|
@ -17,12 +17,11 @@ dependencies = [
|
|||
curl
|
||||
]
|
||||
|
||||
sources = [
|
||||
common_sources = [
|
||||
'cJSON.c',
|
||||
'fetch.c',
|
||||
'image.cpp',
|
||||
'omdb.c',
|
||||
'tiv_lib.cpp'
|
||||
'tiv_lib.cpp',
|
||||
]
|
||||
|
||||
add_project_arguments(cpp_flags, language : 'cpp')
|
||||
|
|
@ -30,7 +29,15 @@ add_project_arguments(c_flags, language : 'c')
|
|||
|
||||
exe = executable(
|
||||
'omdb',
|
||||
[sources],
|
||||
[common_sources, 'omdb.c'],
|
||||
dependencies : dependencies,
|
||||
include_directories : include_directories('deps'),
|
||||
install : true,
|
||||
)
|
||||
|
||||
tmdb_exe = executable(
|
||||
'tmdb',
|
||||
[common_sources, 'tmdb.c'],
|
||||
dependencies : dependencies,
|
||||
include_directories : include_directories('deps'),
|
||||
install : true,
|
||||
|
|
|
|||
24
omdb.c
24
omdb.c
|
|
@ -16,7 +16,7 @@
|
|||
#define OMDB_URL "http://www.omdbapi.com"
|
||||
#define PROJECT_NAME "omdb"
|
||||
|
||||
const char *TITLE_LOOKUP_KEYS[] = {
|
||||
static const char *TITLE_LOOKUP_KEYS[] = {
|
||||
"Actors", "Awards", "BoxOffice", "Country", "DVD",
|
||||
"Director", "Genre", "Language", "Metascore", "Plot",
|
||||
"Production", "Rated", "Ratings", "Released", "Response",
|
||||
|
|
@ -34,18 +34,21 @@ static struct option opts[] = {{"api-key", required_argument, NULL, 'k'},
|
|||
{"id", no_argument, NULL, 'i'},
|
||||
{"json", no_argument, NULL, 'j'},
|
||||
{"full-plot", no_argument, NULL, 'f'},
|
||||
{"search", no_argument, NULL, 's'},
|
||||
{"search-type", required_argument, NULL, 't'},
|
||||
{"year", required_argument, NULL, 'y'},
|
||||
{NULL, 0, NULL, 0}};
|
||||
|
||||
void print_usage(void) {
|
||||
printf(
|
||||
PROJECT_NAME
|
||||
fprintf(
|
||||
stderr, PROJECT_NAME
|
||||
" <OPTIONS> <TITLE-OR-ID>\n"
|
||||
"\t-i/--id: Search by ID rather than title. (optional)\n"
|
||||
"\t-i/--id: Search by IMDB ID rather than title. (optional)\n"
|
||||
"\t-j/--json: Output full JSON response.\n"
|
||||
"\t-k/--api-key: OMDB API Key. (required)\n"
|
||||
"\t-f/--full-plot: Output long plot description.\n"
|
||||
"\t-s/--search: Search for multiple matches rather than a specific "
|
||||
"title/id.\n"
|
||||
"\t-t/--search-type: Search type. (optional) [movie, series, episode]\n"
|
||||
"\t-y/--year: Year of release.\n");
|
||||
}
|
||||
|
|
@ -190,6 +193,7 @@ int main(int argc, char **argv) {
|
|||
int ch;
|
||||
bool i_flag = false;
|
||||
bool k_flag = false;
|
||||
bool s_flag = false;
|
||||
char search_mode[8] = "movie";
|
||||
|
||||
if (argc == 0) {
|
||||
|
|
@ -205,7 +209,7 @@ int main(int argc, char **argv) {
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while ((ch = getopt_long(argc, argv, "hi:jk:ft:y:", opts, NULL)) != -1) {
|
||||
while ((ch = getopt_long(argc, argv, "hi:jk:fst:y:", opts, NULL)) != -1) {
|
||||
switch (ch) {
|
||||
case 'i':
|
||||
/* Lookup by ID */
|
||||
|
|
@ -223,6 +227,9 @@ int main(int argc, char **argv) {
|
|||
case 'f':
|
||||
set_param(url, "plot", "full");
|
||||
break;
|
||||
case 's':
|
||||
s_flag = true;
|
||||
break;
|
||||
case 't':
|
||||
/* Type: movie, series, episode */
|
||||
strlcpy(search_mode, optarg, sizeof search_mode);
|
||||
|
|
@ -247,6 +254,13 @@ int main(int argc, char **argv) {
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Make sure arguments make sense. */
|
||||
if (i_flag && s_flag) {
|
||||
fputs("--id and --search are incompatible.\n", stderr);
|
||||
print_usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Set remaining params if any... */
|
||||
set_param(url, "type", search_mode);
|
||||
set_param(url, "r", "json");
|
||||
|
|
|
|||
Loading…
Reference in a new issue