Skip to content

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

refactor: prune dead code, unify slash commands, and eliminate harmful fallbacks

Samir Hossains28cfe43cada3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b7e5322..cc44ebd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,10 @@
- Scoped `Ctrl+P` strictly to Streaming Mode for provider cycling, eliminating redundant `Ctrl+P` handling in TV and Addon modes.
- Streamlined `/config` as a direct alias for `/settings`.
+- **Command Dispatch & Cache Lookup Optimization**:
+ - Unified `ParsedCommand` and `SlashCommand` into a single canonical enum, eliminating duplicate type definitions across command dispatch and testing.
+ - Streamlined image disk cache lookups (`get_namespaced_image_cache`), eliminating 6-iteration fallback namespace scans across unrelated provider directories on cache misses.
+ - Replaced duplicate `is_termux_env` in player module with `crate::updater::artifact::is_termux_environment`.
- **Automation Workflows & Installer Hardening**:
- Added bounded execution timeouts (`timeout-minutes`) across all CI and release pipeline jobs to prevent runner hangs.
- Accelerated release preflight by eliminating redundant cross-compilation target toolchain downloads during source packaging.
@@ -26,6 +30,9 @@
- Updated macOS Homebrew installation with explicit `brew trust` step required by Homebrew 6.0+ for third-party taps.
- Streamlined quickstart section to reference in-app interactive help (`?`) and `docs/controls.md`, preventing documentation drift.
### Fixed
+- **Resilient Configuration & Accurate Metadata**:
+ - Safeguarded user TV playlists (`tv_config.json`) and HTTP addons (`addons_config.json`): replaced destructive error-swallowing deletion with timestamped `.corrupt.{timestamp}` file rotation and sanitized logging on JSON parse failures.
+ - Eliminated fabricated S01E01 fallback in addon metadata adapter, accurately reporting empty series episodes when an upstream catalog entry lacks episode records instead of injecting unplayable dummy data.
- **Update Modal Input Isolation & Event Guards**:
- Prevented keystroke hijacking: deferred blocking update modal presentation while the user is actively typing in the search bar (`InputMode::Editing`), ensuring keys (`u`, `o`, `Esc`) never trigger unintended update actions.
- Added input lock during in-flight updates (`is_updating`), consuming all keyboard and mouse events to prevent mid-upgrade process termination or disk corruption.
@@ -52,6 +59,8 @@
- Added 64-byte `PT_TLS` alignment anchor in `src/main.rs` to satisfy Android Bionic's ARM64 TLS segment minimum alignment validation.
- Added automated ELF `e_type` and `PT_TLS` validation checks to `.github/workflows/release.yml` and a post-installation execution smoke test to `install.sh`.
### Removed
+- Pruned unused legacy type aliases (`SeasonInfo`, `EpisodeInfo`, `StreamResource`, `StreamMirror`) in `src/models.rs`.
+- Removed dead `util_row` struct field from `LandingRows` in `src/tui/screens/home.rs`.
- Removed vestigial `ShowPlaybackPicker` and `ShowPlayerPicker` action variants and playback picker state fields in favor of direct compatible player dispatch.
- Removed unreferenced static screenshot assets (`assets/`), reducing repository clone size by ~1.3MB.
- **Redundant Slash Commands**:
diff --git a/docs/addons-mode.md b/docs/addons-mode.md
index 2b8eb00..71241c5 100644
--- a/docs/addons-mode.md
+++ b/docs/addons-mode.md
@@ -32,4 +32,4 @@ Addon Mode enables support for community HTTP addon manifests. You can install a
## Persistence
-Installed addons are atomically saved to `addons_config.json` inside the application config directory (`~/Library/Application Support/moviebox-tui/` on macOS, `~/.config/moviebox-tui/` on Linux, `%APPDATA%\moviebox-tui\` on Windows).
+Installed addons are atomically saved to `addons_config.json` inside the application config directory (`~/Library/Application Support/moviebox-tui/` on macOS, `~/.config/moviebox-tui/` on Linux, `%APPDATA%\moviebox-tui\` on Windows). If `addons_config.json` encounters corrupt data on disk, it is preserved and rotated to `addons_config.json.corrupt.{timestamp}` before initializing fallback defaults, preventing silent data loss.
diff --git a/docs/tv-mode.md b/docs/tv-mode.md
index 448ec7a..254a19c 100644
--- a/docs/tv-mode.md
+++ b/docs/tv-mode.md
@@ -19,7 +19,8 @@ file path, and the app parses, groups, dedupes, and lets you search and play the
- File example: `~/playlists/mine.m3u`
3. Sources persist in `tv_config.json` (under the config dir). Local file playlists are
reread directly on every TV-mode entry; remote URL playlists may reuse a recent
- cached snapshot for up to 24 hours.
+ cached snapshot for up to 24 hours. If `tv_config.json` encounters corrupt data on disk,
+ it is safely rotated to `tv_config.json.corrupt.{timestamp}` rather than deleted.
4. Highlight a source and press `d` (or `Enter`) to remove it; the list reloads.
## Parsing and search
diff --git a/src/cache.rs b/src/cache.rs
index 7d3d72f..ca831d3 100644
--- a/src/cache.rs
+++ b/src/cache.rs
@@ -457,27 +457,7 @@ fn check_image_file(path: &PathBuf) -> Option<Vec<u8>> {
pub fn get_namespaced_image_cache(namespace: &str, id: &str) -> Option<Vec<u8>> {
let path = get_namespaced_image_path(namespace, id);
- if let Some(bytes) = check_image_file(&path) {
- return Some(bytes);
- }
- let fallback_namespaces = [
- "posters",
- "moviebox",
- "fourkhdhub",
- "iptv",
- "circleftp",
- "dhakaflix",
- "addons",
- ];
- for fb in fallback_namespaces {
- if fb != namespace {
- let fb_path = get_namespaced_image_path(fb, id);
- if let Some(bytes) = check_image_file(&fb_path) {
- return Some(bytes);
- }
- }
- }
- None
+ check_image_file(&path)
}
pub fn set_namespaced_image_cache(namespace: &str, id: &str, bytes: &[u8]) {
diff --git a/src/config.rs b/src/config.rs
index 22aa7ea..a913e39 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -184,10 +184,40 @@ pub fn save(config: &Config) {
}
pub fn load_addons() -> Vec<InstalledAddon> {
- let mut list = addons_path()
- .and_then(|path| std::fs::read_to_string(path).ok())
- .and_then(|content| serde_json::from_str::<Vec<InstalledAddon>>(&content).ok())
- .unwrap_or_default();
+ let mut list = if let Some(path) = addons_path() {
+ if path.exists() {
+ match std::fs::read_to_string(&path) {
+ Ok(content) => match serde_json::from_str::<Vec<InstalledAddon>>(&content) {
+ Ok(parsed) => parsed,
+ Err(e) => {
+ let stamp = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap_or_default()
+ .as_secs();
+ let corrupt_path = path.with_extension(format!("corrupt.{stamp}"));
+ log::error!(
+ "failed to parse addons config from {} ({e}), rotating to {}",
+ crate::logging::sanitize_path(&path),
+ crate::logging::sanitize_path(&corrupt_path)
+ );
+ let _ = std::fs::rename(&path, corrupt_path);
+ Vec::new()
+ }
+ },
+ Err(e) => {
+ log::warn!(
+ "failed to read addons config from {}: {e}",
+ crate::logging::sanitize_path(&path)
+ );
+ Vec::new()
+ }
+ }
+ } else {
+ Vec::new()
+ }
+ } else {
+ Vec::new()
+ };
if !list.iter().any(|a| a.is_core()) {
list.insert(0, InstalledAddon::cinemeta_default());
diff --git a/src/models.rs b/src/models.rs
index eb54513..d4f0380 100644
--- a/src/models.rs
+++ b/src/models.rs
@@ -3,10 +3,6 @@ pub use crate::providers::models::{
ProviderKind, ProviderMediaId, Release, Season, SourceMirror, SubtitleOption,
};
-pub type SeasonInfo = Season;
-pub type EpisodeInfo = Episode;
-pub type StreamResource = Release;
-pub type StreamMirror = SourceMirror;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use std::time::{Duration, Instant};
diff --git a/src/player.rs b/src/player.rs
index 12b0b97..90a193f 100644
--- a/src/player.rs
+++ b/src/player.rs
@@ -127,13 +127,6 @@ enum AndroidOpener {
SystemAm(String),
}
-fn is_termux_env() -> bool {
- cfg!(target_os = "android")
- || std::env::var("TERMUX_VERSION").is_ok()
- || std::env::var("PREFIX").is_ok_and(|p| p.contains("com.termux"))
- || Path::new("/data/data/com.termux/files/usr").exists()
-}
-
fn android_opener() -> Option<AndroidOpener> {
static CACHED: std::sync::OnceLock<Option<AndroidOpener>> = std::sync::OnceLock::new();
CACHED
@@ -148,7 +141,7 @@ fn android_opener() -> Option<AndroidOpener> {
}
}
- let is_termux = is_termux_env();
+ let is_termux = crate::updater::artifact::is_termux_environment();
if let Ok(prefix) = std::env::var("PREFIX") {
let termux_open = format!("{prefix}/bin/termux-open");
diff --git a/src/providers/addons/adapter.rs b/src/providers/addons/adapter.rs
index 071ecb5..89bc2f6 100644
--- a/src/providers/addons/adapter.rs
+++ b/src/providers/addons/adapter.rs
@@ -95,7 +95,7 @@ pub fn meta_detail_to_media_details(detail: &MetaDetail) -> MediaDetails {
eps.sort_unstable();
}
- let mut seasons = season_map
+ let seasons = season_map
.into_iter()
.map(|(season_num, eps)| Season {
number: season_num,
@@ -110,17 +110,6 @@ pub fn meta_detail_to_media_details(detail: &MetaDetail) -> MediaDetails {
})
.collect::<Vec<_>>();
- if is_series && seasons.is_empty() {
- seasons.push(Season {
- number: 1,
- episodes: vec![Episode {
- season: 1,
- number: 1,
- title: None,
- }],
- });
- }
-
let year_raw = detail
.release_info
.as_deref()
diff --git a/src/tui/app/mod.rs b/src/tui/app/mod.rs
index ee5b14f..aee8bba 100644
--- a/src/tui/app/mod.rs
+++ b/src/tui/app/mod.rs
@@ -253,20 +253,38 @@ impl App {
let Some(path) = crate::config::tv_path() else {
return;
};
- if let Ok(content) = std::fs::read_to_string(&path)
- && let Ok(list) = serde_json::from_str::<Vec<String>>(&content)
- {
- let mut seen = std::collections::HashSet::new();
- self.state.tv_playlists = list
- .into_iter()
- .map(|item| item.trim().to_string())
- .filter(|item| !item.is_empty() && seen.insert(item.clone()))
- .collect();
- if self.state.tv_playlists.is_empty() {
- let _ = std::fs::remove_file(path);
+ if path.exists() {
+ match std::fs::read_to_string(&path) {
+ Ok(content) => match serde_json::from_str::<Vec<String>>(&content) {
+ Ok(list) => {
+ let mut seen = std::collections::HashSet::new();
+ self.state.tv_playlists = list
+ .into_iter()
+ .map(|item| item.trim().to_string())
+ .filter(|item| !item.is_empty() && seen.insert(item.clone()))
+ .collect();
+ }
+ Err(e) => {
+ let stamp = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap_or_default()
+ .as_secs();
+ let corrupt_path = path.with_extension(format!("corrupt.{stamp}"));
+ log::error!(
+ "failed to parse tv playlists from {} ({e}), rotating to {}",
+ crate::logging::sanitize_path(&path),
+ crate::logging::sanitize_path(&corrupt_path)
+ );
+ let _ = std::fs::rename(&path, corrupt_path);
+ }
+ },
+ Err(e) => {
+ log::warn!(
+ "failed to read tv playlists from {}: {e}",
+ crate::logging::sanitize_path(&path)
+ );
+ }
}
- } else if path.exists() {
- let _ = std::fs::remove_file(path);
}
}
diff --git a/src/tui/app/search.rs b/src/tui/app/search.rs
index e01dace..f9c91cf 100644
--- a/src/tui/app/search.rs
+++ b/src/tui/app/search.rs
@@ -100,13 +100,13 @@ impl App {
let will_handle = !matches!(
&parsed,
- crate::tui::commands::ParsedCommand::History if current_mode != crate::tui::state::AppMode::Tv
+ crate::tui::commands::SlashCommand::History if current_mode != crate::tui::state::AppMode::Tv
) && !matches!(
&parsed,
- crate::tui::commands::ParsedCommand::Favorites if current_mode != crate::tui::state::AppMode::Tv
+ crate::tui::commands::SlashCommand::Favorites if current_mode != crate::tui::state::AppMode::Tv
) && !matches!(
&parsed,
- crate::tui::commands::ParsedCommand::List if current_mode == crate::tui::state::AppMode::Tv
+ crate::tui::commands::SlashCommand::List if current_mode == crate::tui::state::AppMode::Tv
);
if will_handle {
@@ -115,11 +115,11 @@ impl App {
}
match parsed {
- crate::tui::commands::ParsedCommand::Exit => {
+ crate::tui::commands::SlashCommand::Exit => {
self.action_sender.send(Action::Quit).ok();
Some(true)
}
- crate::tui::commands::ParsedCommand::Settings => {
+ crate::tui::commands::SlashCommand::Settings => {
if trimmed.eq_ignore_ascii_case("/config") {
if self.state.is_tv_mode {
self.action_sender.send(Action::ShowTvConfig).ok();
@@ -132,20 +132,20 @@ impl App {
self.action_sender.send(Action::ToggleSettingsPopup).ok();
Some(true)
}
- crate::tui::commands::ParsedCommand::Clear => {
+ crate::tui::commands::SlashCommand::Clear => {
self.state.clear_search_state();
self.state.set_status_default("Search cleared.");
Some(true)
}
- crate::tui::commands::ParsedCommand::Help => {
+ crate::tui::commands::SlashCommand::Help => {
self.action_sender.send(Action::ToggleHelp).ok();
Some(true)
}
- crate::tui::commands::ParsedCommand::Theme => {
+ crate::tui::commands::SlashCommand::Theme => {
self.action_sender.send(Action::ToggleThemePopup).ok();
Some(true)
}
- crate::tui::commands::ParsedCommand::Browse => {
+ crate::tui::commands::SlashCommand::Browse => {
if current_mode == crate::tui::state::AppMode::Tv {
self.state.notify(
NotificationKind::Info,
@@ -157,7 +157,7 @@ impl App {
}
Some(true)
}
- crate::tui::commands::ParsedCommand::History => {
+ crate::tui::commands::SlashCommand::History => {
if current_mode == crate::tui::state::AppMode::Tv {
self.state.notify(
NotificationKind::Info,
@@ -169,7 +169,7 @@ impl App {
None
}
}
- crate::tui::commands::ParsedCommand::Favorites => {
+ crate::tui::commands::SlashCommand::Favorites => {
if current_mode == crate::tui::state::AppMode::Tv {
self.state.notify(
NotificationKind::Info,
@@ -181,7 +181,7 @@ impl App {
None
}
}
- crate::tui::commands::ParsedCommand::List => {
+ crate::tui::commands::SlashCommand::List => {
if current_mode == crate::tui::state::AppMode::Tv {
self.apply_tv_search_results(query, lower_query);
} else {
diff --git a/src/tui/commands.rs b/src/tui/commands.rs
index d72b645..5ec6d8e 100644
--- a/src/tui/commands.rs
+++ b/src/tui/commands.rs
@@ -13,19 +13,6 @@ pub enum SlashCommand {
Exit,
}
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub enum ParsedCommand {
- Settings,
- Browse,
- History,
- Favorites,
- Theme,
- Clear,
- Help,
- List,
- Exit,
-}
-
impl SlashCommand {
pub const ALL: [Self; 9] = [
Self::Settings,
@@ -153,7 +140,7 @@ impl SlashCommand {
}
}
- pub fn parse(input: &str) -> Option<ParsedCommand> {
+ pub fn parse(input: &str) -> Option<Self> {
let trimmed = input.trim();
if !trimmed.starts_with('/') {
return None;
@@ -163,17 +150,15 @@ impl SlashCommand {
let command_name = parts.next()?;
match command_name.to_ascii_lowercase().as_str() {
- "/settings" | "/config" | "/pref" | "/preferences" | "/options" => {
- Some(ParsedCommand::Settings)
- }
- "/browse" => Some(ParsedCommand::Browse),
- "/history" => Some(ParsedCommand::History),
- "/favorites" => Some(ParsedCommand::Favorites),
- "/theme" => Some(ParsedCommand::Theme),
- "/clear" => Some(ParsedCommand::Clear),
- "/help" | "/?" => Some(ParsedCommand::Help),
- "/list" => Some(ParsedCommand::List),
- "/exit" | "/quit" | "/q" => Some(ParsedCommand::Exit),
+ "/settings" | "/config" | "/pref" | "/preferences" | "/options" => Some(Self::Settings),
+ "/browse" => Some(Self::Browse),
+ "/history" => Some(Self::History),
+ "/favorites" => Some(Self::Favorites),
+ "/theme" => Some(Self::Theme),
+ "/clear" => Some(Self::Clear),
+ "/help" | "/?" => Some(Self::Help),
+ "/list" => Some(Self::List),
+ "/exit" | "/quit" | "/q" => Some(Self::Exit),
_ => None,
}
}
@@ -226,7 +211,7 @@ mod tests {
let state = AppState::default();
assert_eq!(
SlashCommand::parse("/favorites"),
- Some(ParsedCommand::Favorites)
+ Some(SlashCommand::Favorites)
);
assert!(SlashCommand::Favorites.is_available(&state));
assert_eq!(SlashCommand::Favorites.name(), "/favorites");
@@ -246,46 +231,39 @@ mod tests {
let state = AppState::default();
assert_eq!(SlashCommand::ALL.len(), 9);
assert_eq!(SlashCommand::PRIMARY.len(), 7);
- assert_eq!(SlashCommand::parse("/exit"), Some(ParsedCommand::Exit));
- assert_eq!(SlashCommand::parse("/quit"), Some(ParsedCommand::Exit));
- assert_eq!(SlashCommand::parse("/q"), Some(ParsedCommand::Exit));
+ assert_eq!(SlashCommand::parse("/exit"), Some(SlashCommand::Exit));
+ assert_eq!(SlashCommand::parse("/quit"), Some(SlashCommand::Exit));
+ assert_eq!(SlashCommand::parse("/q"), Some(SlashCommand::Exit));
assert!(SlashCommand::Exit.is_available(&state));
assert_eq!(SlashCommand::Exit.name(), "/exit");
- assert_eq!(SlashCommand::parse("/clear"), Some(ParsedCommand::Clear));
+ assert_eq!(SlashCommand::parse("/clear"), Some(SlashCommand::Clear));
assert!(SlashCommand::Clear.is_available(&state));
assert_eq!(SlashCommand::Clear.name(), "/clear");
- assert_eq!(SlashCommand::parse("/help"), Some(ParsedCommand::Help));
- assert_eq!(SlashCommand::parse("/?"), Some(ParsedCommand::Help));
+ assert_eq!(SlashCommand::parse("/help"), Some(SlashCommand::Help));
+ assert_eq!(SlashCommand::parse("/?"), Some(SlashCommand::Help));
assert!(SlashCommand::Help.is_available(&state));
assert_eq!(SlashCommand::Help.name(), "/help");
assert_eq!(
SlashCommand::parse("/settings"),
- Some(ParsedCommand::Settings)
- );
- assert_eq!(
- SlashCommand::parse("/config"),
- Some(ParsedCommand::Settings)
+ Some(SlashCommand::Settings)
);
- assert_eq!(SlashCommand::parse("/pref"), Some(ParsedCommand::Settings));
+ assert_eq!(SlashCommand::parse("/config"), Some(SlashCommand::Settings));
+ assert_eq!(SlashCommand::parse("/pref"), Some(SlashCommand::Settings));
assert_eq!(
SlashCommand::parse("/preferences"),
- Some(ParsedCommand::Settings)
+ Some(SlashCommand::Settings)
);
assert_eq!(
SlashCommand::parse("/options"),
- Some(ParsedCommand::Settings)
- );
-
- assert_eq!(SlashCommand::parse("/list"), Some(ParsedCommand::List));
- assert_eq!(SlashCommand::parse("/browse"), Some(ParsedCommand::Browse));
- assert_eq!(
- SlashCommand::parse("/history"),
- Some(ParsedCommand::History)
+ Some(SlashCommand::Settings)
);
+ assert_eq!(SlashCommand::parse("/list"), Some(SlashCommand::List));
+ assert_eq!(SlashCommand::parse("/browse"), Some(SlashCommand::Browse));
+ assert_eq!(SlashCommand::parse("/history"), Some(SlashCommand::History));
assert_eq!(SlashCommand::parse("/toggle-tv"), None);
assert_eq!(SlashCommand::parse("/enable-tv"), None);
assert_eq!(SlashCommand::parse("/disable-tv"), None);
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index 2986cc7..7809468 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -160,8 +160,6 @@ pub struct LandingRows {
pub search: usize,
pub favorites: usize,
pub mode_row: usize,
- #[allow(dead_code)]
- pub util_row: Option<usize>,
pub logo_width: u16,
}
@@ -207,7 +205,6 @@ pub fn landing_split(
search: 4,
favorites: 6,
mode_row: 7,
- util_row: None,
logo_width,
},
)
diff --git a/tests/settings_hub.rs b/tests/settings_hub.rs
index f13fdee..3aec2d1 100644
--- a/tests/settings_hub.rs
+++ b/tests/settings_hub.rs
@@ -4,7 +4,7 @@ use moviebox_tui::{
tui::{
action::Action,
app::App,
- commands::{ParsedCommand, SlashCommand},
+ commands::SlashCommand,
state::{AppState, SettingsCategory, settings_player_label},
widgets::settings::{
category_tab_rects, settings_category_tab_at, settings_row_at, settings_row_rects,
@@ -20,23 +20,20 @@ fn test_settings_command_parsing_and_aliases() {
assert_eq!(SlashCommand::Settings.name(), "/settings");
assert_eq!(
SlashCommand::parse("/settings"),
- Some(ParsedCommand::Settings)
+ Some(SlashCommand::Settings)
);
- assert_eq!(SlashCommand::parse("/pref"), Some(ParsedCommand::Settings));
+ assert_eq!(SlashCommand::parse("/pref"), Some(SlashCommand::Settings));
assert_eq!(
SlashCommand::parse("/preferences"),
- Some(ParsedCommand::Settings)
+ Some(SlashCommand::Settings)
);
assert_eq!(
SlashCommand::parse("/options"),
- Some(ParsedCommand::Settings)
+ Some(SlashCommand::Settings)
);
- assert_eq!(
- SlashCommand::parse("/config"),
- Some(ParsedCommand::Settings)
- );
- assert_eq!(SlashCommand::parse("/help"), Some(ParsedCommand::Help));
- assert_eq!(SlashCommand::parse("/?"), Some(ParsedCommand::Help));
+ assert_eq!(SlashCommand::parse("/config"), Some(SlashCommand::Settings));
+ assert_eq!(SlashCommand::parse("/help"), Some(SlashCommand::Help));
+ assert_eq!(SlashCommand::parse("/?"), Some(SlashCommand::Help));
let suggestions = SlashCommand::suggest(&state, "/");
assert_eq!(