How stremio/stremio-video works
Project type and purpose
• This is a JavaScript/Node.js library (package.json at project root, uses .npmignore) named “stremio-video.”
• Purpose: Provide an abstraction layer over multiple video player implementations (Chromecast, HTML5, IFrame, Shell, Stremio, Titan, Tizen, Vidaa, WebOS, YouTube) and higher-order wrappers (subtitles, streaming server, video params).
File structure
• Top-level: configuration files (.eslintrc, .gitignore, workflows), package.json, README.md, src/
• src/ contains:
– Core entrypoints: src/index.js, src/error.js, src/mediaCapabilities.js, src/platform.js, src/supportsTranscoding.js, src/tracksData.js
– Player implementations (one directory per platform): ChromecastSenderVideo/, HTMLVideo/, IFrameVideo/, ShellVideo/, StremioVideo/, TitanVideo/, TizenVideo/, VidaaVideo/, WebOsVideo/, YouTubeVideo/
– Higher-order wrappers (prefix “with…”): withHTMLSubtitles/, withStreamingServer/, withVideoParams/
• Pattern: A central abstraction (“core”) that dynamically selects or wraps specific video backends and applies cross-cutting concerns (subtitles, streaming, params).
README for additional insights
• The README is minimal: “Abstraction layer on top of different media players.”
a. Main components
1. Core Abstraction Layer
– src/index.js: exports public API
– Utility modules: mediaCapabilities, platform detection, error handling, transcoding support, track data
2. Video Player Modules
– One module per target platform (Chromecast, HTML5, IFrame, etc.)
3. Higher-Order Wrappers
– withHTMLSubtitles: subtitle parsing, conversion, rendering
– withStreamingServer: torrent conversion, server setup, param fetching
– withVideoParams: query and inject video parameters
4. External Platforms & Services
– Browsers (HTML5 video, IFrame), Smart TV environments (Tizen, WebOS, Vidaa), Chromecast, YouTube API, Stremio host
5. (Optional) Underlying libraries
– e.g., WebTorrent for streaming server, HLS.js for HTMLVideo, fetch/XHR
b. Relationships and interactions
– Consumer (app or Stremio addon) → imports stremio-video API
– Core Abstraction → selects appropriate Player Module based on platform / mediaCapabilities
– Player Module ↔ External Platform/Device
– Wrappers wrap core API to add functionality:
• withHTMLSubtitles → sits between Consumer and Core, intercepts subtitle data flow
• withStreamingServer → intercepts media source URLs, starts local server or torrent stream
• withVideoParams → appends auth tokens, metadata to stream URLs
– Utility Modules → used by Core and Wrappers for environment detection and error handling
c. Architectural patterns & design principles
– Strategy pattern: each Player Module implements a common interface but different behavior per platform
– Decorator / Higher-order functions: wrappers extend or modify the base player functionality
– Single Responsibility: modules are small and focused (detection, error, transcoding, parsing)
– Plug-in style: new player modules or wrappers can be added without core changes
d. Key technologies
– JavaScript / Node.js
– Browser APIs (HTML5 Video, IFrame)
– Smart TV SDKs (Tizen, WebOS)
– WebTorrent or custom streaming code (withStreamingServer)
– Subtitle formats (SRT, WebVTT)