Files
Showy/docs-vault/Streaming.md
T
X4Lo 229ecef902 Update docs vault and README for recent features
- New notes: History, Artwork
- Rewrite TMDB Integration: single detail request, entry mapper, rate
  limiter, refresh sync, stale-entry refresh, recommendations
- Update pages, routing, API reference, models, database migrations,
  services, components, hooks, API clients, settings, media system,
  library, Electron (Tauri in progress) and known issues
- Rewrite README for the current React/Express stack and setup
2026-11-05 19:55:04 +00:00

126 lines
4.5 KiB
Markdown

# 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 [[Pages#EntryDetailsPage|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