Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
fix(providers): keep moviebox search payload native in the seam
Samir Hossains01cdde5f6c79
diff --git a/docs/providers.md b/docs/providers.mdindex c52b2eb..e5928c1 100644--- a/docs/providers.md+++ b/docs/providers.md@@ -18,12 +18,17 @@ default (`bdix_enabled` in config; `/enable-bdix`).## Shared flow-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.+Search, details, and episode-streams are dispatched per provider. Crate-internal seams+in `providers/mod.rs` give every client one interface and one error type:++- `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.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 99e7142..ed831ae 100644--- a/src/providers/bdix/circleftp/mod.rs+++ b/src/providers/bdix/circleftp/mod.rs@@ -5,13 +5,16 @@ pub use client::{CircleFtpClient, CircleFtpError};use crate::providers::{Provider, ReleaseProvider,- fourkhdhub::details_to_moviebox_json,- models::{CatalogItem, Release},+ fourkhdhub::{details_to_moviebox_json, search_to_moviebox_json},+ models::Release,};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())+ async fn search(&self, query: &str, _page: usize) -> Result<serde_json::Value, String> {+ self.search(query)+ .await+ .map(|items| search_to_moviebox_json(&items))+ .map_err(|error| error.to_string())}async fn details(&self, id: &str) -> Result<serde_json::Value, String> {diff --git a/src/providers/bdix/dhakaflix/mod.rs b/src/providers/bdix/dhakaflix/mod.rsindex 72a94b2..c01fb79 100644--- a/src/providers/bdix/dhakaflix/mod.rs+++ b/src/providers/bdix/dhakaflix/mod.rs@@ -2,13 +2,16 @@ pub mod client;use crate::providers::{Provider, ReleaseProvider,- fourkhdhub::details_to_moviebox_json,- models::{CatalogItem, Release},+ fourkhdhub::{details_to_moviebox_json, search_to_moviebox_json},+ models::Release,};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())+ async fn search(&self, query: &str, _page: usize) -> Result<serde_json::Value, String> {+ self.search(query)+ .await+ .map(|items| search_to_moviebox_json(&items))+ .map_err(|error| error.to_string())}async fn details(&self, id: &str) -> Result<serde_json::Value, String> {diff --git a/src/providers/fourkhdhub/mod.rs b/src/providers/fourkhdhub/mod.rsindex 7ec2d83..db2e77f 100644--- a/src/providers/fourkhdhub/mod.rs+++ b/src/providers/fourkhdhub/mod.rs@@ -5,14 +5,14 @@ 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::{CatalogItem, Release},-};+use crate::providers::{Provider, ReleaseProvider, models::Release};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())+ async fn search(&self, query: &str, _page: usize) -> Result<serde_json::Value, String> {+ self.search(query)+ .await+ .map(|items| search_to_moviebox_json(&items))+ .map_err(|error| error.to_string())}async fn details(&self, id: &str) -> Result<serde_json::Value, String> {diff --git a/src/providers/mod.rs b/src/providers/mod.rsindex 600b9f1..77b776f 100644--- a/src/providers/mod.rs+++ b/src/providers/mod.rs@@ -4,10 +4,10 @@ pub mod m3u;pub mod models;pub mod moviebox;-use models::{CatalogItem, Release};+use models::Release;pub(crate) trait Provider {- async fn search(&self, query: &str, page: usize) -> Result<Vec<CatalogItem>, String>;+ async fn search(&self, query: &str, page: usize) -> Result<serde_json::Value, String>;async fn details(&self, id: &str) -> Result<serde_json::Value, String>;}diff --git a/src/providers/models.rs b/src/providers/models.rsindex 27f9231..9408224 100644--- a/src/providers/models.rs+++ b/src/providers/models.rs@@ -117,15 +117,6 @@ pub struct SourceMirror {pub direct_file: bool,}-#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]-pub struct StreamItem {- pub resource_id: String,- pub link: String,- pub resolution: Option<u32>,- pub season: Option<usize>,- pub episode: Option<usize>,-}-#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]pub struct SubtitleOption {pub name: String,diff --git a/src/providers/moviebox/adapt.rs b/src/providers/moviebox/adapt.rsindex 3a14150..628afda 100644--- a/src/providers/moviebox/adapt.rs+++ b/src/providers/moviebox/adapt.rs@@ -1,189 +1,4 @@-use crate::providers::models::{- CatalogItem, MediaDetails, MediaType, ProviderKind, ProviderMediaId, StreamItem, SubtitleOption,-};--fn provider_id(id: &str) -> ProviderMediaId {- ProviderMediaId {- provider: ProviderKind::MovieBox,- value: id.to_string(),- }-}--fn media_type(value: &serde_json::Value) -> MediaType {- if value- .get("subjectType")- .or_else(|| value.get("stype"))- .and_then(|s| s.as_i64())- == Some(2)- {- MediaType::Series- } else {- MediaType::Movie- }-}--fn cover_url(value: &serde_json::Value) -> Option<String> {- value- .get("poster")- .or_else(|| value.get("cover"))- .or_else(|| value.get("pic"))- .and_then(|c| c.as_str().or_else(|| c.get("url").and_then(|u| u.as_str())))- .map(|s| s.to_string())-}--fn year(value: &serde_json::Value) -> Option<String> {- value- .get("year")- .or_else(|| value.get("releaseDate"))- .or_else(|| value.get("releaseYear"))- .and_then(|y| {- y.as_str()- .map(|s| s.to_string())- .or_else(|| y.as_i64().map(|n| n.to_string()))- })-}--pub fn search_json_to_catalog(payload: &serde_json::Value) -> Vec<CatalogItem> {- let Some(subjects) = payload- .get("results")- .and_then(|r| r.as_array())- .and_then(|arr| arr.first())- .and_then(|first| first.get("subjects"))- .and_then(|s| s.as_array())- else {- return Vec::new();- };-- subjects- .iter()- .filter_map(|item| {- let id = item.get("subjectId").and_then(|i| i.as_str())?;- let title = item- .get("title")- .and_then(|t| t.as_str())- .unwrap_or("Unknown");- Some(CatalogItem {- id: provider_id(id),- title: title.to_string(),- media_type: media_type(item),- year: year(item),- poster_url: cover_url(item),- season_count: item- .get("season")- .or_else(|| item.get("seasonCount"))- .and_then(|s| s.as_u64())- .map(|n| n as usize),- })- })- .collect()-}--pub fn details_json_to_media(details: &serde_json::Value) -> MediaDetails {- let id = details- .get("id")- .and_then(|i| i.as_str())- .unwrap_or("")- .to_string();- MediaDetails {- id: provider_id(&id),- title: details- .get("title")- .and_then(|t| t.as_str())- .unwrap_or("Unknown")- .to_string(),- media_type: media_type(details),- year: year(details),- description: details- .get("synopsis")- .or_else(|| details.get("description"))- .and_then(|s| s.as_str())- .map(|s| s.to_string()),- tagline: details- .get("intro")- .or_else(|| details.get("tagline"))- .and_then(|s| s.as_str())- .map(|s| s.to_string()),- imdb_rating: details- .get("imdbRatingValue")- .or_else(|| details.get("imdbRating"))- .and_then(|s| s.as_str())- .map(|s| s.to_string()),- director: details- .get("director")- .and_then(|s| s.as_str())- .map(|s| s.to_string()),- stars: details- .get("stars")- .and_then(|s| s.as_str())- .map(|s| s.to_string()),- prints: details- .get("prints")- .and_then(|s| s.as_str())- .map(|s| s.to_string()),- audios: details- .get("audios")- .and_then(|s| s.as_str())- .map(|s| s.to_string()),- poster_url: cover_url(details),- duration: details- .get("duration")- .and_then(|s| s.as_str())- .map(|s| s.to_string()),- genres: match details.get("genre") {- Some(serde_json::Value::Array(items)) => items- .iter()- .filter_map(|g| g.as_str())- .map(|s| s.to_string())- .collect(),- Some(value) => value- .as_str()- .map(|s| {- s.split(['/', ','])- .map(str::trim)- .filter(|g| !g.is_empty())- .map(|g| g.to_string())- .collect()- })- .unwrap_or_default(),- None => Vec::new(),- },- seasons: Vec::new(),- }-}--pub fn stream_json_to_items(payload: &serde_json::Value) -> Vec<StreamItem> {- let items = match payload {- serde_json::Value::Array(items) => items,- value => match value.get("list") {- Some(serde_json::Value::Array(items)) => items,- _ => return Vec::new(),- },- };-- items- .iter()- .filter_map(|item| {- let link = item.get("resourceLink").and_then(|l| l.as_str())?;- if link.is_empty() {- return None;- }- Some(StreamItem {- resource_id: item- .get("resourceId")- .and_then(|r| r.as_str())- .unwrap_or("")- .to_string(),- link: link.to_string(),- resolution: item- .get("resolution")- .and_then(|r| r.as_u64())- .map(|n| n as u32),- season: item.get("se").and_then(|s| s.as_u64()).map(|n| n as usize),- episode: item.get("ep").and_then(|s| s.as_u64()).map(|n| n as usize),- })- })- .collect()-}+use crate::providers::models::SubtitleOption;pub fn captions_json_to_options(payload: &serde_json::Value) -> Vec<SubtitleOption> {let Some(captions) = payload.get("extCaptions").and_then(|c| c.as_array()) else {diff --git a/src/providers/moviebox/mod.rs b/src/providers/moviebox/mod.rsindex a8cc2e4..2159c9b 100644--- a/src/providers/moviebox/mod.rs+++ b/src/providers/moviebox/mod.rs@@ -5,15 +5,13 @@ pub mod title;pub use title::clean_moviebox_title;-use crate::providers::{Provider, models::CatalogItem};+use crate::providers::Provider;impl Provider for client::MovieBoxClient {- async fn search(&self, query: &str, page: usize) -> Result<Vec<CatalogItem>, String> {- let value = self- .search(query, page)+ async fn search(&self, query: &str, page: usize) -> Result<serde_json::Value, String> {+ self.search(query, page).await- .map_err(|error| format!("{error:?}"))?;- Ok(adapt::search_json_to_catalog(&value))+ .map_err(|error| format!("{error:?}"))}async fn details(&self, id: &str) -> Result<serde_json::Value, String> {diff --git a/src/tui/app/network.rs b/src/tui/app/network.rsindex 8badfc7..3c3bda6 100644--- a/src/tui/app/network.rs+++ b/src/tui/app/network.rs@@ -1,8 +1,5 @@use crate::providers::{- Provider,- fourkhdhub::{FourKHdHubClient, search_to_moviebox_json},- models::ProviderKind,- moviebox::client::MovieBoxClient,+ Provider, fourkhdhub::FourKHdHubClient, models::ProviderKind, moviebox::client::MovieBoxClient,};pub(super) async fn fetch_poster_bytes(client: &reqwest::Client, url: &str) -> Option<Vec<u8>> {@@ -32,13 +29,12 @@ pub(super) async fn provider_search(query: &str,page: usize,) -> Result<serde_json::Value, String> {- let result = match provider {+ 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(