Introduction
The@hls-downloader/core package is the heart of HLS Downloader, containing all shared business logic and state management for downloading and processing HLS video streams. Built with TypeScript, Redux Toolkit, and Redux-Observable, it provides a clean separation between business logic and platform-specific implementations.
Package information
@hls-downloader/core
0.0.0
MIT
Architecture
The core package is organized into several key modules:Use cases
Business logic functions that perform specific operations like downloading fragments, decrypting content, and managing file storage. Each use case is a factory function that accepts service dependencies and returns an executable function. See Use cases for detailed documentation.Controllers (Epics)
Redux-Observable epics that orchestrate asynchronous workflows by listening to actions and coordinating use cases. These handle complex operations like download jobs, playlist management, and subtitle processing. See Controllers for detailed documentation.Store
Redux store configuration using Redux Toolkit slices to manage application state including playlists, jobs, levels, and configuration. The store is the single source of truth for the extension’s state. See Store for detailed documentation.Entities
Core data types and classes representing domain concepts:- Playlist: HLS master playlist representation
- Level: Individual quality level or track (video, audio, subtitle)
- Fragment: Individual media segment to download
- Job: Download job containing fragments and metadata
- Key: Encryption key information for decryption
Services
Abstract interfaces for platform-specific functionality that must be implemented by consuming packages:Dependencies
The core package relies on these key libraries:- @reduxjs/toolkit (1.9.3): Redux state management with modern patterns
- redux-observable (2.0.0): RxJS-based middleware for handling async actions
- rxjs (7.8.0): Reactive programming for complex async workflows
- typesafe-actions (5.1.0): Type-safe Redux action creators
Data flow
- User action: UI dispatches a Redux action
- Epic listening: Corresponding epic filters and processes the action
- Use case execution: Epic calls use case factories with dependencies
- Service interaction: Use cases interact with services (loader, parser, fs, decryptor)
- State update: Epic dispatches new actions to update Redux store
- UI reaction: React components re-render based on state changes
The core package contains no platform-specific code. All browser APIs, file system operations, and network requests are abstracted behind service interfaces.
Usage example
Testing
The core package includes comprehensive unit tests using Vitest:Build output
Source TypeScript files insrc/core/src/ compile to JavaScript in src/core/lib/. Never modify the lib/ directory directly.