From 1d7003147241e1dff8915534eac3c49c5a6d4155 Mon Sep 17 00:00:00 2001 From: Micheal Smith Date: Thu, 5 Feb 2026 20:42:41 -0600 Subject: [PATCH] Added search by id support --- meson.build | 15 +++++++++++---- omdb.c | 24 +++++++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index 3095d31..6b5d2aa 100644 --- a/meson.build +++ b/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, diff --git a/omdb.c b/omdb.c index b64c5c3..9335475 100644 --- a/omdb.c +++ b/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 " \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");