Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
feat(player): support custom player executable paths and stabilize modal table alignment
Samir Hossainsd385ab895bd6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5c2d769..319b5e5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,7 +11,13 @@- **MovieBox Stream Resolution Picker & Adaptive Bitrate Capping**:- Decomposed multi-resolution DASH streams in `src/providers/moviebox/adapt.rs` into individual resolution stream rows (`1080p`, `720p`, `480p`, etc.) sorted by quality, enabling direct stream selection from the details screen.- Threaded resolution constraints to player command builders (`src/player.rs` and `src/tui/app/playback.rs`), injecting `--ytdl-format="bestvideo[height<=H]+bestaudio/best"` for `mpv`/`IINA` and `--adaptive-maxheight=H` for `VLC` to prevent playback buffering on slow connections.+- **Custom Player Executable Path Configuration**:+ - Added `vlc_path`, `mpv_path`, and `iina_path` fields to `Config` in `src/config.rs` and `src/tui/state.rs`.+ - Updated player resolution in `src/player.rs` to fall back to persisted configuration files (`config.json`) when custom player paths are not passed via environment variables (`MOVIEBOX_VLC_PATH`, `MOVIEBOX_MPV_PATH`, `MOVIEBOX_IINA_PATH`), allowing users to configure non-standard or portable player executables (e.g. `D:\PortableApps\VLC\vlc.exe`).+ - Added `clear_cached_player_executables` in `src/player.rs` to safely invalidate in-memory static player path caches when player configurations update.### Fixed+- **Streams Table Column Alignment Under Modal Backdrops**:+ - Unified `pane_styles` highlight symbol to `""` during modal active states in `src/tui/screens/details.rs`, preventing Ratatui `Table` from reserving a 2-character highlight prefix column that shifted table headers and columns to the right whenever a popup (subtitles, player picker, help) opened.- **In-App Updater Streaming Timeout & Chunk Retry Recovery**:- Removed the static 30-second total request deadline from the release binary download client in `src/updater/check.rs`, preventing mid-transfer decode aborts (`download chunk stream error: error decoding response body`) on slow or high-latency network connections.- Added mid-stream chunk failure recovery in `src/updater/download.rs` with automatic temporary file cleanup, exponential backoff, and retry loop up to 3 attempts.diff --git a/docs/config.md b/docs/config.mdindex 383ebc4..0001fa3 100644--- a/docs/config.md+++ b/docs/config.md@@ -31,8 +31,20 @@ All settings in `config.json` can be configured interactively inside the applica- **Content Modes**: Toggle Streaming Mode, open the Streaming Sources selector (to enable/disable MovieBox, 4KHDHub, CircleFTP, DhakaFlix), and toggle Live TV.- **Appearance**: Open the visual theme swatch picker to select among 6 built-in color themes.- **Maintenance**: Purge disk cache, clear watch history, query GitHub for release updates, open GitHub repository, and trigger a manual local network BDIX re-probe.-## Other persisted files+## Persisted configuration (`config.json`)++The central configuration file is located at `~/.config/moviebox-tui/config.json` (or `%APPDATA%\MovieBox-Tui\config.json` on Windows). In addition to settings toggled via `/settings`, custom player binary paths can be directly set here:+```json+{+ "default_player": "vlc",+ "vlc_path": "D:\\PortableApps\\VLC\\vlc.exe",+ "mpv_path": "C:\\Program Files\\mpv\\mpv.exe",+ "iina_path": "/Applications/IINA.app/Contents/MacOS/iina-cli"+}+```++## Other persisted files- `addons_config.json` — list of installed HTTP addons in the config directory (see [addons-mode.md](addons-mode.md)).- `tv_config.json` — list of M3U playlist sources in the config directory (see [tv-mode.md](tv-mode.md)).- `history.json` — watch history in the system data directory (`dirs::data_dir()/moviebox-tui/`).diff --git a/src/config.rs b/src/config.rsindex 24bf564..955c915 100644--- a/src/config.rs+++ b/src/config.rs@@ -23,6 +23,9 @@ pub struct Config {pub addons_enabled: bool,pub default_player: Option<String>,pub download_dir: Option<String>,+ pub vlc_path: Option<String>,+ pub mpv_path: Option<String>,+ pub iina_path: Option<String>,}impl Default for Config {fn default() -> Self {@@ -43,6 +46,9 @@ impl Default for Config {addons_enabled: false,default_player: None,download_dir: None,+ vlc_path: None,+ mpv_path: None,+ iina_path: None,}}}diff --git a/src/player.rs b/src/player.rsindex 8980205..bf625c6 100644--- a/src/player.rs+++ b/src/player.rs@@ -539,10 +539,11 @@ fn probe_iina_resolution() -> Option<IinaResolution> {}#[cfg(target_os = "macos")]-fn iina_resolution() -> Option<IinaResolution> {- static CACHED: std::sync::RwLock<Option<IinaResolution>> = std::sync::RwLock::new(None);+static IINA_CACHED: std::sync::RwLock<Option<IinaResolution>> = std::sync::RwLock::new(None);- if let Ok(guard) = CACHED.read() {+#[cfg(target_os = "macos")]+fn iina_resolution() -> Option<IinaResolution> {+ if let Ok(guard) = IINA_CACHED.read() {if let Some(res) = &*guard {return Some(res.clone());}@@ -550,7 +551,7 @@ fn iina_resolution() -> Option<IinaResolution> {let detected = probe_iina_resolution();if let Some(res) = &detected {- if let Ok(mut guard) = CACHED.write() {+ if let Ok(mut guard) = IINA_CACHED.write() {*guard = Some(res.clone());}}@@ -1250,10 +1251,11 @@ fn probe_vlc() -> Option<String> {)}-fn mpv_executable() -> Option<String> {- static CACHED: std::sync::RwLock<Option<String>> = std::sync::RwLock::new(None);+static MPV_CACHED: std::sync::RwLock<Option<String>> = std::sync::RwLock::new(None);+static VLC_CACHED: std::sync::RwLock<Option<String>> = std::sync::RwLock::new(None);- if let Ok(guard) = CACHED.read() {+fn mpv_executable() -> Option<String> {+ if let Ok(guard) = MPV_CACHED.read() {if let Some(path) = &*guard {if path.starts_with("flatpak run ") || Path::new(path).is_file() {return Some(path.clone());@@ -1263,7 +1265,7 @@ fn mpv_executable() -> Option<String> {let detected = probe_mpv();if let Some(path) = &detected {- if let Ok(mut guard) = CACHED.write() {+ if let Ok(mut guard) = MPV_CACHED.write() {*guard = Some(path.clone());}}@@ -1271,9 +1273,7 @@ fn mpv_executable() -> Option<String> {}fn vlc_executable() -> Option<String> {- static CACHED: std::sync::RwLock<Option<String>> = std::sync::RwLock::new(None);-- if let Ok(guard) = CACHED.read() {+ if let Ok(guard) = VLC_CACHED.read() {if let Some(path) = &*guard {if path.starts_with("flatpak run ") || Path::new(path).is_file() {return Some(path.clone());@@ -1283,12 +1283,24 @@ fn vlc_executable() -> Option<String> {let detected = probe_vlc();if let Some(path) = &detected {- if let Ok(mut guard) = CACHED.write() {+ if let Ok(mut guard) = VLC_CACHED.write() {*guard = Some(path.clone());}}detected}+pub fn clear_cached_player_executables() {+ if let Ok(mut guard) = MPV_CACHED.write() {+ *guard = None;+ }+ if let Ok(mut guard) = VLC_CACHED.write() {+ *guard = None;+ }+ #[cfg(target_os = "macos")]+ if let Ok(mut guard) = IINA_CACHED.write() {+ *guard = None;+ }+}#[cfg(target_os = "macos")]fn iina_available() -> bool {@@ -1333,8 +1345,16 @@ fn flatpak_executable(app_id: &str) -> Option<String> {}fn configured_executable(variable: &str) -> Option<String> {- let val = std::env::var(variable).ok()?;- let trimmed = val.trim();+ let raw = std::env::var(variable).ok().or_else(|| {+ let cfg = crate::config::load();+ match variable {+ "MOVIEBOX_VLC_PATH" => cfg.vlc_path,+ "MOVIEBOX_MPV_PATH" => cfg.mpv_path,+ "MOVIEBOX_IINA_PATH" => cfg.iina_path,+ _ => None,+ }+ })?;+ let trimmed = raw.trim();if trimmed.is_empty() {return None;}@@ -1591,8 +1611,11 @@ mod tests {assert!(args.contains(&"--http-header-fields=Cookie: session=abc, token=123".to_string()));assert!(args.contains(&"--http-header-fields=Accept: text/html, */*".to_string()));}+ static ENV_MUTEX: std::sync::Mutex<()> = std::sync::Mutex::new(());+#[test]fn test_android_intent_commands_fallback_order() {+ let _lock = ENV_MUTEX.lock().unwrap();let temp_dir =std::env::temp_dir().join(format!("termux_fallback_test_{}", std::process::id()));let bin_dir = temp_dir.join("bin");@@ -1690,7 +1713,7 @@ mod tests {std::fs::create_dir_all(&bin_dir).unwrap();let termux_am = bin_dir.join("termux-am");std::fs::write(&termux_am, "#!/bin/sh\nexit 0").unwrap();-+ let _lock = ENV_MUTEX.lock().unwrap();unsafe {std::env::set_var("TERMUX_VERSION", "0.118.0");std::env::set_var("PREFIX", temp_dir.to_str().unwrap());@@ -1807,4 +1830,13 @@ mod tests {fn test_create_no_window_constant() {assert_eq!(CREATE_NO_WINDOW, 0x0800_0000);}+ #[test]+ fn test_configured_executable_fallback_to_config() {+ clear_cached_player_executables();+ let _cfg = crate::config::Config {+ vlc_path: Some("/nonexistent/vlc.exe".to_string()),+ ..Default::default()+ };+ assert!(configured_executable("MOVIEBOX_VLC_PATH").is_none());+ }}diff --git a/src/tui/app/mod.rs b/src/tui/app/mod.rsindex ea9ce78..d2bd947 100644--- a/src/tui/app/mod.rs+++ b/src/tui/app/mod.rs@@ -157,6 +157,9 @@ impl App {}state.active_theme_kind = config.active_theme;state.default_player = config.default_player;+ state.vlc_path = config.vlc_path;+ state.mpv_path = config.mpv_path;+ state.iina_path = config.iina_path;state.download_dir = config.download_dir.map(std::path::PathBuf::from);state.installed_addons = crate::config::load_addons();@@ -253,6 +256,9 @@ impl App {.download_dir.as_ref().map(|p| p.to_string_lossy().to_string()),+ vlc_path: self.state.vlc_path.clone(),+ mpv_path: self.state.mpv_path.clone(),+ iina_path: self.state.iina_path.clone(),};crate::tui::config::save(&config);}diff --git a/src/tui/app/playback.rs b/src/tui/app/playback.rsindex d4ba63b..b923f42 100644--- a/src/tui/app/playback.rs+++ b/src/tui/app/playback.rs@@ -129,13 +129,30 @@ impl App {PlaybackResolution::NoPlayersInstalled => {self.state.is_resolving_playback = false;self.state.pending_playback_source = None;- let message = if crate::updater::artifact::is_termux_environment() {- "Run 'pkg install termux-tools' and install an Android video player."+ let custom_path = match self.state.default_player.as_deref() {+ Some("vlc") => self.state.vlc_path.as_deref(),+ Some("mpv") => self.state.mpv_path.as_deref(),+ Some("iina") => self.state.iina_path.as_deref(),+ _ => None,+ };+ let (title, message) = if let Some(bad_path) = custom_path {+ (+ "Invalid Player Path",+ format!("Player path not found: {bad_path}"),+ )+ } else if crate::updater::artifact::is_termux_environment() {+ (+ "No Media Player Found",+ "Run 'pkg install termux-tools' and install an Android video player."+ .to_string(),+ )} else {- "Install mpv, IINA, or VLC to enable video playback."+ (+ "No Media Player Found",+ "Install mpv, IINA, or VLC to enable video playback.".to_string(),+ )};- self.state- .notify(NotificationKind::Error, "No Media Player Found", message);+ self.state.notify(NotificationKind::Error, title, message);}}}@@ -1325,6 +1342,30 @@ mod tests {);}#[tokio::test]+ async fn test_dispatch_playback_notifies_bad_player_path() {+ let mut app = crate::tui::app::App::new();+ app.state.available_players.clear();+ app.state.default_player = Some("vlc".to_string());+ app.state.vlc_path = Some("D:\\PortableApps\\VLC\\vlc.exe".to_string());+ let source = crate::providers::models::PlaybackSource {+ provider: crate::providers::models::ProviderKind::MovieBox,+ url: "https://example.com/video.mp4".to_string(),+ headers: vec![],+ subtitle: None,+ source_label: "Direct".to_string(),+ max_height: None,+ };++ app.dispatch_playback_or_notify(source);++ let notif = app.state.notifications.back().expect("notification pushed");+ assert_eq!(notif.title, "Invalid Player Path");+ assert_eq!(+ notif.message,+ "Player path not found: D:\\PortableApps\\VLC\\vlc.exe"+ );+ }+ #[tokio::test]async fn test_explicit_player_incompatible_does_not_launch_alternative() {let mut app = crate::tui::app::App::new();app.state.available_players = vec![diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rsindex 7eb9cb2..1172852 100644--- a/src/tui/screens/details.rs+++ b/src/tui/screens/details.rs@@ -1831,7 +1831,7 @@ fn pane_styles(theme: &Theme,) -> (Style, Style, Style, &'static str) {if modal_active {- (theme.muted, theme.muted, theme.muted, " ")+ (theme.muted, theme.muted, theme.muted, "")} else {(if focused {@@ -2505,6 +2505,88 @@ mod tests {"Streams table header should not have selection background");}+ #[test]+ fn test_streams_table_alignment_invariant_under_modal() {+ let backend = ratatui::backend::TestBackend::new(120, 30);+ let mut terminal = ratatui::Terminal::new(backend).unwrap();+ let mut state = AppState {+ selected_details: Some(crate::providers::models::MediaDetails {+ id: crate::providers::models::ProviderMediaId {+ provider: crate::providers::models::ProviderKind::MovieBox,+ value: "m1".to_string(),+ },+ title: "Movie".to_string(),+ media_type: crate::providers::models::MediaType::Movie,+ year: Some("2024".to_string()),+ description: None,+ tagline: None,+ imdb_rating: None,+ director: None,+ stars: None,+ prints: None,+ audios: None,+ poster_url: None,+ duration: None,+ genres: vec![],+ seasons: vec![],+ dubs: vec![],+ }),+ selected_resources: vec![crate::providers::models::Release {+ provider: crate::providers::models::ProviderKind::MovieBox,+ filename: "Movie.1080p.mkv".to_string(),+ quality: Some("1080p".to_string()),+ codec: Some("HEVC".to_string()),+ language: None,+ size_bytes: Some(1_000_000_000),+ season: None,+ episode: None,+ mirrors: vec![],+ resource_id: None,+ }],+ details_pane: crate::tui::state::DetailsPane::Streams,+ ..Default::default()+ };+ state.resource_list_state.select(Some(0));+ let theme = Theme::mocha();++ terminal+ .draw(|frame| {+ draw(frame, frame.area(), &mut state, &theme);+ })+ .unwrap();++ let buffer_normal = terminal.backend().buffer().clone();+ let normal_header_x = (0..buffer_normal.area.height)+ .find_map(|y| {+ let row: String = (0..buffer_normal.area.width)+ .map(|x| buffer_normal[(x, y)].symbol())+ .collect();+ row.find("RES")+ })+ .expect("header found in normal state");++ state.subtitle_popup = true;+ terminal+ .draw(|frame| {+ draw(frame, frame.area(), &mut state, &theme);+ })+ .unwrap();++ let buffer_modal = terminal.backend().buffer().clone();+ let modal_header_x = (0..buffer_modal.area.height)+ .find_map(|y| {+ let row: String = (0..buffer_modal.area.width)+ .map(|x| buffer_modal[(x, y)].symbol())+ .collect();+ row.find("RES")+ })+ .expect("header found in modal state");++ assert_eq!(+ normal_header_x, modal_header_x,+ "Streams table column alignment must not shift when a modal opens"+ );+ }#[test]fn test_details_error_state_rendering() {diff --git a/src/tui/state.rs b/src/tui/state.rsindex 705ac5d..8b5ca06 100644--- a/src/tui/state.rs+++ b/src/tui/state.rs@@ -256,6 +256,9 @@ pub struct AppState {pub settings_player_picker: bool,pub available_players: Vec<PlayerKind>,pub default_player: Option<String>,+ pub vlc_path: Option<String>,+ pub mpv_path: Option<String>,+ pub iina_path: Option<String>,pub is_loading: bool,pub is_resolving_playback: bool,pub has_streams_settled: bool,@@ -334,6 +337,7 @@ impl Default for AppState {active_provider: ProviderKind::MovieBox,provider_generation: 0,active_screen: Screen::Home,+ dirty: true,input_mode: InputMode::Normal,search_query: crate::tui::text::TextInputBuffer::new(),last_suggest_query: String::new(),@@ -427,7 +431,9 @@ impl Default for AppState {settings_player_picker: false,available_players: Vec::new(),default_player: None,- dirty: true,+ vlc_path: None,+ mpv_path: None,+ iina_path: None,is_loading: false,is_resolving_playback: false,has_streams_settled: false,