Skip to content

Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.

fix(providers): persist dhakaflix config and harden async requests

Samir Hossains7f7068c28f7a
diff --git a/src/cache.rs b/src/cache.rs
index ec9c7c6..21e906a 100644
--- a/src/cache.rs
+++ b/src/cache.rs
@@ -76,7 +76,17 @@ pub fn set_typed_cache<T: Serialize + ?Sized>(path: &Path, expiry_secs: u64, dat
let mut file_bytes = Vec::with_capacity(4 + msgpack_bytes.len());
file_bytes.extend_from_slice(&CACHE_MAGIC);
file_bytes.extend_from_slice(&msgpack_bytes);
- let _ = atomic_write_file(path, &file_bytes);
+ if let Err(error) = atomic_write_file(path, &file_bytes) {
+ log::warn!(
+ "failed to write cache file {}: {error}",
+ crate::logging::sanitize_path(path)
+ );
+ }
+ } else {
+ log::warn!(
+ "failed to serialize cache envelope for {}",
+ crate::logging::sanitize_path(path)
+ );
}
}
diff --git a/src/net.rs b/src/net.rs
index 168738b..c483c40 100644
--- a/src/net.rs
+++ b/src/net.rs
@@ -43,10 +43,15 @@ fn fallback_config() -> ResolverConfig {
fn build_resolver() -> TokioResolver {
let mut builder = match TokioResolver::builder_tokio() {
Ok(builder) => builder,
- Err(_) => TokioResolver::builder_with_config(
- fallback_config(),
- TokioConnectionProvider::default(),
- ),
+ Err(e) => {
+ log::warn!(
+ "system DNS resolver failed ({e}); falling back to public DNS (Cloudflare/Google/Quad9)"
+ );
+ TokioResolver::builder_with_config(
+ fallback_config(),
+ TokioConnectionProvider::default(),
+ )
+ }
};
builder.options_mut().ip_strategy = LookupIpStrategy::Ipv4AndIpv6;
builder.build()
@@ -74,6 +79,8 @@ pub fn http_client_builder() -> reqwest::ClientBuilder {
.tcp_keepalive(Some(std::time::Duration::from_secs(45)))
.pool_idle_timeout(Some(std::time::Duration::from_secs(90)))
.pool_max_idle_per_host(8)
+ .connect_timeout(std::time::Duration::from_secs(15))
+ .timeout(std::time::Duration::from_secs(60))
}
pub async fn probe_url(url: &str, timeout: std::time::Duration) -> bool {
@@ -84,15 +91,32 @@ pub async fn probe_url(url: &str, timeout: std::time::Duration) -> bool {
else {
return false;
};
- if let Ok(resp) = client.head(url).send().await {
- if resp.status().is_success() || resp.status().is_redirection() {
- return true;
+ match client.head(url).send().await {
+ Ok(resp) if resp.status().is_success() || resp.status().is_redirection() => return true,
+ Ok(resp) => {
+ log::debug!(
+ "probe HEAD non-success for {}: {}",
+ crate::logging::sanitize_url(url),
+ resp.status()
+ );
+ }
+ Err(e) => {
+ log::debug!(
+ "probe HEAD error for {}: {e}",
+ crate::logging::sanitize_url(url)
+ );
}
}
- if let Ok(resp) = client.get(url).send().await {
- return resp.status().is_success() || resp.status().is_redirection();
+ match client.get(url).send().await {
+ Ok(resp) => resp.status().is_success() || resp.status().is_redirection(),
+ Err(e) => {
+ log::debug!(
+ "probe GET error for {}: {e}",
+ crate::logging::sanitize_url(url)
+ );
+ false
+ }
}
- false
}
pub fn is_http_url(source: &str) -> bool {
diff --git a/src/providers/addons/aggregator.rs b/src/providers/addons/aggregator.rs
index fa13113..7717e86 100644
--- a/src/providers/addons/aggregator.rs
+++ b/src/providers/addons/aggregator.rs
@@ -55,7 +55,10 @@ pub async fn aggregate_streams(
(releases, None)
}
}
- Err(_) => (Vec::new(), None),
+ Err(err) => {
+ log::warn!("addon {addon_name} failed to fetch streams: {err}");
+ (Vec::new(), None)
+ }
}
});
}
diff --git a/src/providers/bdix/circleftp/client.rs b/src/providers/bdix/circleftp/client.rs
index 12be322..bda9181 100644
--- a/src/providers/bdix/circleftp/client.rs
+++ b/src/providers/bdix/circleftp/client.rs
@@ -48,7 +48,7 @@ impl CircleFtpClient {
.append_pair("searchTerm", query)
.append_pair("order", "desc");
- let resp = self.client.get(url).send().await?;
+ let resp = self.client.get(url).send().await?.error_for_status()?;
let search_resp: CircleFtpSearchResponse = resp.json().await?;
Ok(circleftp_search_to_catalog(&search_resp))
@@ -56,7 +56,7 @@ impl CircleFtpClient {
pub async fn details(&self, id: &str) -> Result<MediaDetails, CircleFtpError> {
let url = format!("{}/posts/{}", self.base_url, id);
- let resp = self.client.get(&url).send().await?;
+ let resp = self.client.get(&url).send().await?.error_for_status()?;
let json: serde_json::Value = resp.json().await?;
let title = json
@@ -302,10 +302,6 @@ impl CircleFtpClient {
Ok(releases)
}
-
- pub async fn resolve_release(&self, resolver_url: &str) -> Result<String, CircleFtpError> {
- Ok(resolver_url.to_string())
- }
}
fn build_client() -> reqwest::Client {
diff --git a/src/providers/bdix/dhakaflix/client.rs b/src/providers/bdix/dhakaflix/client.rs
index 7af6dcc..fd70e94 100644
--- a/src/providers/bdix/dhakaflix/client.rs
+++ b/src/providers/bdix/dhakaflix/client.rs
@@ -414,10 +414,6 @@ impl DhakaFlixClient {
Ok(releases)
}
-
- pub async fn resolve_release(&self, resolver_url: &str) -> Result<String, DhakaFlixError> {
- Ok(resolver_url.to_string())
- }
}
fn parse_dhakaflix_id(id: &str) -> Option<(&str, &str)> {
diff --git a/src/providers/dramachi/client.rs b/src/providers/dramachi/client.rs
index 9d5dddd..69d30bc 100644
--- a/src/providers/dramachi/client.rs
+++ b/src/providers/dramachi/client.rs
@@ -85,7 +85,7 @@ impl DramachiClient {
page.max(1)
);
- let resp = self.client.get(&url).send().await?;
+ let resp = self.client.get(&url).send().await?.error_for_status()?;
let data: DramachiSearchResponse = resp
.json()
.await
@@ -143,7 +143,7 @@ impl DramachiClient {
self.base_url,
encode_param(title_id)
);
- let resp = self.client.get(&url).send().await?;
+ let resp = self.client.get(&url).send().await?.error_for_status()?;
let data: DramachiTitleDetailsResponse = resp
.json()
.await
@@ -351,7 +351,7 @@ impl DramachiClient {
encode_param(title_id)
);
- let resp = self.client.get(&url).send().await?;
+ let resp = self.client.get(&url).send().await?.error_for_status()?;
let data: DramachiEpisodeListResponse = resp
.json()
.await
diff --git a/src/providers/tv/parser.rs b/src/providers/tv/parser.rs
index 5ff5bfe..abd4ece 100644
--- a/src/providers/tv/parser.rs
+++ b/src/providers/tv/parser.rs
@@ -36,7 +36,7 @@ impl M3UParser {
let file_path = self.cache_dir.join(cache_filename(trimmed));
let mut needs_download = true;
- if file_path.exists() {
+ if tokio::fs::try_exists(&file_path).await.unwrap_or(false) {
if let Ok(metadata) = tokio::fs::metadata(&file_path).await {
if let Ok(modified) = metadata.modified() {
if let Ok(duration) = SystemTime::now().duration_since(modified) {
diff --git a/src/tui/app/mod.rs b/src/tui/app/mod.rs
index bdf48d2..ea9ce78 100644
--- a/src/tui/app/mod.rs
+++ b/src/tui/app/mod.rs
@@ -116,6 +116,7 @@ impl App {
state.fourkhdhub_enabled = config.fourkhdhub_enabled;
state.dramachi_enabled = config.dramachi_enabled;
state.bdix_circleftp_enabled = config.bdix_circleftp_enabled;
+ state.bdix_dhakaflix_enabled = config.bdix_dhakaflix_enabled;
state.bdix_probed = config.bdix_probed;
state.streaming_enabled = config.streaming_enabled;
state.tv_enabled = config.tv_enabled;
@@ -335,7 +336,8 @@ impl App {
Ok(channels) => all_channels.extend(channels),
Err(error) => {
failed += 1;
- log::warn!("tv playlist failed ({source}): {error}");
+ let safe_source = crate::logging::sanitize_url(source);
+ log::warn!("tv playlist failed ({safe_source}): {error}");
}
}
}