/* spfiles — pure C ScorpioPlayer "what can I actually play" client. * * SCORPIO PLAYER 2027 fleet, row 19c. Sibling of scorpiox-scorpioplayer-spimdb-movie-client * (row 19) and scorpiox-scorpioplayer-spimdb-catalogue-client (row 19b): same error * taxonomy, same conventions. * * Read surfaces (gcp.scorpioplayer.com): * GET /api/finder/getfiles?id=[&s=&e=] — the files behind an id * GET /api/KeyValue/StartsWith?k= — playlists, progress, subs, session index * POST /api/AAA/GetPlaybackSessions — comma-joined keys, text/plain * * ☢️ Write exports (save_progress / update_playback_session / download_magnet) * are compiled but REFUSE with SPFILES_ERR_NOT_ARMED until an explicit * spfiles_arm_writes(1). --test, the unit suite, the fuzzer and the console * harness never arm. No write reaches production from this library by default. * * Marker URIs (cdn.scorpioplayer.com.gcp9.scorpioplayer.com) are placeholders * by design — passed through verbatim, never fetched, never "fixed". */ #ifndef SPFILES_H #define SPFILES_H #include #include "scorpiox-io.h" /* frozen v1 face (vendor/scorpiox-http-transport/include) */ #if defined(_WIN32) # if defined(SPFILES_BUILD) # define SPFILES_API __declspec(dllexport) # else # define SPFILES_API # endif #else # define SPFILES_API __attribute__((visibility("default"))) #endif #ifdef __cplusplus extern "C" { #endif /* ---- error taxonomy: identical codes to the spimdb movie/catalogue clients ---- */ enum { SPFILES_OK = 0, SPFILES_ERR_TRANSPORT = 1, SPFILES_ERR_HTTP = 2, SPFILES_ERR_PARSE = 3, SPFILES_ERR_EMPTY = 4, SPFILES_ERR_NOT_FOUND = 5, SPFILES_ERR_INVALID_ARG= 6, SPFILES_ERR_NO_IO = 7, SPFILES_ERR_OOM = 8, SPFILES_ERR_NOT_ARMED = 9 /* ☢️ write export refused (default) */ }; /* ---- core ---- */ SPFILES_API const char *spfiles_version(void); /* io must carry a fleet transport: scorpiox_http_of(io) != NULL (SPEC D1). 0/1. */ SPFILES_API int spfiles_set_io(const scorpiox_io *io); /* Install the built-in real backend: libcurl, falling back to WinHTTP on Windows. */ SPFILES_API int spfiles_use_curl(void); /* Install the built-in in-process fake (corpus replay + error injection, SPEC 0.2). */ SPFILES_API int spfiles_use_fake(void); SPFILES_API const char *spfiles_last_error(void); SPFILES_API long spfiles_last_http_code(void); /* Host override (tests). NULL resets to https://gcp.scorpioplayer.com. */ SPFILES_API void spfiles_set_host(const char *host); /* Free all retained docs, cache and state. Call at process teardown. */ SPFILES_API void spfiles_shutdown(void); /* ---- cache config (SPEC 3) ---- */ /* seconds; 0 = keep current/default (files 300, kv 900, sessions 60) */ SPFILES_API void spfiles_cache_set_ttl(int files_s, int kv_s, int sessions_s); SPFILES_API void spfiles_cache_clear(void); SPFILES_API int spfiles_cache_invalidate(const char *what, const char *key); SPFILES_API int spfiles_cache_has(const char *what, const char *key, int *out_has); /* ---- files (the product contract, SPEC 1.1) ---- */ /* season/episode: -1 = absent (movie). getfiles?id=X&s=-1-form → plain id query. */ SPFILES_API int spfiles_get_by_imdb(const char *imdb_id, int season, int episode); /* the POST form (C# GetFilesAsync(string[])); live server 405s it — SPEC D3 */ SPFILES_API int spfiles_get_by_keys(const char *const *keys, size_t n); SPFILES_API int spfiles_count(void); SPFILES_API const char *spfiles_key(int i); SPFILES_API const char *spfiles_filename(int i); SPFILES_API const char *spfiles_imdb(int i); SPFILES_API const char *spfiles_parent_key(int i); SPFILES_API const char *spfiles_path(int i); SPFILES_API long long spfiles_size(int i); SPFILES_API int spfiles_season(int i); /* -1 absent */ SPFILES_API int spfiles_episode(int i); /* -1 absent */ SPFILES_API long long spfiles_duration_seconds(int i); SPFILES_API int spfiles_is_hdr(int i); /* -1 absent, 0/1 */ SPFILES_API int spfiles_is_hevc(int i); /* -1 absent, 0/1 */ SPFILES_API int spfiles_is_dolby(int i); /* -1 absent, 0/1 */ SPFILES_API int spfiles_subtitle_count(int i); SPFILES_API const char *spfiles_subtitle_languages(int i); SPFILES_API const char *spfiles_subtitle_language_titles(int i); SPFILES_API int spfiles_audio_channels(int i); SPFILES_API int spfiles_video_width(int i); SPFILES_API int spfiles_video_height(int i); SPFILES_API const char *spfiles_extension(int i); SPFILES_API const char *spfiles_created(int i); SPFILES_API const char *spfiles_record_updated(int i); SPFILES_API int spfiles_entry_count(int i); SPFILES_API const char *spfiles_entry_uri(int i, int e); SPFILES_API const char *spfiles_entry_url(int i, int e); SPFILES_API int spfiles_entry_is_active(int i, int e); SPFILES_API int spfiles_entry_content_source(int i, int e); SPFILES_API const char *spfiles_file_json(int i); /* the raw TheFile object */ /* THE product question: 1 = playable (entries >= 1), 0 = no, <0 = error code. */ SPFILES_API int spfiles_is_playable(const char *imdb_id); SPFILES_API int spfiles_is_playable_se(const char *imdb_id, int season, int episode); /* ---- storages (SPEC 1.5) ---- */ SPFILES_API int spfiles_get_storages(void); SPFILES_API int spfiles_storage_count(void); SPFILES_API const char *spfiles_storage_email(int i); SPFILES_API const char *spfiles_storage_name(int i); SPFILES_API const char *spfiles_storage_id(int i); SPFILES_API const char *spfiles_storage_state(int i); SPFILES_API const char *spfiles_storage_type(int i); SPFILES_API int spfiles_storage_files_count(int i); SPFILES_API long long spfiles_storage_total(int i); SPFILES_API long long spfiles_storage_used(int i); SPFILES_API long long spfiles_storage_remaining(int i); /* ---- playlists (SPEC 1.2): type = "Production" | "Movies" | "Series" ---- */ SPFILES_API int spfiles_get_playlists(const char *userId, int profileId, const char *type); SPFILES_API int spfiles_playlist_count(void); SPFILES_API const char *spfiles_playlist_key(int i); SPFILES_API const char *spfiles_playlist_value(int i); /* raw row value */ SPFILES_API long long spfiles_playlist_id(int i); /* Production inner JSON; -1 absent */ SPFILES_API const char *spfiles_playlist_name(int i); SPFILES_API const char *spfiles_playlist_logo(int i); SPFILES_API const char *spfiles_playlist_origin(int i); SPFILES_API int spfiles_playlist_imdb_count(int i); SPFILES_API const char *spfiles_playlist_imdb(int i, int k); SPFILES_API const char *spfiles_playlist_imdbids(int i); /* comma-joined (C# IDGroup.Value) */ /* ---- playback progress (SPEC 1.3): value = fraction 0..1 ---- */ SPFILES_API int spfiles_get_progress(const char *userId, int profileId, const char *imdbId); SPFILES_API int spfiles_progress_count(void); SPFILES_API double spfiles_progress_value(int i); SPFILES_API int spfiles_progress_season(int i); SPFILES_API int spfiles_progress_episode(int i); SPFILES_API long long spfiles_progress_size(int i); SPFILES_API const char *spfiles_progress_key(int i); SPFILES_API const char *spfiles_progress_updated(int i); /* ---- external subtitles (SPEC 1.4) ⭐ — what subtitle-fetch consumes ---- */ SPFILES_API int spfiles_get_external_subtitles(const char *imdb_id, int season, int episode); SPFILES_API int spfiles_sub_count(void); SPFILES_API const char *spfiles_sub_key(int i); SPFILES_API const char *spfiles_sub_label(int i); /* key minus prefix */ SPFILES_API const char *spfiles_sub_uri(int i); /* the .srt URL */ SPFILES_API const char *spfiles_sub_filename(int i); /* p5 */ SPFILES_API int spfiles_sub_enabled(int i); /* 0/1 */ SPFILES_API long long spfiles_sub_id(int i); /* stable hash of the key */ SPFILES_API int spfiles_sub_is_child(int i); SPFILES_API long long spfiles_sub_parent_id(int i); SPFILES_API const char *spfiles_sub_updated(int i); /* The C# GetStringStableHashCode (djb2 over UTF-16 code units) — subtitle-fetch * needs it to reproduce track ids. Same algorithm as spmhash/spcat. */ SPFILES_API long long spfiles_stable_hash(const char *utf8); /* ---- playback sessions (SPEC 1.6) ---- */ /* ids: comma-joined session keys (C# parity). POST text/plain. */ SPFILES_API int spfiles_get_playback_sessions(const char *ids); SPFILES_API int spfiles_session_count(void); SPFILES_API const char *spfiles_session_id(int i); SPFILES_API const char *spfiles_session_created(int i); SPFILES_API const char *spfiles_session_value(int i); /* the 0/1 bit-string */ SPFILES_API int spfiles_session_bit(int i, int k); /* -1 out of range */ /* the index read: k=SCORPIOX_PlaybackSession_ */ SPFILES_API int spfiles_get_session_index(const char *userId); SPFILES_API int spfiles_sessionix_count(void); SPFILES_API const char *spfiles_sessionix_key(int i); SPFILES_API const char *spfiles_sessionix_user(int i); SPFILES_API int spfiles_sessionix_profile(int i); SPFILES_API const char *spfiles_sessionix_imdb(int i); SPFILES_API int spfiles_sessionix_season(int i); SPFILES_API int spfiles_sessionix_episode(int i); SPFILES_API long long spfiles_sessionix_size(int i); SPFILES_API const char *spfiles_sessionix_sessionkey(int i); /* ---- ☢️ writes — REFUSE with SPFILES_ERR_NOT_ARMED unless armed ---- */ /* Arming is an explicit, deliberate act. --test / unit / fuzz / console never arm. */ SPFILES_API int spfiles_arm_writes(int arm); /* 0=disarm, 1=arm, else EINVAL */ SPFILES_API int spfiles_writes_armed(void); /* read-back for the harness */ SPFILES_API int spfiles_save_progress(const char *userId, int profileId, const char *imdbId, int season, int episode, long long size, double position_seconds, double duration_seconds); SPFILES_API int spfiles_update_playback_session(const char *key, const char *base64, const char *position, const char *duration); SPFILES_API int spfiles_download_magnet(const char *userId, const char *magnet, const char *storageId, const char *downloaderId, const char *extension, const char *tkey); /* ---- fake backend (tests / .console --test; in-process, zero sockets) ---- */ SPFILES_API int spfiles_fake_corpus(const char *dir); /* 0=replay 1=transport-fail 2=http-500 3=http-404 4=malformed 5=empty 6=json-null */ SPFILES_API int spfiles_fake_mode(int mode); SPFILES_API long long spfiles_fake_calls(void); SPFILES_API long long spfiles_fake_fail_count(void); SPFILES_API const char *spfiles_fake_last_url(void); SPFILES_API void spfiles_fake_reset(void); #ifdef __cplusplus } #endif #endif /* SPFILES_H */