/* * spmeta.h — scorpiox-scorpioplayer-metadata-client: pure C99 read-only metadata client * for the THIRD-PARTY services SCORPIO PLAYER uses to identify a film/show/podcast: * TMDb (api.themoviedb.org), OMDb (www.omdbapi.com), iTunes Search (itunes.apple.com). * * Out of scope (SPEC section 0): spimdb/gcp.scorpioplayer.com (shipped engine covers it), * search-engine scraping (removed on purpose), podcast RSS parsing (scorpiox-podcastfeed). * * Rules: * - API keys are REQUIRED parameters with no default (ERR_NO_KEY if unset). Never hardcode. * - Ratings/popularity are integer per-mille (D18) — no float formatting crosses the FFI. * - Strings returned by getters are library-owned, valid until the next spmeta_* call on * the same (thread's) state. Copy immediately. * - All JSON via vendored yyjson (family rule 14). * - --test must never hit a third-party API: fake backend only. */ #ifndef SPMETA_H #define SPMETA_H #include #include "scorpiox_io.h" #ifdef __cplusplus extern "C" { #endif #if defined(_WIN32) # if defined(SPMETA_BUILD) # define SPMETA_API __declspec(dllexport) # else # define SPMETA_API __declspec(dllimport) # endif #else # define SPMETA_API __attribute__((visibility("default"))) #endif #define SPMETA_VERSION "1.0.0" /* ---- error taxonomy (SPEC section 3) ---- */ #define SPMETA_OK 0 #define SPMETA_ERR_TRANSPORT -1 /* IO backend failure: DNS/TLS/timeout/no network */ #define SPMETA_ERR_HTTP -2 /* completed, non-2xx (spmeta_last_http_code) */ #define SPMETA_ERR_AUTH -3 /* TMDb 401 (bad/absent key) */ #define SPMETA_ERR_RATE_LIMITED -4 /* Apple 403 / TMDb 429 — recoverable, back off */ #define SPMETA_ERR_JSON -5 /* body present but not valid JSON */ #define SPMETA_ERR_NOT_FOUND -6 /* OMDb Response:False; TMDb empty results[] */ #define SPMETA_ERR_EMPTY -7 /* parsed but nothing usable */ #define SPMETA_ERR_NO_KEY -8 /* the service needs a key and none was set */ #define SPMETA_ERR_NO_IO -9 /* no IO backend installed */ #define SPMETA_ERR_INVALID_ARG -10 /* NULL/empty/out-of-range argument */ #define SPMETA_ERR_OOM -11 /* allocation failure */ /* ---- transport (SPEC section 2) ---- */ SPMETA_API void spmeta_set_io(const scorpiox_io *io); /* NULL => libcurl default */ SPMETA_API int spmeta_use_curl(void); /* OK, or ERR_NO_IO in a no-curl build */ SPMETA_API int spmeta_use_fake(void); /* canned-dir fake, offline */ /* ---- configuration (keys REQUIRED, no defaults — SPEC section 1) ---- */ SPMETA_API int spmeta_tmdb_set_key(const char *api_key); /* v3 api_key= */ SPMETA_API int spmeta_tmdb_set_bearer(const char *v4_token); /* v4 Authorization: Bearer */ SPMETA_API int spmeta_omdb_set_key(const char *api_key); SPMETA_API int spmeta_set_language(const char *lang); /* NULL => "en-US" */ SPMETA_API int spmeta_set_timeout_ms(int ms); /* 0 => backend default */ /* ---- TMDb (SPEC section 4) ---- */ SPMETA_API int spmeta_tmdb_find_by_imdb(const char *imdb_id); SPMETA_API int spmeta_tmdb_search_multi(const char *query, int page); SPMETA_API int spmeta_tmdb_discover_movie(int page, int year); /* year 0 = omit */ SPMETA_API int spmeta_tmdb_discover_tv(int page, int include_adult, int year); SPMETA_API int spmeta_tmdb_tv_airing_today(int page); SPMETA_API int spmeta_tmdb_tv_on_the_air(int page); SPMETA_API int spmeta_tmdb_tv_detail(int tmdb_id); SPMETA_API int spmeta_tmdb_external_ids(int tmdb_id, int is_tv); /* is_tv: 0=movie 1=tv */ SPMETA_API const char *spmeta_tmdb_image_url(const char *path, const char *size); /* ---- OMDb (SPEC section 5) ---- */ SPMETA_API int spmeta_omdb_by_imdb(const char *imdb_id); SPMETA_API int spmeta_omdb_by_title(const char *title); SPMETA_API int spmeta_omdb_season(const char *imdb_id, int season); SPMETA_API const char *spmeta_omdb_field(const char *key); /* raw string, "N/A" preserved */ SPMETA_API int spmeta_omdb_runtime_minutes(int *out); /* "142 min" -> 142, -1 absent */ SPMETA_API int spmeta_omdb_votes(unsigned long long *out); /* "1,234,567" -> 1234567 */ /* ---- iTunes (SPEC section 6) ---- */ SPMETA_API int spmeta_itunes_search(const char *term, const char *media, int limit, const char *country); SPMETA_API int spmeta_itunes_lookup(long long id); /* ---- unified results (SPEC section 7) — index i into the last call's results ---- */ SPMETA_API int spmeta_result_count(void); SPMETA_API const char *spmeta_result_source(int i); /* TMDB | OMDB | ITUNES */ SPMETA_API const char *spmeta_result_id(int i); SPMETA_API const char *spmeta_result_imdb_id(int i); SPMETA_API const char *spmeta_result_title(int i); SPMETA_API const char *spmeta_result_original_title(int i); SPMETA_API const char *spmeta_result_overview(int i); SPMETA_API int spmeta_result_year(int i); /* -1 if absent */ SPMETA_API const char *spmeta_result_media_type(int i); /* movie|tv|person|podcast */ SPMETA_API const char *spmeta_result_poster_path(int i); SPMETA_API const char *spmeta_result_backdrop_path(int i); SPMETA_API int spmeta_result_rating_permille(int i); /* -1 absent; 0..1000 */ SPMETA_API int spmeta_result_popularity_permille(int i); SPMETA_API const char *spmeta_result_feed_url(int i); /* iTunes podcast -> podcastfeed */ /* ---- paging (SPEC D6) — what the last TMDb/iTunes call saw ---- */ SPMETA_API int spmeta_total_pages(void); SPMETA_API int spmeta_total_results(void); SPMETA_API int spmeta_page(void); /* ---- TMDb tv_detail extras (SPEC D9) — indexed over the last tv_detail call ---- */ SPMETA_API int spmeta_tv_season_count(void); SPMETA_API int spmeta_tv_season_number(int i); SPMETA_API const char *spmeta_tv_season_poster(int i); SPMETA_API int spmeta_tv_last_episode_season(void); /* -1 absent */ SPMETA_API int spmeta_tv_last_episode_number(void); /* -1 absent */ /* ---- diagnostics ---- */ SPMETA_API long spmeta_last_http_code(void); SPMETA_API const char *spmeta_last_url(void); /* keys REDACTED (see below) */ SPMETA_API const char *spmeta_last_error(void); SPMETA_API const char *spmeta_result_json(void); /* raw JSON of the last call (vendored yyjson) */ SPMETA_API int spmeta_warning_count(void); SPMETA_API const char *spmeta_warning(int i); /* ---- the in-memory fake transport (tests + the .console harness --test; offline only) ---- */ SPMETA_API void sp_fake_reset(void); SPMETA_API int sp_fake_set(const char *method, const char *url, long http_code, const char *body); SPMETA_API int sp_fake_fail(const char *method, const char *url, const char *transport_error); SPMETA_API int sp_fake_calls(const char *method, const char *url); /* url NULL => all */ /* ---- lifecycle ---- */ SPMETA_API void spmeta_shutdown(void); /* free results + state */ #ifdef __cplusplus } #endif #endif /* SPMETA_H */