Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
refactor(providers): add Provider seam and route search through it
Samir Hossains60cbccd04fca
diff --git a/docs/providers.md b/docs/providers.mdindex 5175b52..c52b2eb 100644--- a/docs/providers.md+++ b/docs/providers.md@@ -18,10 +18,12 @@ default (`bdix_enabled` in config; `/enable-bdix`).## Shared flow-Search, details, and episode-streams are dispatched per provider in-`app/network.rs` (`provider_search`, `provider_details`) and `app/requests.rs`.-Each provider returns typed models; non-moviebox results are converted to the moviebox-JSON schema by `fourkhdhub/parser.rs` adapters before reaching the UI.+Search, details, and episode-streams are dispatched per provider. A crate-internal+`Provider` trait (in `providers/mod.rs`) gives every client one `search` interface+returning the typed `CatalogItem` list; `app/network.rs::provider_search` dispatches+through it and normalizes to the moviebox JSON the UI consumes. `provider_details` still+uses the concrete clients pending typed details wiring. Each provider keeps its own+internal format and adapter.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/bdix/circleftp/mod.rs b/src/providers/bdix/circleftp/mod.rsindex 9145a12..ef2502f 100644--- a/src/providers/bdix/circleftp/mod.rs+++ b/src/providers/bdix/circleftp/mod.rs@@ -2,3 +2,11 @@ pub mod client;pub mod parser;pub use client::{CircleFtpClient, CircleFtpError};++use crate::providers::{Provider, models::CatalogItem};++impl Provider for client::CircleFtpClient {+ async fn search(&self, query: &str, _page: usize) -> Result<Vec<CatalogItem>, String> {+ self.search(query).await.map_err(|error| error.to_string())+ }+}diff --git a/src/providers/bdix/dhakaflix/mod.rs b/src/providers/bdix/dhakaflix/mod.rsindex b9babe5..ad4472a 100644--- a/src/providers/bdix/dhakaflix/mod.rs+++ b/src/providers/bdix/dhakaflix/mod.rs@@ -1 +1,9 @@pub mod client;++use crate::providers::{Provider, models::CatalogItem};++impl Provider for client::DhakaFlixClient {+ async fn search(&self, query: &str, _page: usize) -> Result<Vec<CatalogItem>, String> {+ self.search(query).await.map_err(|error| error.to_string())+ }+}diff --git a/src/providers/fourkhdhub/mod.rs b/src/providers/fourkhdhub/mod.rsindex 6812315..237b4c8 100644--- a/src/providers/fourkhdhub/mod.rs+++ b/src/providers/fourkhdhub/mod.rs@@ -4,3 +4,11 @@ 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, models::CatalogItem};++impl Provider for FourKHdHubClient {+ async fn search(&self, query: &str, _page: usize) -> Result<Vec<CatalogItem>, String> {+ self.search(query).await.map_err(|error| error.to_string())+ }+}diff --git a/src/providers/mod.rs b/src/providers/mod.rsindex 04f454c..c146c3e 100644--- a/src/providers/mod.rs+++ b/src/providers/mod.rs@@ -3,3 +3,9 @@ pub mod fourkhdhub;pub mod m3u;pub mod models;pub mod moviebox;++use models::CatalogItem;++pub(crate) trait Provider {+ async fn search(&self, query: &str, page: usize) -> Result<Vec<CatalogItem>, String>;+}diff --git a/src/providers/moviebox/adapt.rs b/src/providers/moviebox/adapt.rsindex 5dd6f33..3a14150 100644--- a/src/providers/moviebox/adapt.rs+++ b/src/providers/moviebox/adapt.rs@@ -69,7 +69,8 @@ pub fn search_json_to_catalog(payload: &serde_json::Value) -> Vec<CatalogItem> {year: year(item),poster_url: cover_url(item),season_count: item- .get("seasonCount")+ .get("season")+ .or_else(|| item.get("seasonCount")).and_then(|s| s.as_u64()).map(|n| n as usize),})diff --git a/src/providers/moviebox/mod.rs b/src/providers/moviebox/mod.rsindex d39d619..5d107eb 100644--- a/src/providers/moviebox/mod.rs+++ b/src/providers/moviebox/mod.rs@@ -5,6 +5,18 @@ pub mod title;pub use title::clean_moviebox_title;+use crate::providers::{Provider, models::CatalogItem};++impl Provider for client::MovieBoxClient {+ async fn search(&self, query: &str, page: usize) -> Result<Vec<CatalogItem>, String> {+ let value = self+ .search(query, page)+ .await+ .map_err(|error| format!("{error:?}"))?;+ Ok(adapt::search_json_to_catalog(&value))+ }+}+use client::{MovieBoxClient, ScraperError};use serde_json::{Value, json};diff --git a/src/tui/app/network.rs b/src/tui/app/network.rsindex 7cb25df..880eaff 100644--- a/src/tui/app/network.rs+++ b/src/tui/app/network.rs@@ -1,4 +1,5 @@use crate::providers::{+ Provider,fourkhdhub::{FourKHdHubClient, details_to_moviebox_json, search_to_moviebox_json},models::ProviderKind,moviebox::client::MovieBoxClient,@@ -31,27 +32,13 @@ pub(super) async fn provider_search(query: &str,page: usize,) -> Result<serde_json::Value, String> {- match provider {- ProviderKind::MovieBox => moviebox- .search(query, page)- .await- .map_err(|error| format!("{error:?}")),- ProviderKind::FourKHdHub => fourk- .search(query)- .await- .map(|items| search_to_moviebox_json(&items))- .map_err(|error| error.to_string()),- ProviderKind::BdixCircleFtp => circleftp- .search(query)- .await- .map(|items| crate::providers::fourkhdhub::search_to_moviebox_json(&items))- .map_err(|error| error.to_string()),- ProviderKind::BdixDhakaFlix => dhakaflix- .search(query)- .await- .map(|items| crate::providers::fourkhdhub::search_to_moviebox_json(&items))- .map_err(|error| error.to_string()),- }+ let result = match provider {+ ProviderKind::MovieBox => Provider::search(moviebox, query, page).await,+ ProviderKind::FourKHdHub => Provider::search(fourk, query, page).await,+ ProviderKind::BdixCircleFtp => Provider::search(circleftp, query, page).await,+ ProviderKind::BdixDhakaFlix => Provider::search(dhakaflix, query, page).await,+ };+ result.map(|items| search_to_moviebox_json(&items))}pub(super) async fn provider_details(