How jellyfin/jellyfin-mpv-shim works
Purpose and entry points
Jellyfin MPV Shim is a cross-platform Python desktop/cast-target client for Jellyfin. It plays media through MPV, can expose itself for remote control/casting, and optionally provides a native library browser and offline downloads. Primary launch surfaces are run.py, command-line handling in jellyfin_mpv_shim/args.py, and application orchestration in jellyfin_mpv_shim/mpv_shim.py.
Startup, process lifecycle, and configuration
Startup parses CLI/configuration, establishes one instance per config directory, initializes UI/player services, and supports restart/stop behavior. Configuration and persisted credentials/preferences form a boundary between local state and Jellyfin sessions. Key paths: jellyfin_mpv_shim/conf.py, jellyfin_mpv_shim/conffile.py, jellyfin_mpv_shim/single_instance.py, jellyfin_mpv_shim/restart.py.
Jellyfin connectivity and session control
The client communicates with user-configured Jellyfin servers for authentication, library metadata, playback control, progress reporting, Live TV, and SyncPlay. Multi-server/user behavior is concentrated in client/session abstractions and browser gateway adapters. Key paths: jellyfin_mpv_shim/clients.py, jellyfin_mpv_shim/session_reporter.py, jellyfin_mpv_shim/mpvtk_browser/gateway/servers.py, jellyfin_mpv_shim/mpvtk_browser/gateway/playback.py.
Playback engine and remote-control boundary
Playback control translates Jellyfin play requests and local input into MPV operations, then reports player state back to Jellyfin. MPV events, OSC integration, subtitles/audio selection, trickplay, and external-MPV support belong on this boundary. Key paths: jellyfin_mpv_shim/player.py, jellyfin_mpv_shim/mpv_events.py, jellyfin_mpv_shim/osc_bridge.py, jellyfin_mpv_shim/media.py.
Native browser and rendering stack
The optional desktop browser is a custom MPV-rendered UI rather than a web application. mpvtk supplies rendering/layout/widgets; mpvtk_browser owns navigation, pages, UI state, library presentation, settings, and user interactions. Browser code reaches backend behavior through the gateway layer, avoiding direct page-to-player/server coupling. Key paths: jellyfin_mpv_shim/mpvtk/app.py, jellyfin_mpv_shim/mpvtk_browser/app.py, jellyfin_mpv_shim/mpvtk_browser/navigator.py, jellyfin_mpv_shim/mpvtk_browser/pages/.
Specialized media, synchronization, and integrations
Offline sync persists download state locally and reconciles it with Jellyfin; SyncPlay coordinates group playback. Separate flows support books/comics/EPUB handling, Live TV, shaders/SVP, gamepads, tray behavior, and Discord presence. Key paths: jellyfin_mpv_shim/sync/manager.py, jellyfin_mpv_shim/sync/db.py, jellyfin_mpv_shim/syncplay.py, jellyfin_mpv_shim/live_tv.py, jellyfin_mpv_shim/books.py.
Runtime and distribution boundaries
Runtime dependencies include Python, libmpv/MPV, and embedded Lua scripts for MPV-side rendering and playback features. Jellyfin is the principal external network service; optional desktop integration includes system tray, Discord, SVP, and external MPV. Windows builds package the application with PyInstaller/Inno Setup; Linux packaging includes Flatpak. Key paths: pyproject.toml, jellyfin_mpv_shim/mpvtk/renderer.lua, jellyfin_mpv_shim/thumbfast.lua, flatpak/com.github.iwalton3.jellyfin-mpv-shim.json, .github/workflows/main.yml.
Main entry points: mpv_shim.py Application Orchestrator · player.py Playback Controller · clients.py Jellyfin Clients & Sessions · app.py Browser App & Navigation
Components 19
Client Core
- Launch & CLI · Starts the desktop or cast-target client.
run.py - Application Orchestrator · Coordinates startup, UI, player, and shutdown.
jellyfin_mpv_shim/mpv_shim.py - Config & Local State · Preferences and credentials scoped by configuration directory.
jellyfin_mpv_shim/conf.py - Single Instance · Enforces one process per config directory.
jellyfin_mpv_shim/single_instance.py - Jellyfin Clients & Sessions · Manages server, user, authentication, and session access.
jellyfin_mpv_shim/clients.py - Session Reporting · Reports playback progress and state to Jellyfin.
jellyfin_mpv_shim/session_reporter.py
Native Browser
- Browser App & Navigation · Owns pages, navigation, UI state, and user interaction.
jellyfin_mpv_shim/mpvtk_browser/app.py - MPV UI Toolkit · Provides MPV-rendered layout and widgets.
jellyfin_mpv_shim/mpvtk/app.py - Browser Gateway · Decouples pages from server and playback behavior.
jellyfin_mpv_shim/mpvtk_browser/gateway/servers.py
Playback & Media
- Playback Controller · Translates play requests and input into MPV commands.
jellyfin_mpv_shim/player.py - MPV Event Bridge · Handles MPV events, OSC, and player state changes.
jellyfin_mpv_shim/mpv_events.py - Media Features · Handles media selection, subtitles, trickplay, and specialized formats.
jellyfin_mpv_shim/media.py
Offline & Sync
- Offline Sync Manager · Reconciles local downloads with Jellyfin.
jellyfin_mpv_shim/sync/manager.py - Offline Download DB · Persists offline download state.
jellyfin_mpv_shim/sync/db.py - SyncPlay · Coordinates synchronized group playback.
jellyfin_mpv_shim/syncplay.py
Runtime & Distribution
- MPV / libmpv · Media engine and rendering host.
- Embedded Lua Scripts · MPV-side rendering and playback extensions.
jellyfin_mpv_shim/mpvtk/renderer.lua - Packaging Pipelines · Builds desktop packages for supported platforms.
.github/workflows/main.yml
Other components
- Jellyfin Server · Provides authentication, metadata, playback control, and media APIs.
Connections 22
- Launch & CLI → Application Orchestrator: starts
- Application Orchestrator → Config & Local State: loads state
- Application Orchestrator → Single Instance: acquires lock
- Application Orchestrator → Jellyfin Clients & Sessions: initializes
- Application Orchestrator → Playback Controller: initializes
- Application Orchestrator → Browser App & Navigation: optionally launches
- Config & Local State → Jellyfin Clients & Sessions: supplies credentials
- Jellyfin Clients & Sessions → Jellyfin Server: server API
- Browser App & Navigation → MPV UI Toolkit: renders through
- Browser App & Navigation → Browser Gateway: uses
- Browser Gateway → Jellyfin Clients & Sessions: server operations
- Browser Gateway → Playback Controller: playback requests
- Playback Controller → MPV / libmpv: controls
- MPV Event Bridge → Playback Controller: state events
- Playback Controller → Media Features: applies media options
- Playback Controller → Session Reporting: playback state
- Session Reporting → Jellyfin Server: reports progress
- Offline Sync Manager → Offline Download DB: persists downloads
- Offline Sync Manager → Jellyfin Clients & Sessions: reconciles with
- SyncPlay → Jellyfin Clients & Sessions: coordinates through
- Embedded Lua Scripts → MPV / libmpv: runs in
- Packaging Pipelines → Launch & CLI: packages application