How jellyfin/jellyfin-plugin-tvheadend works
1. This repository is a Jellyfin server plugin that acts as a bridge to a TVHeadend backend. The architectural boundary is: Jellyfin on one side, TVHeadend on the other, with this plugin translating between Jellyfin’s plugin/service model and TVHeadend’s HTSP protocol.
2. The plugin entry point is centered around Plugin.cs, ServiceRegistrator.cs, and LiveTvService.cs. These files are the main integration surface with Jellyfin: they register services, expose plugin metadata/configuration, and provide the live-TV functionality Jellyfin consumes.
3. The core backend connection layer is split into HTSConnectionHandler.cs and the HTSP/ folder. This is the transport/protocol subsystem responsible for opening and maintaining the connection to TVHeadend, sending requests, and receiving responses asynchronously.
4. HTSP/HTSConnectionAsync.cs, HTSP/HTSConnectionListener.cs, HTSP/HTSMessage.cs, and HTSP/HTSResponseHandler.cs form the protocol stack. The design suggests a message-based async client: one part handles socket/listener behavior, one part models messages, and one part dispatches responses back to typed handlers.
5. The HTSP_Responses/ folder contains response-specific handlers such as GetEventsResponseHandler.cs and LoopBackResponseHandler.cs. This indicates a command/response pattern where protocol replies are parsed and routed to specialized processors rather than handled in a single monolithic connection class.
6. The DataHelper/ folder is the domain-mapping layer. ChannelDataHelper.cs, DvrDataHelper.cs, AutorecDataHelper.cs, and TunerDataHelper.cs appear to transform TVHeadend data into the shapes Jellyfin expects for channels, DVR/recordings, autorecord rules, and tuner status.
7. RecordingsChannel.cs and AccessTicketHandler.cs suggest additional domain concerns beyond basic channel listing. RecordingsChannel likely exposes recorded content as a dedicated logical channel/source, while AccessTicketHandler likely manages TVHeadend ticket or token-based access for stream or recording URLs.
8. Configuration/PluginConfiguration.cs is the persistent plugin settings model. This is the boundary for user-configurable TVHeadend connection details and plugin behavior, separating runtime protocol logic from configuration stored by Jellyfin.
9. Web/tvheadend.html and Web/tvheadend.js provide the plugin’s configuration UI inside Jellyfin’s admin surface. This is the only front-end artifact in the repo, and it is narrowly scoped to settings/editing rather than a standalone web application.
10. The Helper/ and TimeoutHelper/ folders are infrastructure utilities that support the main flow. They include low-level buffer and queue primitives, SHA1/date helpers, and timeout wrappers, which indicate the plugin needs careful protocol framing, hashing, and bounded waits around backend calls.
11. Overall data flow is: Jellyfin invokes plugin services, services consult configuration, the plugin opens/maintains an HTSP session to TVHeadend, response handlers parse backend replies, data helpers adapt those replies into Jellyfin-facing models, and web assets allow administrators to configure the bridge.
12. Operationally, this is a .NET 8 plugin project (TVHeadEnd.csproj) intended to be published as a DLL and dropped into Jellyfin’s plugins folder. The GitHub Actions files are build/test/publish automation around that packaging flow, not part of the runtime architecture.
Main entry points: HTSConnectionHandler.cs Connection handler · LiveTvService.cs Live TV · Plugin.cs Plugin · HTSResponseHandler.cs Response router
Components 22
Jellyfin integration
Plugin entry points and Jellyfin-facing live TV services.
- Plugin · Jellyfin plugin metadata, lifecycle, and top-level integration.
TVHeadEnd/Plugin.cs - Services · Registers plugin services into Jellyfin's container.
TVHeadEnd/ServiceRegistrator.cs - Live TV · Main Jellyfin live-TV surface exposed by the plugin.
TVHeadEnd/LiveTvService.cs - Recordings · Logical recordings source/channel exposed to Jellyfin.
TVHeadEnd/RecordingsChannel.cs - Access tickets · Manages TVHeadend access tickets for stream and recording URLs.
TVHeadEnd/AccessTicketHandler.cs - Config · Persistent plugin configuration stored by Jellyfin.
TVHeadEnd/Configuration/PluginConfiguration.cs
HTSP backend
Transport and protocol stack for talking to TVHeadend.
- Connection handler · Coordinates backend connectivity and higher-level connection behavior.
TVHeadEnd/HTSConnectionHandler.cs - Async client · Asynchronous HTSP connection and request execution.
TVHeadEnd/HTSP/HTSConnectionAsync.cs - Listener · Receives backend data and drives protocol event handling.
TVHeadEnd/HTSP/HTSConnectionListener.cs - HTSP message · Represents HTSP requests, replies, and payload framing.
TVHeadEnd/HTSP/HTSMessage.cs - Response router · Maps protocol responses to typed handlers.
TVHeadEnd/HTSP/HTSResponseHandler.cs - Events handler · Processes event-related HTSP responses.
TVHeadEnd/HTSP_Responses/GetEventsResponseHandler.cs - Loopback handler · Handles loopback or ping-style protocol responses.
TVHeadEnd/HTSP_Responses/LoopBackResponseHandler.cs
Domain mapping
Transforms TVHeadend payloads into Jellyfin-facing shapes.
- Channels · Maps TVHeadend channel data into Jellyfin channel models.
TVHeadEnd/DataHelper/ChannelDataHelper.cs - DVR · Transforms recordings and DVR data for Jellyfin consumption.
TVHeadEnd/DataHelper/DvrDataHelper.cs - Autorec · Maps automatic recording rule data.
TVHeadEnd/DataHelper/AutorecDataHelper.cs - Tuners · Converts tuner and status data into plugin-facing form.
TVHeadEnd/DataHelper/TunerDataHelper.cs
Support utilities
Low-level helpers used by protocol and domain code.
- Buffers · Byte buffer, queue, and framing primitives.
TVHeadEnd/Helper/ByteBuffer.cs - Helpers · Date, hashing, and size utilities used across the plugin.
TVHeadEnd/Helper/DateTimeHelper.cs - Timeouts · Wraps tasks with bounded waiting and timeout behavior.
TVHeadEnd/TimeoutHelper/TaskWithTimeoutRunner.cs
Admin UI
Plugin configuration UI inside Jellyfin.
- Admin page · Jellyfin admin configuration page for the plugin.
TVHeadEnd/Web/tvheadend.html - Admin script · Client-side logic for the plugin configuration page.
TVHeadEnd/Web/tvheadend.js
Connections 26
- Plugin → Services: registers · Plugin startup wires services into Jellyfin.
- Plugin → Config: uses · Plugin exposes and consumes persisted settings.
- Services → Live TV: wires · Service registration provides the live-TV service.
- Live TV → Connection handler: connects · Live-TV operations depend on the backend session manager.
- Live TV → Recordings: serves · Live-TV surface exposes recordings as a source.
- Live TV → Access tickets: authorizes · Stream and recording access may require tickets.
- Connection handler → Async client: drives · Connection handler coordinates the async HTSP client.
- Connection handler → Listener: listens · Connection handler relies on listener behavior.
- Async client → HTSP message: formats · Client sends and receives HTSP messages.
- Listener → Response router: dispatches · Listener forwards responses into the response router.
- Response router → Events handler: routes · Typed response handler processes event replies.
- Response router → Loopback handler: routes · Typed response handler processes loopback replies.
- Events handler → Channels: feeds · Event data is converted into channel shapes where needed.
- Events handler → DVR: feeds · Event and recording data inform DVR mappings.
- DVR → Autorec: relates · Recording workflows connect to autorecord rules.
- Connection handler → Buffers: uses · Protocol handling depends on byte-level primitives.
- Connection handler → Helpers: uses · Connection logic reuses common helpers.
- Connection handler → Timeouts: bounds · Backend calls are guarded by timeout wrappers.
- Plugin → Admin page: hosts · Plugin exposes its admin configuration page.
- Admin page → Admin script: drives · Admin page is backed by client-side scripting.
- Admin script → Config: edits · UI reads and writes plugin configuration.
- Config → Connection handler: configures · Connection settings shape backend session behavior.
- Channels → Live TV: supports · Channel mappings feed Jellyfin live-TV features.
- DVR → Recordings: supports · DVR mappings feed recordings exposure.
- Autorec → Live TV: supports · Autorecord rules contribute to live-TV workflows.
- Tuners → Live TV: supports · Tuner status informs live-TV availability.