Skip to content

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

fix(provider): centralize provider parsing

Samir Hossainsa70782d374d0
diff --git a/src/providers/models.rs b/src/providers/models.rs
index 9408224..d575102 100644
--- a/src/providers/models.rs
+++ b/src/providers/models.rs
@@ -37,6 +37,16 @@ impl ProviderKind {
}
}
+ pub fn parse(value: &str) -> Option<Self> {
+ match value.trim().to_ascii_lowercase().as_str() {
+ "moviebox" => Some(Self::MovieBox),
+ "4khdhub" | "fourkhdhub" => Some(Self::FourKHdHub),
+ "bdix_circleftp" | "circleftp (bdix)" => Some(Self::BdixCircleFtp),
+ "bdix_dhakaflix" | "dhakaflix (bdix)" => Some(Self::BdixDhakaFlix),
+ _ => None,
+ }
+ }
+
pub const fn is_bdix(self) -> bool {
matches!(self, Self::BdixCircleFtp | Self::BdixDhakaFlix)
}
diff --git a/src/tui/app/requests.rs b/src/tui/app/requests.rs
index e125c3b..6135e61 100644
--- a/src/tui/app/requests.rs
+++ b/src/tui/app/requests.rs
@@ -158,15 +158,13 @@ impl App {
for item in recent {
use crate::providers::models::ProviderKind;
- let stored = item.provider.to_ascii_lowercase();
- let provider = ProviderKind::ENABLED
- .iter()
- .copied()
- .find(|provider| {
- stored == provider.label().to_ascii_lowercase()
- || stored == provider.cache_key()
- })
- .unwrap_or(self.state.active_provider);
+ let provider = ProviderKind::parse(&item.provider).unwrap_or_else(|| {
+ log::warn!(
+ "unknown watch-history provider '{}'; defaulting to MovieBox",
+ item.provider
+ );
+ ProviderKind::MovieBox
+ });
self.state.search_results.push(SearchResult {
id: item.subject_id.clone(),
title: item.title.clone(),
diff --git a/src/tui/config.rs b/src/tui/config.rs
index 248c8fc..097a610 100644
--- a/src/tui/config.rs
+++ b/src/tui/config.rs
@@ -45,17 +45,7 @@ pub fn load() -> Config {
config.last_update_check = v;
}
if let Some(provider) = value.get("active_provider").and_then(|v| v.as_str()) {
- config.active_provider = match provider {
- value if value == ProviderKind::MovieBox.cache_key() => ProviderKind::MovieBox,
- value if value == ProviderKind::FourKHdHub.cache_key() => ProviderKind::FourKHdHub,
- value if value == ProviderKind::BdixCircleFtp.cache_key() => {
- ProviderKind::BdixCircleFtp
- }
- value if value == ProviderKind::BdixDhakaFlix.cache_key() => {
- ProviderKind::BdixDhakaFlix
- }
- _ => config.active_provider,
- };
+ config.active_provider = ProviderKind::parse(provider).unwrap_or(config.active_provider);
}
if let Some(v) = value.get("active_theme").and_then(|v| v.as_str()) {
config.active_theme = v.to_string();