Added search by id support

This commit is contained in:
Micheal Smith 2026-02-05 20:42:41 -06:00
parent 15657f7ba6
commit 1d70031472
Signed by: xulfer
GPG key ID: E40750BFE6702504
2 changed files with 30 additions and 9 deletions

View file

@ -17,12 +17,11 @@ dependencies = [
curl curl
] ]
sources = [ common_sources = [
'cJSON.c', 'cJSON.c',
'fetch.c', 'fetch.c',
'image.cpp', 'image.cpp',
'omdb.c', 'tiv_lib.cpp',
'tiv_lib.cpp'
] ]
add_project_arguments(cpp_flags, language : 'cpp') add_project_arguments(cpp_flags, language : 'cpp')
@ -30,7 +29,15 @@ add_project_arguments(c_flags, language : 'c')
exe = executable( exe = executable(
'omdb', '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, dependencies : dependencies,
include_directories : include_directories('deps'), include_directories : include_directories('deps'),
install : true, install : true,

24
omdb.c
View file

@ -16,7 +16,7 @@
#define OMDB_URL "http://www.omdbapi.com" #define OMDB_URL "http://www.omdbapi.com"
#define PROJECT_NAME "omdb" #define PROJECT_NAME "omdb"
const char *TITLE_LOOKUP_KEYS[] = { static const char *TITLE_LOOKUP_KEYS[] = {
"Actors", "Awards", "BoxOffice", "Country", "DVD", "Actors", "Awards", "BoxOffice", "Country", "DVD",
"Director", "Genre", "Language", "Metascore", "Plot", "Director", "Genre", "Language", "Metascore", "Plot",
"Production", "Rated", "Ratings", "Released", "Response", "Production", "Rated", "Ratings", "Released", "Response",
@ -34,18 +34,21 @@ static struct option opts[] = {{"api-key", required_argument, NULL, 'k'},
{"id", no_argument, NULL, 'i'}, {"id", no_argument, NULL, 'i'},
{"json", no_argument, NULL, 'j'}, {"json", no_argument, NULL, 'j'},
{"full-plot", no_argument, NULL, 'f'}, {"full-plot", no_argument, NULL, 'f'},
{"search", no_argument, NULL, 's'},
{"search-type", required_argument, NULL, 't'}, {"search-type", required_argument, NULL, 't'},
{"year", required_argument, NULL, 'y'}, {"year", required_argument, NULL, 'y'},
{NULL, 0, NULL, 0}}; {NULL, 0, NULL, 0}};
void print_usage(void) { void print_usage(void) {
printf( fprintf(
PROJECT_NAME stderr, PROJECT_NAME
" <OPTIONS> <TITLE-OR-ID>\n" " <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-j/--json: Output full JSON response.\n"
"\t-k/--api-key: OMDB API Key. (required)\n" "\t-k/--api-key: OMDB API Key. (required)\n"
"\t-f/--full-plot: Output long plot description.\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-t/--search-type: Search type. (optional) [movie, series, episode]\n"
"\t-y/--year: Year of release.\n"); "\t-y/--year: Year of release.\n");
} }
@ -190,6 +193,7 @@ int main(int argc, char **argv) {
int ch; int ch;
bool i_flag = false; bool i_flag = false;
bool k_flag = false; bool k_flag = false;
bool s_flag = false;
char search_mode[8] = "movie"; char search_mode[8] = "movie";
if (argc == 0) { if (argc == 0) {
@ -205,7 +209,7 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE); 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) { switch (ch) {
case 'i': case 'i':
/* Lookup by ID */ /* Lookup by ID */
@ -223,6 +227,9 @@ int main(int argc, char **argv) {
case 'f': case 'f':
set_param(url, "plot", "full"); set_param(url, "plot", "full");
break; break;
case 's':
s_flag = true;
break;
case 't': case 't':
/* Type: movie, series, episode */ /* Type: movie, series, episode */
strlcpy(search_mode, optarg, sizeof search_mode); strlcpy(search_mode, optarg, sizeof search_mode);
@ -247,6 +254,13 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE); 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 remaining params if any... */
set_param(url, "type", search_mode); set_param(url, "type", search_mode);
set_param(url, "r", "json"); set_param(url, "r", "json");