Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
refactor(providers): route details through the Provider seam
Samir Hossains9951a0e2737e
diff --git a/src/providers/bdix/circleftp/mod.rs b/src/providers/bdix/circleftp/mod.rsindex ef2502f..b6d4b46 100644--- a/src/providers/bdix/circleftp/mod.rs+++ b/src/providers/bdix/circleftp/mod.rs@@ -3,10 +3,17 @@ pub mod parser;pub use client::{CircleFtpClient, CircleFtpError};-use crate::providers::{Provider, models::CatalogItem};+use crate::providers::{Provider, fourkhdhub::details_to_moviebox_json, 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())}++ async fn details(&self, id: &str) -> Result<serde_json::Value, String> {+ self.details(id)+ .await+ .map(|details| details_to_moviebox_json(&details))+ .map_err(|error| error.to_string())+ }}diff --git a/src/providers/bdix/dhakaflix/mod.rs b/src/providers/bdix/dhakaflix/mod.rsindex ad4472a..26bd85d 100644--- a/src/providers/bdix/dhakaflix/mod.rs+++ b/src/providers/bdix/dhakaflix/mod.rs@@ -1,9 +1,16 @@pub mod client;-use crate::providers::{Provider, models::CatalogItem};+use crate::providers::{Provider, fourkhdhub::details_to_moviebox_json, 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())}++ async fn details(&self, id: &str) -> Result<serde_json::Value, String> {+ self.details(id)+ .await+ .map(|details| details_to_moviebox_json(&details))+ .map_err(|error| error.to_string())+ }}diff --git a/src/providers/fourkhdhub/mod.rs b/src/providers/fourkhdhub/mod.rsindex 237b4c8..e1ad87d 100644--- a/src/providers/fourkhdhub/mod.rs+++ b/src/providers/fourkhdhub/mod.rs@@ -11,4 +11,11 @@ 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 details(&self, id: &str) -> Result<serde_json::Value, String> {+ self.details(id)+ .await+ .map(|details| details_to_moviebox_json(&details))+ .map_err(|error| error.to_string())+ }}diff --git a/src/providers/mod.rs b/src/providers/mod.rsindex c146c3e..f594203 100644--- a/src/providers/mod.rs+++ b/src/providers/mod.rs@@ -8,4 +8,5 @@ use models::CatalogItem;pub(crate) trait Provider {async fn search(&self, query: &str, page: usize) -> Result<Vec<CatalogItem>, String>;+ async fn details(&self, id: &str) -> Result<serde_json::Value, String>;}diff --git a/src/providers/moviebox/mod.rs b/src/providers/moviebox/mod.rsindex 5d107eb..a8cc2e4 100644--- a/src/providers/moviebox/mod.rs+++ b/src/providers/moviebox/mod.rs@@ -15,6 +15,12 @@ impl Provider for client::MovieBoxClient {.map_err(|error| format!("{error:?}"))?;Ok(adapt::search_json_to_catalog(&value))}++ async fn details(&self, id: &str) -> Result<serde_json::Value, String> {+ self.get_details(id)+ .await+ .map_err(|error| format!("{error:?}"))+ }}use client::{MovieBoxClient, ScraperError};diff --git a/src/tui/app/network.rs b/src/tui/app/network.rsindex 880eaff..8badfc7 100644--- a/src/tui/app/network.rs+++ b/src/tui/app/network.rs@@ -1,6 +1,6 @@use crate::providers::{Provider,- fourkhdhub::{FourKHdHubClient, details_to_moviebox_json, search_to_moviebox_json},+ fourkhdhub::{FourKHdHubClient, search_to_moviebox_json},models::ProviderKind,moviebox::client::MovieBoxClient,};@@ -50,24 +50,9 @@ pub(super) async fn provider_details(subject_id: &str,) -> Result<serde_json::Value, String> {match provider {- ProviderKind::MovieBox => moviebox- .get_details(subject_id)- .await- .map_err(|error| format!("{error:?}")),- ProviderKind::FourKHdHub => fourk- .details(subject_id)- .await- .map(|details| details_to_moviebox_json(&details))- .map_err(|error| error.to_string()),- ProviderKind::BdixCircleFtp => circleftp- .details(subject_id)- .await- .map(|details| crate::providers::fourkhdhub::details_to_moviebox_json(&details))- .map_err(|error| error.to_string()),- ProviderKind::BdixDhakaFlix => dhakaflix- .details(subject_id)- .await- .map(|details| crate::providers::fourkhdhub::details_to_moviebox_json(&details))- .map_err(|error| error.to_string()),+ ProviderKind::MovieBox => Provider::details(moviebox, subject_id).await,+ ProviderKind::FourKHdHub => Provider::details(fourk, subject_id).await,+ ProviderKind::BdixCircleFtp => Provider::details(circleftp, subject_id).await,+ ProviderKind::BdixDhakaFlix => Provider::details(dhakaflix, subject_id).await,}}