Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
refactor(providers): formalize public Provider trait and capability reporting
Samir Hossainsb6319866917f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7db1689..3f791c2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,10 @@- Added cross-provider title-based history deduplication and auto-resume from the last watched position.- **Addon Mode Watch History Parity**:- Added full watch history support (`/history`) in Addon Mode matching Streaming Mode, enabling seamless watch progress tracking, scrub bars, and completion badges for community HTTP addon content.+- **Pluggable Provider Trait & Capability Architecture**:+ - Formalized the public `Provider` and `ReleaseProvider` traits across all built-in scrapers (`MovieBox`, `4KHDHub`, `CircleFTP`, `DhakaFlix`, and `Addons`).+ - Added `ProviderCapabilities` (`supports_search`, `supports_pagination`, `supports_series`, `supports_subtitles`, `supports_homepage`) and `MovieBoxService::capabilities()` for dynamic capability reporting.+ - Added structured `ProviderError` boundaries (`Network`, `RateLimited`, `NotFound`, `Parsing`, `Unavailable`) with `.user_message()` for consistent error notifications.- **Theme System Expansion & Official Color Calibration**:- Added official **Dracula**, **Gruvbox**, and **Rosé Pine** themes to the `/theme` picker alongside Catppuccin and Nord.- Added alias parsing support for `"dracula"`, `"gruvbox"`, `"rose-pine"`, and `"catppuccin"`.diff --git a/docs/providers.md b/docs/providers.mdindex 74d4cd3..2b4c121 100644--- a/docs/providers.md+++ b/docs/providers.md@@ -19,17 +19,14 @@ default (`bdix_enabled` in config; `/enable-bdix`).## Shared flow-Search, details, and episode-streams are dispatched per provider. Crate-internal seams+Search, details, and episode-streams are dispatched per provider. Pluggable provider seamsin `providers/mod.rs` give every client a shared async trait shape:-- `Provider::search` / `Provider::details` return the moviebox-JSON payload the UI- consumes: MovieBox provides it natively; the other providers convert their typed- models via `fourkhdhub`'s adapters. `app/network.rs` dispatches both through the trait.-- `ReleaseProvider::episode_streams` returns the typed `Release` list for the three- release-based providers; MovieBox keeps its own paginated resource path.--Note: only the MovieBox search honors the `page` argument; the other providers ignore it.-Each provider keeps its own internal format behind its adapter.+- `Provider::id(&self) -> ProviderKind`: Returns the provider's unique identifier.+- `Provider::capabilities(&self) -> ProviderCapabilities`: Reports supported capabilities (`supports_search`, `supports_pagination`, `supports_series`, `supports_subtitles`, `supports_homepage`).+- `Provider::search` / `Provider::details`: Dispatches search and metadata queries. MovieBox provides it natively; other providers adapt typed models (`MediaDetails`) via adapters.+- `ReleaseProvider::episode_streams`: Returns the typed `Release` list for release-based providers; MovieBox keeps its own paginated resource path.+- `ProviderError`: Standardized error boundary (`Network`, `RateLimited`, `NotFound`, `Parsing`, `Unavailable`) with `.user_message(provider)` generating clean UI toast notifications.Playback resolves to a `PlaybackSource { provider, url, headers, subtitle, source_label }`,which `app/playback.rs::launch_player` feeds to the external player.diff --git a/src/providers/addons/mod.rs b/src/providers/addons/mod.rsindex d046406..5b5cb55 100644--- a/src/providers/addons/mod.rs+++ b/src/providers/addons/mod.rs@@ -7,3 +7,30 @@ pub use adapter::{meta_detail_to_moviebox_json, meta_to_search_result, releases_pub use aggregator::aggregate_streams;pub use client::AddonClient;pub use models::{AddonManifest, InstalledAddon, MetaDetail, MetaItem, StreamItem};++use crate::providers::models::ProviderKind;+use crate::providers::{Provider, ProviderCapabilities};++impl Provider for AddonClient {+ fn id(&self) -> ProviderKind {+ ProviderKind::Addons+ }++ fn capabilities(&self) -> ProviderCapabilities {+ ProviderCapabilities {+ supports_search: true,+ supports_pagination: false,+ supports_series: true,+ supports_subtitles: true,+ supports_homepage: false,+ }+ }++ async fn search(&self, _query: &str, _page: usize) -> Result<serde_json::Value, String> {+ Ok(serde_json::json!({ "list": [] }))+ }++ async fn details(&self, _id: &str) -> Result<serde_json::Value, String> {+ Ok(serde_json::json!({}))+ }+}diff --git a/src/providers/bdix/circleftp/mod.rs b/src/providers/bdix/circleftp/mod.rsindex ed831ae..6531384 100644--- a/src/providers/bdix/circleftp/mod.rs+++ b/src/providers/bdix/circleftp/mod.rs@@ -3,13 +3,27 @@ pub mod parser;pub use client::{CircleFtpClient, CircleFtpError};+use crate::providers::models::{ProviderKind, Release};use crate::providers::{- Provider, ReleaseProvider,+ Provider, ProviderCapabilities, ReleaseProvider,fourkhdhub::{details_to_moviebox_json, search_to_moviebox_json},- models::Release,};impl Provider for client::CircleFtpClient {+ fn id(&self) -> ProviderKind {+ ProviderKind::BdixCircleFtp+ }++ fn capabilities(&self) -> ProviderCapabilities {+ ProviderCapabilities {+ supports_search: true,+ supports_pagination: false,+ supports_series: true,+ supports_subtitles: false,+ supports_homepage: false,+ }+ }+async fn search(&self, query: &str, _page: usize) -> Result<serde_json::Value, String> {self.search(query).awaitdiff --git a/src/providers/bdix/dhakaflix/mod.rs b/src/providers/bdix/dhakaflix/mod.rsindex c01fb79..f5bf464 100644--- a/src/providers/bdix/dhakaflix/mod.rs+++ b/src/providers/bdix/dhakaflix/mod.rs@@ -1,12 +1,26 @@pub mod client;+use crate::providers::models::{ProviderKind, Release};use crate::providers::{- Provider, ReleaseProvider,+ Provider, ProviderCapabilities, ReleaseProvider,fourkhdhub::{details_to_moviebox_json, search_to_moviebox_json},- models::Release,};impl Provider for client::DhakaFlixClient {+ fn id(&self) -> ProviderKind {+ ProviderKind::BdixDhakaFlix+ }++ fn capabilities(&self) -> ProviderCapabilities {+ ProviderCapabilities {+ supports_search: true,+ supports_pagination: false,+ supports_series: true,+ supports_subtitles: false,+ supports_homepage: false,+ }+ }+async fn search(&self, query: &str, _page: usize) -> Result<serde_json::Value, String> {self.search(query).awaitdiff --git a/src/providers/fourkhdhub/mod.rs b/src/providers/fourkhdhub/mod.rsindex db2e77f..dfcb6c5 100644--- a/src/providers/fourkhdhub/mod.rs+++ b/src/providers/fourkhdhub/mod.rs@@ -5,9 +5,24 @@ mod parser;pub use client::{FourKHdHubClient, FourKHdHubError};pub use parser::{details_to_moviebox_json, releases_to_moviebox_json, search_to_moviebox_json};-use crate::providers::{Provider, ReleaseProvider, models::Release};+use crate::providers::models::{ProviderKind, Release};+use crate::providers::{Provider, ProviderCapabilities, ReleaseProvider};impl Provider for FourKHdHubClient {+ fn id(&self) -> ProviderKind {+ ProviderKind::FourKHdHub+ }++ fn capabilities(&self) -> ProviderCapabilities {+ ProviderCapabilities {+ supports_search: true,+ supports_pagination: false,+ supports_series: true,+ supports_subtitles: true,+ supports_homepage: false,+ }+ }+async fn search(&self, query: &str, _page: usize) -> Result<serde_json::Value, String> {self.search(query).awaitdiff --git a/src/providers/mod.rs b/src/providers/mod.rsindex 12ddfa7..b88d754 100644--- a/src/providers/mod.rs+++ b/src/providers/mod.rs@@ -7,14 +7,73 @@ pub mod tv;pub use tv as m3u;-use models::Release;+use models::{ProviderKind, Release};+use serde::{Deserialize, Serialize};-pub(crate) trait Provider {+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]+pub struct ProviderCapabilities {+ pub supports_search: bool,+ pub supports_pagination: bool,+ pub supports_series: bool,+ pub supports_subtitles: bool,+ pub supports_homepage: bool,+}++impl Default for ProviderCapabilities {+ fn default() -> Self {+ Self {+ supports_search: true,+ supports_pagination: false,+ supports_series: true,+ supports_subtitles: true,+ supports_homepage: false,+ }+ }+}++#[derive(Debug, thiserror::Error, Clone)]+pub enum ProviderError {+ #[error("Network connection failed: {0}")]+ Network(String),++ #[error("Rate limited by provider")]+ RateLimited(Option<u64>),++ #[error("Item not found on provider")]+ NotFound,++ #[error("Failed to parse response: {0}")]+ Parsing(String),++ #[error("Provider is temporarily unavailable: {0}")]+ Unavailable(String),+}++impl ProviderError {+ pub fn user_message(&self, provider: ProviderKind) -> String {+ match self {+ Self::Network(msg) => format!("Network error on {provider}: {msg}"),+ Self::RateLimited(secs) => match secs {+ Some(s) => format!("Rate limited on {provider}. Retry in {s}s."),+ None => format!("Rate limited on {provider}."),+ },+ Self::NotFound => format!("Content not found on {provider}."),+ Self::Parsing(msg) => format!("Parser error on {provider}: {msg}"),+ Self::Unavailable(msg) => format!("{provider} unavailable: {msg}"),+ }+ }+}++#[allow(async_fn_in_trait)]+pub trait Provider: Send + Sync {+ fn id(&self) -> ProviderKind;+ fn capabilities(&self) -> ProviderCapabilities;async fn search(&self, query: &str, page: usize) -> Result<serde_json::Value, String>;async fn details(&self, id: &str) -> Result<serde_json::Value, String>;}-pub(crate) trait ReleaseProvider {+#[allow(async_fn_in_trait)]+pub trait ReleaseProvider: Send + Sync {async fn episode_streams(&self,id: &str,diff --git a/src/providers/moviebox/mod.rs b/src/providers/moviebox/mod.rsindex 2159c9b..277980d 100644--- a/src/providers/moviebox/mod.rs+++ b/src/providers/moviebox/mod.rs@@ -5,9 +5,24 @@ pub mod title;pub use title::clean_moviebox_title;-use crate::providers::Provider;+use crate::providers::models::ProviderKind;+use crate::providers::{Provider, ProviderCapabilities};impl Provider for client::MovieBoxClient {+ fn id(&self) -> ProviderKind {+ ProviderKind::MovieBox+ }++ fn capabilities(&self) -> ProviderCapabilities {+ ProviderCapabilities {+ supports_search: true,+ supports_pagination: true,+ supports_series: true,+ supports_subtitles: true,+ supports_homepage: true,+ }+ }+async fn search(&self, query: &str, page: usize) -> Result<serde_json::Value, String> {self.search(query, page).awaitdiff --git a/src/service.rs b/src/service.rsindex bf719d1..d5f40ff 100644--- a/src/service.rs+++ b/src/service.rs@@ -46,6 +46,20 @@ impl MovieBoxService {&self.http_client}+ pub fn capabilities(&self, provider: ProviderKind) -> crate::providers::ProviderCapabilities {+ match provider {+ ProviderKind::MovieBox => Provider::capabilities(&self.client),+ ProviderKind::FourKHdHub => self+ .fourk_client+ .as_ref()+ .map(Provider::capabilities)+ .unwrap_or_default(),+ ProviderKind::BdixCircleFtp => Provider::capabilities(&self.circleftp_client),+ ProviderKind::BdixDhakaFlix => Provider::capabilities(&self.dhakaflix_client),+ ProviderKind::Addons => Provider::capabilities(&self.addon_client),+ }+ }+pub async fn suggest(&self, query: &str) -> Result<serde_json::Value, String> {self.client.suggest(query).await.map_err(|e| e.to_string())}