/* * sphrm.h — scorpiox-scorpioplayer-media-library-home-rows-model * * SCORPIO PLAYER 2027 home/library POLICY: what goes on the home screen, in what * order, what each tile means, where resume comes from, what plays next. * * Pure policy over JSON the shell already got from shipped engines * (spcat_ server home, spfiles_ files/progress, spfsc_/spmcat_/spplfm_ library * listings, spis_ store). No sockets, no auth, no engine links, no writes. * * Every shell (WinUI3, GTK4, SwiftUI, Compose) renders the SAME rows: * sphrm_result_json() is the render-ready document. Shells hold no logic. * * Conventions (fleet): * - int status: SPHRM_OK (0) or a negative/positive SPHRM_ERR_*; * sphrm_last_error() has the message, sphrm_last_code() the code. * - every returned const char * is library-owned and valid until the next * call that replaces the same state. COPY IT IMMEDIATELY. * - single-threaded, global state. * - all strings UTF-8. * * See SPEC.md for every threshold and its legacy citation. */ #ifndef SPHRM_H #define SPHRM_H #include #ifdef __cplusplus extern "C" { #endif #if defined(SPHRM_STATIC) # define SPHRM_API #elif defined(_WIN32) # if defined(SPHRM_BUILD) # define SPHRM_API __declspec(dllexport) # else # define SPHRM_API __declspec(dllimport) # endif #else # define SPHRM_API __attribute__((visibility("default"))) #endif #define SPHRM_ABI_VERSION 1 #define SPHRM_VERSION "1.0.1" /* ---- error taxonomy (SPEC §12) — values are frozen ---- */ #define SPHRM_OK 0 #define SPHRM_ERR_BAD_INPUT 1 /* JSON invalid / wrong shape — state cleared */ #define SPHRM_ERR_INVALID_ARG 2 #define SPHRM_ERR_OOM 3 #define SPHRM_ERR_TOO_LARGE 4 /* cap exceeded or output buffer too small */ #define SPHRM_ERR_NO_STATE 5 /* no inputs loaded / no item selected */ /* ---- row kinds (SPEC §4.1) — values are frozen ---- */ #define SPHRM_ROW_CONTINUE_WATCHING 0 #define SPHRM_ROW_RECENTLY_ADDED 1 #define SPHRM_ROW_MOVIES 2 #define SPHRM_ROW_TV_SHOWS 3 #define SPHRM_ROW_FOLDERS 4 #define SPHRM_ROW_FAVOURITES 5 #define SPHRM_ROW_GENRES 6 #define SPHRM_ROW_COLLECTIONS 7 #define SPHRM_ROW_UNMATCHED 8 #define SPHRM_ROW_SERVER_SECTION 9 #define SPHRM_ROW_SPOTLIGHT 10 #define SPHRM_ROW_NOW_PLAYING 11 #define SPHRM_ROW_EPISODES 12 #define SPHRM_ROW_SEASONS 13 #define SPHRM_ROW_AUDIO 14 #define SPHRM_ROW_PICTURE 15 /* ---- item kinds ---- */ #define SPHRM_ITEM_MOVIE 0 #define SPHRM_ITEM_TV 1 #define SPHRM_ITEM_EPISODE 2 #define SPHRM_ITEM_FILE 3 #define SPHRM_ITEM_FOLDER 4 #define SPHRM_ITEM_OTHER 5 /* ---- resume actions (SPEC §8) — values are frozen ---- */ #define SPHRM_RESUME_START 0 #define SPHRM_RESUME_RESUME 1 #define SPHRM_RESUME_FINISHED 2 /* ---- library origins ---- */ #define SPHRM_LIB_SCORPIO_PLUS 0 #define SPHRM_LIB_MEDIA_EMPIRE 1 #define SPHRM_LIB_DEBRID 2 #define SPHRM_LIB_LOCAL 3 #define SPHRM_LIB_OTHER 4 #define SPHRM_LIB_UNKNOWN 5 /* ================= lifecycle & configuration ================= */ SPHRM_API const char *sphrm_version(void); SPHRM_API const char *sphrm_last_error(void); /* "" after success */ SPHRM_API int sphrm_last_code(void); SPHRM_API void sphrm_shutdown(void); /* free everything */ SPHRM_API int sphrm_clear(void); /* drop rows/items, keep config */ /* cells per row (default 200, hard max 2000). Returns SPHRM_ERR_INVALID_ARG * if n < 1 or n > 2000. */ SPHRM_API int sphrm_set_row_cap(int n); SPHRM_API int sphrm_get_row_cap(void); /* {"remember_last_position":true,"remember_audio":false} * defaults: remember_last_position=1 (CONSTANTS.RememberLastPosition default true, * Events.cs:1578), remember_audio=0 (DefaultValue.RememberAudioProgress, * Properties.cs:780-787). NULL/"" restores defaults. */ SPHRM_API int sphrm_set_resume_settings(const char *json); /* {"enabled":1,"use_fixed_present_before":1,"present_before_duration_s":90, * "use_percentage_present_before":0,"present_before_percentage":0.85, * "enable_counting_down":1,"countdown_duration_s":30,"automatic_play_next":1} * No invented defaults: without this the autoplay timeline is empty and * sphrm_detail_autoplay_configured() reports 0. */ SPHRM_API int sphrm_set_autoplay_settings(const char *json); /* ================= input blocks (SPEC §2) ================= */ /* one object {"server_home":…,"items":[…],"watch":[…],"library":[…],"store":…}. * Replaces ALL state. Bad JSON → SPHRM_ERR_BAD_INPUT and state is cleared. */ SPHRM_API int sphrm_load_inputs(const char *json); /* incremental loaders (a shell that fetches engines one at a time): * each replaces/extends only its own block, then rebuilds the rows. */ SPHRM_API int sphrm_set_server_home(const char *server_home_json); SPHRM_API int sphrm_add_items(const char *items_json_array); /* append */ SPHRM_API int sphrm_set_watch(const char *watch_json_array); /* replace */ SPHRM_API int sphrm_set_library(const char *library_json_array); /* replace */ SPHRM_API int sphrm_set_store(const char *store_json_object); /* replace */ /* ================= items, indexed (SPEC §2.1) ================= */ SPHRM_API int sphrm_item_count(void); SPHRM_API const char *sphrm_item_json(int i); /* the full record + derived */ /* -1 when no such id; ids are matched verbatim, then case-insensitively. */ SPHRM_API int sphrm_item_index_of(const char *item_id); SPHRM_API const char *sphrm_item_id(int i); SPHRM_API const char *sphrm_item_title(int i); /* NULL when unknown */ SPHRM_API const char *sphrm_item_imdb(int i); /* NULL when none */ SPHRM_API int sphrm_item_kind(int i); /* SPHRM_ITEM_* */ SPHRM_API int sphrm_item_year(int i); /* -1 unknown */ SPHRM_API int sphrm_item_season(int i); /* -1 absent */ SPHRM_API int sphrm_item_episode(int i); /* -1 absent */ SPHRM_API const char *sphrm_item_poster_url(int i); SPHRM_API int sphrm_item_playable(int i); /* 1 = >=1 active source */ SPHRM_API int sphrm_item_source_count(int i); SPHRM_API int sphrm_item_resume_action(int i); /* SPHRM_RESUME_* */ SPHRM_API long long sphrm_item_added_ms(int i); /* -1 unknown */ SPHRM_API int sphrm_item_unmatched(int i); /* 1 = walked, never matched */ SPHRM_API const char *sphrm_item_next_id(int i); /* NULL when no next */ /* ================= selection + detail (SPEC §7–§9) ================= */ /* select by item id / imdb id / source key. SPHRM_OK or SPHRM_ERR_NO_STATE * (not found is NO_STATE, matching "nothing selected"). */ SPHRM_API int sphrm_select_item(const char *item_id); SPHRM_API int sphrm_select_imdb(const char *imdb_id); SPHRM_API int sphrm_select_source(const char *source_key); SPHRM_API int sphrm_selected_index(void); /* -1 = none */ SPHRM_API const char *sphrm_detail_json(void); /* item + sources + resume + next + autoplay */ SPHRM_API int sphrm_detail_source_count(void); SPHRM_API const char *sphrm_detail_source_json(int s); /* ranked, best first */ SPHRM_API const char *sphrm_detail_best_source_url(void); SPHRM_API int sphrm_detail_resume_action(void); SPHRM_API double sphrm_detail_resume_position_s(void); SPHRM_API double sphrm_detail_progress_fraction(void); SPHRM_API int sphrm_detail_resume_clamped(void); /* 1 = position clamped */ SPHRM_API const char *sphrm_detail_next_json(void); /* "{}" when none */ SPHRM_API const char *sphrm_detail_autoplay_json(void); /* timeline array, "[]" when none */ SPHRM_API int sphrm_detail_autoplay_configured(void); /* ================= rows (SPEC §3–§6) ================= */ SPHRM_API int sphrm_row_count(void); SPHRM_API int sphrm_row_kind(int r); /* SPHRM_ROW_* */ SPHRM_API const char *sphrm_row_key(int r); /* "Spotlight", "ContinueWatching", … */ SPHRM_API const char *sphrm_row_title(int r); /* display title (localized by shell) */ SPHRM_API int sphrm_row_cell_count(int r); /* REAL count, even when truncated */ SPHRM_API const char *sphrm_row_cell_json(int r, int c); SPHRM_API const char *sphrm_row_json(int r); SPHRM_API int sphrm_row_truncated(int r); /* 1 = more cells than the cap */ SPHRM_API const char *sphrm_row_cell_title(int r, int c); SPHRM_API const char *sphrm_row_cell_poster_url(int r, int c); SPHRM_API int sphrm_row_cell_resume_action(int r, int c); SPHRM_API int sphrm_row_cell_playable(int r, int c); /* ================= outputs ================= */ SPHRM_API const char *sphrm_result_json(void); /* THE render-ready document */ SPHRM_API const char *sphrm_stats_json(void); /* {"high_speed_ids":[…],"scorpio_plus_ids":[…],"chromecast_ids":[…], * "level30_ids":[…],"feature_flags":{…}} — ITheFileItemService.Assign() inputs * (ISPIMDbService.cs:732-738) */ SPHRM_API const char *sphrm_server_flags_json(void); SPHRM_API const char *sphrm_watchlist_json(void); /* the MyWatchlist IDGroup */ SPHRM_API const char *sphrm_browse_history_json(void); /* the BrowseHistory IDGroup */ /* ================= stable ids (SPEC §10, spplfm_ v2 rules) ================= */ /* decimal GetStableHashCode (djb2 over UTF-16 code units, Math.Abs fold; * INT32_MIN -> 0 exactly as C# throws-and-returns-0). n < needed -> TOO_LARGE. */ SPHRM_API int sphrm_stable_hash(const char *utf8, char *out, size_t n); /* v2: Base64(UTF-8(backend_id + "\u0001" + folder_path + "\u0001" + name)) */ SPHRM_API int sphrm_resume_key(const char *backend_id, const char *folder_path, const char *name, char *out, size_t n); /* byte-exact legacy: Base64(UTF-8(folder_name)) (LoadFolderAsync.cs:241-242) */ SPHRM_API int sphrm_legacy_resume_key(const char *folder_name, char *out, size_t n); #ifdef __cplusplus } #endif #endif /* SPHRM_H */