/* * spplus.h — SCORPIO+ Web Front API Client (pure C99, SCORPIO PLAYER 2027 fleet). * * Calls the SCORPIO+ web front (https://plus.scorpiox.net or self-hosted scorpiox-plus-web) * using ?format=json passthrough, with pluggable scorpiox_http transport for: * - Linux x86_64 CLI / desktop (libcurl default) * - Windows x64 WinUI3 desktop (WinHTTP default) * - Windows x64 UWP / Xbox AppContainer (zero banned Win32 imports; shell installs HttpClient) * - Apple iOS / macOS / tvOS XCFramework (shell installs URLSession) * - Android arm64-v8a / x86_64 (shell installs OkHttp / HttpURLConnection) * - Offline deterministic fake backend (unit tests, C# .console --test) * * Write exports (spplus_save_progress, spplus_watchlist_set) are REFUSED by default with * SPPLUS_ERR_NOT_ARMED until the caller explicitly arms writes via spplus_arm_writes(h, 1). * spplus_logout() and spplus_destroy() always disarm writes and wipe credentials. */ #ifndef SPPLUS_H #define SPPLUS_H #include #include #include "scorpiox-http.h" #define SPPLUS_VERSION "1.0.0" #define SPPLUS_ABI_VERSION 1 #if defined(_WIN32) || defined(__CYGWIN__) # ifdef SPPLUS_BUILD # define SPPLUS_API __declspec(dllexport) # else # define SPPLUS_API # endif #else # if defined(__GNUC__) || defined(__clang__) # define SPPLUS_API __attribute__((visibility("default"))) # else # define SPPLUS_API # endif #endif #ifdef __cplusplus extern "C" { #endif typedef struct spplus_handle spplus_handle; typedef enum spplus_err { SPPLUS_OK = 0, SPPLUS_ERR_INVALID_ARG = 1, SPPLUS_ERR_NO_IO = 2, SPPLUS_ERR_TRANSPORT = 3, SPPLUS_ERR_AUTH = 4, /* HTTP 401/403 or 302 redirect to login */ SPPLUS_ERR_NOT_FOUND = 5, /* HTTP 404 or cache miss */ SPPLUS_ERR_UPSTREAM = 6, /* HTTP 5xx (502/503/504) or API ok:false */ SPPLUS_ERR_HTTP = 7, /* other non-2xx HTTP status */ SPPLUS_ERR_PARSE = 8, /* invalid JSON response */ SPPLUS_ERR_OOM = 9, SPPLUS_ERR_NOT_ARMED = 10, /* write export refused until spplus_arm_writes(h, 1) */ SPPLUS_ERR_IO = 11 /* cache disk I/O error */ } spplus_err; typedef enum spplus_auth_mode { SPPLUS_AUTH_JWT = 0, /* Cloud: Cookie: sx_token= */ SPPLUS_AUTH_PASSWORD = 1, /* Self-host: X-Plus-Password: */ SPPLUS_AUTH_NONE = 2 /* Tests / anonymous */ } spplus_auth_mode; /* ---- Core lifecycle & result inspection ---- */ SPPLUS_API const char *spplus_version(void); SPPLUS_API int spplus_abi_version(void); SPPLUS_API spplus_handle *spplus_create(void); SPPLUS_API void spplus_destroy(spplus_handle *h); SPPLUS_API const char *spplus_last_error(const spplus_handle *h); SPPLUS_API int spplus_last_http_status(const spplus_handle *h); SPPLUS_API const char *spplus_result_json(const spplus_handle *h); SPPLUS_API void spplus_free(void *ptr); /* ---- Configuration & transport ---- */ /* Default base URL: "https://plus.scorpiox.net" (supports custom self-hosted http://host:8154). */ SPPLUS_API int spplus_set_base_url(spplus_handle *h, const char *url); /* Default auth URL: "https://auth.scorpiox.net" (used by spplus_login). */ SPPLUS_API int spplus_set_auth_url(spplus_handle *h, const char *url); SPPLUS_API int spplus_set_auth_mode(spplus_handle *h, int mode); SPPLUS_API int spplus_set_token(spplus_handle *h, const char *jwt); SPPLUS_API int spplus_set_password(spplus_handle *h, const char *pw); SPPLUS_API int spplus_set_profile(spplus_handle *h, int profile_id); SPPLUS_API int spplus_set_timeout_ms(spplus_handle *h, int timeout_ms); /* Install a pluggable scorpiox_http vtable (URLSession, OkHttp, UWP HttpClient, custom). * Pass NULL to restore the platform default backend (libcurl on Linux, WinHTTP on Win32). */ SPPLUS_API int spplus_set_http_backend(spplus_handle *h, const scorpiox_http *backend); /* Configure automatic /t/p/original/ -> /t/p/w/ rewriting in returned JSON. * Defaults: card_w=342, detail_w=500, backdrop_w=780. Pass 0 for any width to leave raw. */ SPPLUS_API int spplus_set_image_widths(spplus_handle *h, int card_w, int detail_w, int backdrop_w); /* Standalone pure utility: rewrite a single TMDB/img2 /t/p/original/ URL to /t/p/w/. * width <= 0 copies url verbatim. Returns SPPLUS_OK or SPPLUS_ERR_INVALID_ARG. */ SPPLUS_API int spplus_resize_image_url(const char *url, int width, char *out, size_t out_cap); /* ---- Auth (SCORPIO+ cloud login + session) ---- */ /* POST /api/login -> stores sx_token JWT + userId + email in handle. * Never logs or persists password. Result JSON: {"ok":true,"userId":"...","email":"...","token":"..."}. */ SPPLUS_API int spplus_login(spplus_handle *h, const char *email, const char *password); /* Clears token/password/session state and disarms writes. */ SPPLUS_API int spplus_logout(spplus_handle *h); /* Returns 1 if handle holds credentials for the active auth mode, 0 otherwise. */ SPPLUS_API int spplus_is_authenticated(const spplus_handle *h); /* ---- Homepage & instant-start cache ---- */ /* Optional cache directory for stale-while-revalidate homepage caching. NULL disables all disk I/O. */ SPPLUS_API int spplus_set_cache_dir(spplus_handle *h, const char *dir); /* Load cached /home JSON from cache_dir immediately (0 ms cold launch). * profile < 0 uses handle's configured profile_id. Returns SPPLUS_ERR_NOT_FOUND on miss. */ SPPLUS_API int spplus_home_cached(spplus_handle *h, int profile); /* GET /?format=json&cap=&profile=. Default cap=15 if <=0, clamped 1..200. * Rewrites image URLs, saves to cache_dir if configured, sets "changed":true|false in JSON. */ SPPLUS_API int spplus_home(spplus_handle *h, int profile, int cap); /* ---- Catalogue & detail ---- */ /* GET /browse?kind=&list=&page=&format=json (list_name URL-encoded). * kind/list_name may be NULL/empty for the kinds index. page <= 0 defaults to 1. */ SPPLUS_API int spplus_browse(spplus_handle *h, const char *kind, const char *list_name, int page); /* GET /title?id=&format=json (validates tt[0-9]+). */ SPPLUS_API int spplus_title(spplus_handle *h, const char *imdb_id); /* GET /tv?id=[&season=]&format=json (season < 0 omits season param). */ SPPLUS_API int spplus_tv(spplus_handle *h, const char *imdb_id, int season); /* GET /person?id=&format=json (URL-encodes nm..., numeric, or plain name). */ SPPLUS_API int spplus_person(spplus_handle *h, const char *id_or_name); /* GET /search?q=&page=&format=json (URL-encodes query, page <= 0 -> 1). */ SPPLUS_API int spplus_search(spplus_handle *h, const char *query, int page); /* ---- User, playback & watchlist ---- */ /* GET /account?format=json */ SPPLUS_API int spplus_account(spplus_handle *h); /* GET /continue?profile=&format=json. * If /continue returns 404 on an older web front, falls back to /?format=json&cap=1&profile=... */ SPPLUS_API int spplus_continue(spplus_handle *h, int profile); /* GET /prewarm?id=[&s=&e=] (season < 0 or episode < 0 omits s/e). */ SPPLUS_API int spplus_prewarm(spplus_handle *h, const char *imdb_id, int season, int episode); /* GET /watch?id=[&s=&e=][&native=1][&file_index=]&format=json. * Accepts and normalizes both direct_url and stream_url, plus candidates[] / file / resume / duration. */ SPPLUS_API int spplus_watch(spplus_handle *h, const char *imdb_id, int season, int episode, int native_mode, int file_index); /* GET /watchlist?format=json */ SPPLUS_API int spplus_watchlist_get(spplus_handle *h); /* ---- Write-armed exports (DEFAULT REFUSED: SPPLUS_ERR_NOT_ARMED) ---- */ SPPLUS_API int spplus_arm_writes(spplus_handle *h, int armed); /* POST /progress {"id","s","e","position","duration","size"} (accepts 204 or 200). */ SPPLUS_API int spplus_save_progress(spplus_handle *h, const char *imdb_id, int season, int episode, double position_sec, double duration_sec, int64_t file_size); /* POST /watchlist {"op":"add"|"remove","id":"tt..."} */ SPPLUS_API int spplus_watchlist_set(spplus_handle *h, const char *imdb_id, int add_bool); /* ---- Built-in per-handle offline fake HTTP backend (for unit tests & .console --test) ---- */ SPPLUS_API int spplus_use_fake_http(spplus_handle *h); SPPLUS_API int spplus_fake_reset(spplus_handle *h); SPPLUS_API int spplus_fake_add_route(spplus_handle *h, const char *method, const char *url, int http_status, const char *headers, const char *body); SPPLUS_API int spplus_fake_request_count(const spplus_handle *h); SPPLUS_API const char *spplus_fake_last_request_json(const spplus_handle *h); #ifdef __cplusplus } #endif #endif /* SPPLUS_H */