From a928a5a99572d5ae90fc493fee685f1d06a111d1 Mon Sep 17 00:00:00 2001 From: Mohammed Abad Date: Mon, 25 May 2026 02:10:38 +0100 Subject: [PATCH] Docs: add streaming system docs - Create docs-vault/Streaming.md with full streaming architecture docs - Update docs-vault/Index.md to link to streaming documentation --- docs-vault/Index.md | 1 + docs-vault/Streaming.md | 125 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 docs-vault/Streaming.md diff --git a/docs-vault/Index.md b/docs-vault/Index.md index 9b5b036..8fde307 100644 --- a/docs-vault/Index.md +++ b/docs-vault/Index.md @@ -55,6 +55,7 @@ aliases: - [[Library]] — Entry management, watchlist, favorites - [[Collections]] — TMDB and user collections - [[Watch Tracking]] — EntrySeen, EpisodeSeen, accuracy system +- [[Streaming]] — In-app streaming system with 4 providers (8 servers) - [[Calendar]] — Upcoming episodes view - [[Statistics]] — Dashboard charts and data - [[People]] — Cast, crew, filmography diff --git a/docs-vault/Streaming.md b/docs-vault/Streaming.md new file mode 100644 index 0000000..78ec1f9 --- /dev/null +++ b/docs-vault/Streaming.md @@ -0,0 +1,125 @@ +# Streaming System + +## Overview + +Showy includes an in-app streaming system that embeds video players from external streaming APIs. The system supports 4 providers (8 total servers) and is designed to be easily extensible. + +## Architecture + +``` +StreamingSection (Entry Page UI) + └── StreamingPlayer (iframe + controls) + ├── ServerSelector (dropdown) + ├── EpisodeNavigator (season/episode grid) + └── AutoMarkWatchedPrompt + +useStreamingStore (Zustand) + └── streaming-manager.ts (core logic) + └── providers/ (adapters per API) + ├── vidlink.ts + ├── vidking.ts + └── anyembed.ts +``` + +## Providers + +| Provider | Servers | Events | Progress | ID Support | +|----------|---------|--------|----------|------------| +| [[#VidLink]] | 2 (Default, JW Player) | ✅ | ✅ | TMDB | +| [[#VidKing]] | 1 | ✅ | ✅ | TMDB | +| [[#AnyEmbed]] | 5 (server 1-5) | ❌ | ❌ | TMDB, IMDB | + +### VidLink + +- Base: `https://vidlink.pro` +- Movie: `/movie/{tmdbId}` +- TV: `/tv/{tmdbId}/{season}/{episode}` +- Supports: autoplay, next button, custom player (JW), startAt, progress tracking via postMessage + +### VidKing + +- Base: `https://www.vidking.net` +- Movie: `/embed/movie/{tmdbId}` +- TV: `/embed/tv/{tmdbId}/{season}/{episode}` +- Supports: autoPlay, nextEpisode button, episodeSelector, progress resume, color customization + +### AnyEmbed + +- Base: `https://anyembed.xyz` +- Movie: `/movie/{id}` (TMDB or IMDB with `tt` prefix) +- TV: `/tv/{id}/{season}/{episode}` +- Supports: `?server={1-5}` parameter for server selection + +## Key Files + +| File | Purpose | +|------|---------| +| `src/lib/streaming/types.ts` | All TypeScript interfaces | +| `src/lib/streaming/streaming-manager.ts` | Core logic, persistence, validation | +| `src/lib/streaming/providers/*.ts` | Provider adapters | +| `src/stores/useStreamingStore.ts` | Zustand state management | +| `src/components/streaming/StreamingPlayer.tsx` | Player component | +| `src/components/streaming/StreamingSection.tsx` | Entry page integration | +| `src/components/streaming/ServerSelector.tsx` | Server picker | +| `src/components/streaming/EpisodeNavigator.tsx` | Episode navigation | + +## Data Flow + +1. User clicks "Watch Now" / "Continue Watching" on [[Entry Details Page|EntryDetailsPage]] +2. `StreamingSection` determines the request (movie or TV + season/episode) +3. `useStreamingStore.play()` builds a URL via the active server's provider adapter +4. `StreamingPlayer` renders an iframe with the embed URL +5. Player events (postMessage) update localStorage progress +6. On `ended` event: auto-mark-as-watched if enabled, or prompt user + +## Persistence (localStorage) + +| Key | Purpose | +|-----|---------| +| `showy_preferred_server` | Last selected server ID | +| `showy_watch_progress` | Per-entry playback progress | +| `showy_auto_mark_watched` | Auto-mark config `{ enabled, threshold }` | +| `showy_auto_mark_prompt_shown` | Whether prompt was shown | +| `showy_watch_logs` | Completed watch events (for future DB backup) | + +## Security + +- Embed URLs validated against allowlist of origins +- postMessage origins checked before processing events +- iframe sandbox: `allow-scripts allow-same-origin allow-forms allow-popups allow-presentation` +- iframe allow: `autoplay; fullscreen; picture-in-picture; encrypted-media` + +## Server Switching + +- Users can switch servers at any time via the overlay dropdown +- Preference is persisted to localStorage +- On failure: error UI with "Try Another Server" button (cycles to next server) +- `tryNextServer()` iterates through all servers before showing "all unavailable" + +## Continue Watching Logic + +1. Check `showy_watch_progress` localStorage for TMDB ID +2. If TV: use `lastSeasonWatched` / `lastEpisodeWatched` +3. Fallback: check `episodeSeens` from database (last watched → suggest next) +4. Default: Season 1, Episode 1 + +## Auto-Mark-as-Watched + +- First time a movie/episode ends → prompt user to enable +- If enabled: automatically calls `useCreateEntrySeen` or `useCreateEpisodeSeen` +- Threshold: 90% of duration (configurable) +- Decision stored in localStorage, prompt only shown once + +## Adding a New Provider + +1. Create `src/lib/streaming/providers/newprovider.ts` +2. Implement `StreamingProvider` interface +3. Export from `providers/index.ts` +4. Import in `streaming-manager.ts` and add to `providers` array + +## Related + +- [[Backend]] — Future: watch logs backup endpoint +- [[Frontend]] — Component architecture +- [[Watch Tracking]] — Existing episode/entry seen system +- [[Settings Page]] — Potential streaming settings section