Skip to content

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

fix(playback): prevent silent player override and eliminate graphics probe leak

Samir Hossains6351c64660cd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e1af700..789ff4a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,20 @@
# Changelog
+## [Unreleased]
+
+### Fixed
+- **Direct Playback & Header Compatibility**:
+ - Eliminated vestigial in-stream "Open with" popup that blocked playback when only VLC was installed, routing playback directly to the preferred compatible player.
+ - Prevented silent player overrides: when a user explicitly selects a default player (e.g. VLC) that cannot satisfy stream authentication headers (e.g. MovieBox signed DASH manifests), the app now halts playback and warns the user with actionable detected alternatives instead of silently launching an unselected player.
+ - Added structured `PlaybackResolution` engine with dynamic context-aware notifications across playback resolution, download operations, and `/download-dir` commands.
+ - Expanded Windows `mpv.exe` detection across winget (`MPV Player`, `mpv-player`), portable `C:\mpv`, and user directory paths.
+
+- **Terminal Graphics Probe Leak**:
+ - Prevented raw Kitty APC escape sequence leak (`Gi=31...`) on macOS `Terminal.app` and legacy non-graphics consoles by skipping graphics stdio probes.
+ - Removed unsafe mid-session stdio graphics re-probing on `FocusChange` events.
+### Removed
+- Removed vestigial `ShowPlaybackPicker` and `ShowPlayerPicker` action variants and playback picker state fields in favor of direct compatible player dispatch.
+
## [0.1.15] - 2026-09-03
### Added
diff --git a/docs/controls.md b/docs/controls.md
index 8c6331c..deef389 100644
--- a/docs/controls.md
+++ b/docs/controls.md
@@ -43,7 +43,7 @@ Text editing across Search, TV Playlist Manager, and Addon Manager uses a unifie
## Modal Dialogs & Pickers
-All popup dialogs (Theme picker, Browse categories, Player picker, TV Manager, Addon Manager, Download Confirmation) support standard keyboard controls:
+All popup dialogs (Theme picker, Browse categories, Settings Media Player picker, TV Manager, Addon Manager, Download Confirmation) support standard keyboard controls:
- **`↑` / `↓` / `k` / `j`**: Move selection up / down by one item (vim keys `k`/`j` supported in pickers such as `/theme`).
- **`Home` / `End`**: Jump immediately to the first or last item in the list.
diff --git a/docs/cross-platform.md b/docs/cross-platform.md
index 0e0dc77..b7ab80e 100644
--- a/docs/cross-platform.md
+++ b/docs/cross-platform.md
@@ -20,8 +20,9 @@ the release checks in [`release-checklist.md`](release-checklist.md).
## Terminal capabilities
The app probes the terminal at startup via `ratatui_image` (400ms cap,
-off the UI thread; retried on focus regain if the first probe found
-nothing, and on demand via `/probe`):
+off the UI thread; on-demand via `/probe`). Non-graphics terminals (e.g.
+macOS `Apple_Terminal`, legacy Windows `conhost`, and `TERM=dumb/linux/cygwin`)
+are skipped to prevent escape sequence probe leakage (`Gi=31...`):
- **Poster rendering**: Sixel, Kitty, and iTerm2 protocols where the probe
detects them. Terminals that report kitty/sixel capability but no cell
diff --git a/docs/players.md b/docs/players.md
index 420b1ff..8f84a58 100644
--- a/docs/players.md
+++ b/docs/players.md
@@ -9,12 +9,12 @@ builds the exact command; `tui/app/playback.rs` spawns it.
- macOS: IINA (if present), then mpv, then VLC (probing `/Applications`, `~/Applications`, Homebrew `/opt/homebrew/bin`, and MacPorts).
- Linux: mpv, then VLC (probing Native `$PATH`, Flathub/Flatpak user & system exports `org.videolan.VLC` / `io.mpv.Mpv`, Snap `/snap/bin/*`, and `flatpak run`).
-- Windows: mpv, then VLC (probing `Program Files`, `LOCALAPPDATA\Programs`, `Microsoft\WindowsApps`, Scoop `scoop\shims`, and Chocolatey).
+- Windows: mpv, then VLC (probing `Program Files` including WinGet `MPV Player` and `mpv-player`, `LOCALAPPDATA\Programs`, `WinGet\Links`, portable `C:\mpv`, Scoop `scoop\shims`, and Chocolatey).
- Android/Termux: `mpv` (if installed via `pkg install mpv`), or Android intent chooser (`termux-open`, `termux-open-url`, or `termux-am`).
Resolution runs once at startup and is cached (`OnceLock`). A preferred player can be
forced via `MOVIEBOX_PLAYER` env or `default_player` in config (e.g. `mpv`, `iina`,
-`vlc`, `android`), which reorders the list. The media player picker in the Settings Hub (`/settings`) lists every detected player on your system and saves your selection to `config.json` unless overridden by `MOVIEBOX_PLAYER`.
+`vlc`, `android`), which reorders the list. The media player picker in the Settings Hub (`/settings`) lists every detected player on your system and saves your selection to `config.json` unless overridden by `MOVIEBOX_PLAYER`. Playback launches directly using the preferred compatible player without intermediate modal dialogs.
## Command construction
@@ -31,11 +31,10 @@ by the image picker, then clamped to a fixed range.
## Headers
Playback sources (for example 4KHD and MovieBox) may carry `Referer`/`User-Agent` headers.
-MovieBox sources forward the client's spoofed Android/Cronet `User-Agent` to satisfy CDN
-stream requirements. mpv/IINA send them via `http-header-fields` (`--http-header-fields=...`
-or `--mpv-http-header-fields=...`), while VLC maps them to `--http-referrer` / `--http-user-agent`.
-The `supports_headers` gate in `app/playback.rs` warns when a player cannot satisfy a source's headers.
-
+MovieBox DASH streams additionally carry signed `Cookie` headers for CloudFront authentication.
+mpv/IINA send them via `http-header-fields` (`--http-header-fields=...` or `--mpv-http-header-fields=...`),
+while VLC maps them to `--http-referrer` / `--http-user-agent`.
+The `supports_headers` gate in `app/playback.rs` validates whether a player can satisfy required stream headers. MovieBox-TUI strictly respects the user's configured default player: if the chosen player cannot satisfy a stream's headers (such as VLC attempting to play signed MovieBox DASH manifests with cookie requirements), playback will not silently fall back to an alternative player. Instead, an explicit warning notification informs the user of the exact incompatibility and lists available compatible alternatives (e.g. mpv) or the option to switch providers with `Ctrl+P`.
## Subtitles
- mpv receives the remote subtitle URL directly (`--sub-file=<url>`); mpv fetches it
diff --git a/src/player.rs b/src/player.rs
index 9fb1eb5..abfc3bf 100644
--- a/src/player.rs
+++ b/src/player.rs
@@ -479,9 +479,13 @@ fn mpv_executable() -> Option<String> {
#[cfg(target_os = "windows")]
{
candidates.push(r"C:\Program Files\mpv\mpv.exe".to_string());
+ candidates.push(r"C:\Program Files\MPV Player\mpv.exe".to_string());
+ candidates.push(r"C:\Program Files\mpv-player\mpv.exe".to_string());
candidates.push(r"C:\Program Files (x86)\mpv\mpv.exe".to_string());
+ candidates.push(r"C:\mpv\mpv.exe".to_string());
if let Ok(local) = std::env::var("LOCALAPPDATA") {
candidates.push(format!(r"{local}\Programs\mpv\mpv.exe"));
+ candidates.push(format!(r"{local}\Microsoft\WinGet\Links\mpv.exe"));
}
if let Ok(appdata) = std::env::var("APPDATA") {
candidates.push(format!(r"{appdata}\mpv\mpv.exe"));
@@ -492,6 +496,8 @@ fn mpv_executable() -> Option<String> {
.to_string_lossy()
.into_owned(),
);
+ candidates.push(home.join(r"mpv\mpv.exe").to_string_lossy().into_owned());
+ candidates.push(home.join(r"bin\mpv.exe").to_string_lossy().into_owned());
}
candidates.push(r"C:\ProgramData\chocolatey\bin\mpv.exe".to_string());
}
diff --git a/src/tui/action.rs b/src/tui/action.rs
index b9c39b9..f65d9b3 100644
--- a/src/tui/action.rs
+++ b/src/tui/action.rs
@@ -1,8 +1,6 @@
#[derive(Debug, Clone)]
pub enum Action {
FocusChange,
- ShowPlayerPicker(String, Option<String>),
- ShowPlaybackPicker(crate::providers::models::PlaybackSource),
LaunchPlayer(crate::tui::state::PlayerKind, String, Option<String>),
Tick,
Key(crossterm::event::KeyEvent),
@@ -146,6 +144,7 @@ pub enum Action {
crate::tui::state::PlayerKind,
crate::providers::models::PlaybackSource,
),
+ DispatchPlayback(crate::providers::models::PlaybackSource),
MarkWatched(crate::history::WatchHistoryItem),
UpdateProgress {
item: crate::history::WatchHistoryItem,
diff --git a/src/tui/app/download.rs b/src/tui/app/download.rs
index 13db116..a10e8bd 100644
--- a/src/tui/app/download.rs
+++ b/src/tui/app/download.rs
@@ -116,8 +116,8 @@ impl App {
.store(false, std::sync::atomic::Ordering::SeqCst);
self.state.notify(
NotificationKind::Info,
- "Download started",
- "Partial data will be preserved.",
+ "Download Started",
+ format!("Downloading {base_name}.{extension} (resumable)."),
);
let cancel = self.state.cancel_download.clone();
@@ -304,8 +304,12 @@ impl App {
};
self.state.notify(
NotificationKind::Info,
- "Preparing download",
- "Resolving the selected mirror.",
+ "Preparing Download",
+ format!(
+ "Resolving {} from {}...",
+ first_mirror.label,
+ release.provider.label()
+ ),
);
let client = if release.provider == ProviderKind::Addons
|| release.provider == ProviderKind::BdixCircleFtp
diff --git a/src/tui/app/mouse.rs b/src/tui/app/mouse.rs
index 2bbcee1..8d6ad5f 100644
--- a/src/tui/app/mouse.rs
+++ b/src/tui/app/mouse.rs
@@ -57,11 +57,7 @@ impl App {
.iter()
.map(|k| k.label().to_string())
.collect::<Vec<_>>();
- let confirm_label = if self.state.settings_player_picker {
- "Select"
- } else {
- "Open"
- };
+ let confirm_label = "Select";
match click_in_picker(
crate::tui::overlay::picker_layout(area, &items, confirm_label, 24),
col,
diff --git a/src/tui/app/navigation.rs b/src/tui/app/navigation.rs
index 9112b92..115a697 100644
--- a/src/tui/app/navigation.rs
+++ b/src/tui/app/navigation.rs
@@ -359,9 +359,6 @@ impl App {
if self.state.player_picker_popup {
self.state.is_resolving_playback = false;
self.state.player_picker_popup = false;
- self.state.player_picker_link = None;
- self.state.player_picker_subtitle = None;
- self.state.player_picker_playback = None;
self.state.player_picker_state.select(None);
self.state.settings_player_picker = false;
return None;
@@ -372,7 +369,6 @@ impl App {
self.state.is_download_subtitle_popup = false;
self.state.pending_play_link = None;
self.state.pending_playback_source = None;
- self.state.pending_open_with = false;
self.state.subtitle_list.clear();
self.state.subtitle_list_state.select(None);
return None;
@@ -717,28 +713,9 @@ impl App {
if self.state.player_picker_popup {
let idx = self.state.player_picker_state.selected().unwrap_or(0);
if let Some(player) = self.state.available_players.get(idx).copied() {
- if let Some(source) = self.state.player_picker_playback.clone() {
- if !crate::tui::player::supports_headers(player, &source.headers) {
- self.state.set_status_long(format!(
- "{} cannot play this source; choose mpv or IINA.",
- player.label()
- ));
- return None;
- }
- }
self.state.player_picker_popup = false;
self.remember_player_preference(player);
self.state.settings_player_picker = false;
- if let Some(source) = self.state.player_picker_playback.take() {
- self.action_sender
- .send(Action::LaunchPlayback(player, source))
- .ok();
- } else if let Some(link) = self.state.player_picker_link.take() {
- let sub = self.state.player_picker_subtitle.take();
- self.action_sender
- .send(Action::LaunchPlayer(player, link, sub))
- .ok();
- }
}
return None;
}
@@ -753,16 +730,7 @@ impl App {
.filter(|s| !s.is_empty());
if let Some(mut source) = self.state.pending_playback_source.take() {
source.subtitle = sub_url;
- let default_player = self.preferred_playback_player(&source);
- if let Some(player) = default_player {
- self.action_sender
- .send(Action::LaunchPlayback(player, source))
- .ok();
- } else {
- self.action_sender
- .send(Action::ShowPlaybackPicker(source))
- .ok();
- }
+ self.dispatch_playback_or_notify(source);
} else if let Some(link) = self.state.pending_play_link.take() {
self.action_sender
.send(Action::LaunchMpv(link, sub_url))
diff --git a/src/tui/app/playback.rs b/src/tui/app/playback.rs
index 6d9bedb..a74da1b 100644
--- a/src/tui/app/playback.rs
+++ b/src/tui/app/playback.rs
@@ -3,16 +3,142 @@ use crate::providers::models::ProviderKind;
use crate::tui::text::parse_duration_seconds;
use crate::tui::{action::Action, overlay::NotificationKind, state::Screen};
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub(super) enum PlaybackResolution {
+ Available(crate::tui::state::PlayerKind),
+ ExplicitPlayerIncompatible {
+ chosen: crate::tui::state::PlayerKind,
+ compatible_alternatives: Vec<crate::tui::state::PlayerKind>,
+ },
+ NoCompatiblePlayer {
+ available: Vec<crate::tui::state::PlayerKind>,
+ },
+ NoPlayersInstalled,
+}
+
impl App {
- pub(super) fn preferred_playback_player(
+ pub(super) fn resolve_playback_player(
&self,
source: &crate::providers::models::PlaybackSource,
- ) -> Option<crate::tui::state::PlayerKind> {
- self.state
+ ) -> PlaybackResolution {
+ if self.state.available_players.is_empty() {
+ return PlaybackResolution::NoPlayersInstalled;
+ }
+
+ let preferred = std::env::var("MOVIEBOX_PLAYER")
+ .ok()
+ .and_then(|value| crate::tui::state::PlayerKind::parse(&value))
+ .or_else(|| {
+ self.state
+ .default_player
+ .as_deref()
+ .filter(|p| !p.eq_ignore_ascii_case("auto"))
+ .and_then(crate::tui::state::PlayerKind::parse)
+ });
+
+ if let Some(chosen) = preferred {
+ if self.state.available_players.contains(&chosen) {
+ if crate::tui::player::supports_headers(chosen, &source.headers) {
+ return PlaybackResolution::Available(chosen);
+ }
+ let compatible_alternatives = self
+ .state
+ .available_players
+ .iter()
+ .copied()
+ .filter(|&k| {
+ k != chosen && crate::tui::player::supports_headers(k, &source.headers)
+ })
+ .collect::<Vec<_>>();
+ return PlaybackResolution::ExplicitPlayerIncompatible {
+ chosen,
+ compatible_alternatives,
+ };
+ }
+ }
+
+ if let Some(player) = self
+ .state
.available_players
.iter()
.copied()
.find(|kind| crate::tui::player::supports_headers(*kind, &source.headers))
+ {
+ PlaybackResolution::Available(player)
+ } else {
+ PlaybackResolution::NoCompatiblePlayer {
+ available: self.state.available_players.clone(),
+ }
+ }
+ }
+
+ pub(super) fn dispatch_playback_or_notify(
+ &mut self,
+ source: crate::providers::models::PlaybackSource,
+ ) {
+ match self.resolve_playback_player(&source) {
+ PlaybackResolution::Available(player) => {
+ self.action_sender
+ .send(Action::LaunchPlayback(player, source))
+ .ok();
+ }
+ PlaybackResolution::ExplicitPlayerIncompatible {
+ chosen,
+ compatible_alternatives,
+ } => {
+ self.state.is_resolving_playback = false;
+ self.state.pending_playback_source = None;
+ let provider_name = source.provider.label();
+ let chosen_name = chosen.label();
+ let body = if !compatible_alternatives.is_empty() {
+ let alternatives_str = compatible_alternatives
+ .iter()
+ .map(|k| k.label())
+ .collect::<Vec<_>>()
+ .join(" or ");
+ format!(
+ "{} cannot play this {} stream due to required authentication headers. Set {} as default in /settings, or press Ctrl+P for 4KHDHub.",
+ chosen_name, provider_name, alternatives_str
+ )
+ } else {
+ format!(
+ "{} cannot play this {} stream due to required authentication headers. Install a compatible player (mpv) or press Ctrl+P for 4KHDHub.",
+ chosen_name, provider_name
+ )
+ };
+ self.state.notify(
+ NotificationKind::Warning,
+ format!("{chosen_name} Incompatible"),
+ body,
+ );
+ }
+ PlaybackResolution::NoCompatiblePlayer { available } => {
+ self.state.is_resolving_playback = false;
+ self.state.pending_playback_source = None;
+ let players_str = available
+ .iter()
+ .map(|k| k.label())
+ .collect::<Vec<_>>()
+ .join(", ");
+ let provider_name = source.provider.label();
+ self.state.notify(
+ NotificationKind::Error,
+ "Incompatible Media Player",
+ format!(
+ "None of your detected players ({players_str}) support authentication headers required by {provider_name} streams. Install mpv or press Ctrl+P for 4KHDHub."
+ ),
+ );
+ }
+ PlaybackResolution::NoPlayersInstalled => {
+ self.state.is_resolving_playback = false;
+ self.state.pending_playback_source = None;
+ self.state.notify(
+ NotificationKind::Error,
+ "No Media Player Found",
+ "Install mpv, IINA, or VLC to enable video playback.",
+ );
+ }
+ }
}
fn build_watch_history_item(&self) -> Option<crate::history::WatchHistoryItem> {
@@ -333,7 +459,11 @@ impl App {
self.state.notify(
NotificationKind::Info,
"Preparing playback",
- "Resolving the selected mirror.",
+ format!(
+ "Resolving {} from {}...",
+ first_mirror.label,
+ release.provider.label()
+ ),
);
let direct_source = crate::providers::models::PlaybackSource {
provider: release.provider,
@@ -342,22 +472,11 @@ impl App {
subtitle: None,
source_label: first_mirror.label.clone(),
};
- let default_player = self.preferred_playback_player(&direct_source);
- let available_players = self.state.available_players.clone();
let client = if release.provider == ProviderKind::Addons
|| release.provider == ProviderKind::BdixCircleFtp
|| release.provider == ProviderKind::BdixDhakaFlix
{
- let sender_clone = self.action_sender.clone();
- if let Some(player) = default_player {
- sender_clone
- .send(Action::LaunchPlayback(player, direct_source))
- .ok();
- } else {
- sender_clone
- .send(Action::ShowPlaybackPicker(direct_source))
- .ok();
- }
+ self.dispatch_playback_or_notify(direct_source);
return None;
} else {
match self.service.fourk_client.clone() {
@@ -382,18 +501,7 @@ impl App {
.await;
match result {
Ok(Ok(source)) => {
- let default_player =
- available_players.iter().copied().find(|kind| {
- crate::tui::player::supports_headers(
- *kind,
- &source.headers,
- )
- });
- if let Some(player) = default_player {
- sender.send(Action::LaunchPlayback(player, source)).ok();
- } else {
- sender.send(Action::ShowPlaybackPicker(source)).ok();
- }
+ sender.send(Action::DispatchPlayback(source)).ok();
}
Ok(Err(error)) => {
log::error!("4KHDHub resolve failed: {error}");
@@ -435,7 +543,6 @@ impl App {
subtitle: None,
source_label: first_mirror.label.clone(),
};
- let default_player = self.preferred_playback_player(&direct_source);
let subject_id = self
.state
.selected_details
@@ -448,7 +555,7 @@ impl App {
self.state.notify(
NotificationKind::Info,
"Preparing playback",
- "Fetching subtitles.",
+ format!("Fetching subtitles for {}...", release.filename),
);
self.state.pending_playback_source = Some(direct_source.clone());
let service = self.service.clone();
@@ -491,26 +598,12 @@ impl App {
.ok();
}
_ => {
- if let Some(player) = default_player {
- sender
- .send(Action::LaunchPlayback(player, source_clone))
- .ok();
- } else {
- sender.send(Action::ShowPlaybackPicker(source_clone)).ok();
- }
+ sender.send(Action::DispatchPlayback(source_clone)).ok();
}
}
});
} else {
- if let Some(player) = default_player {
- self.action_sender
- .send(Action::LaunchPlayback(player, direct_source))
- .ok();
- } else {
- self.action_sender
- .send(Action::ShowPlaybackPicker(direct_source))
- .ok();
- }
+ self.dispatch_playback_or_notify(direct_source);
}
} else {
self.state.is_resolving_playback = false;
@@ -531,16 +624,7 @@ impl App {
self.state.pending_play_link = Some(link);
} else {
if let Some(source) = self.state.pending_playback_source.take() {
- let default_player = self.preferred_playback_player(&source);
- if let Some(player) = default_player {
- self.action_sender
- .send(Action::LaunchPlayback(player, source))
- .ok();
- } else {
- self.action_sender
- .send(Action::ShowPlaybackPicker(source))
- .ok();
- }
+ self.dispatch_playback_or_notify(source);
} else {
self.action_sender.send(Action::LaunchMpv(link, None)).ok();
}
@@ -581,23 +665,16 @@ impl App {
None => {
self.state.notify(
NotificationKind::Error,
- "Player unavailable",
- "Install mpv, IINA, or VLC.",
+ "Player Unavailable",
+ "Install mpv, IINA, or VLC to enable playback.",
);
}
Some(kind) => {
- let player_name = match kind {
- crate::tui::state::PlayerKind::Mpv => "MPV",
- crate::tui::state::PlayerKind::Iina => "IINA",
- crate::tui::state::PlayerKind::Vlc => "VLC",
- crate::tui::state::PlayerKind::AndroidIntent => "Android Player",
- };
self.state.notify(
NotificationKind::Info,
- "Opening player",
- format!("Launching {player_name}."),
+ "Opening Player",
+ format!("Launching {}.", kind.label()),
);
-
self.action_sender
.send(Action::LaunchPlayer(kind, link, subtitle_url))
.ok();
@@ -605,42 +682,6 @@ impl App {
}
}
- Action::ShowPlaybackPicker(source) => {
- self.state.is_resolving_playback = false;
- if self.state.available_players.is_empty() {
- self.state.set_status_default(
- "No media player found. Install mpv, IINA, VLC, or use Android Player.",
- );
- return None;
- }
- self.state.show_help = false;
- self.state.tv_config_popup = false;
- self.state.player_picker_popup = true;
- self.state.player_picker_playback = Some(source);
- self.state.player_picker_link = None;
- self.state.player_picker_subtitle = None;
- self.state.player_picker_state.select(Some(0));
- self.state.subtitle_popup = false;
- }
- Action::ShowPlayerPicker(link, subtitle) => {
- self.state.is_resolving_playback = false;
- if self.state.available_players.is_empty() {
- self.state.notify(
- NotificationKind::Error,
- "Player unavailable",
- "Install mpv, IINA, VLC, or use Android Player.",
- );
- return None;
- }
- self.state.show_help = false;
- self.state.tv_config_popup = false;
- self.state.player_picker_popup = true;
- self.state.player_picker_playback = None;
- self.state.player_picker_link = Some(link);
- self.state.player_picker_subtitle = subtitle;
- self.state.player_picker_state.select(Some(0));
- self.state.subtitle_popup = false;
- }
Action::LaunchPlayer(kind, link, sub) => {
self.state.is_resolving_playback = false;
self.state.player_picker_popup = false;
@@ -661,14 +702,22 @@ impl App {
self.state.player_picker_popup = false;
self.state.last_playback_launch = std::time::Instant::now();
if !crate::tui::player::supports_headers(kind, &source.headers) {
- self.state.set_status_long(format!(
- "This source needs headers {} cannot provide; use mpv or IINA.",
- kind.label()
- ));
+ self.state.notify(
+ NotificationKind::Error,
+ format!("{} Incompatible", kind.label()),
+ format!(
+ "{} cannot play this {} stream because it requires authentication headers.",
+ kind.label(),
+ source.provider.label(),
+ ),
+ );
return None;
}
self.launch_player(kind, source.url, source.subtitle, source.headers);
}
+ Action::DispatchPlayback(source) => {
+ self.dispatch_playback_or_notify(source);
+ }
Action::MarkWatched(item) => {
self.state.history.mark_watched(item);
let history = self.state.history.clone();
@@ -772,22 +821,68 @@ mod tests {
}
#[tokio::test]
- async fn test_playback_resolving_lock_resets_on_picker_and_player_actions() {
+ async fn test_playback_resolving_lock_resets_on_incompatible_player() {
let mut app = crate::tui::app::App::new();
app.state.is_resolving_playback = true;
+ app.state.available_players = vec![crate::tui::state::PlayerKind::Vlc];
+
+ let source = crate::providers::models::PlaybackSource {
+ provider: crate::providers::models::ProviderKind::MovieBox,
+ url: "https://example.com/index.mpd".to_string(),
+ headers: vec![("Cookie".to_string(), "CloudFront-Policy=test".to_string())],
+ subtitle: None,
+ source_label: "Multi-Res".to_string(),
+ };
- app.handle_playback(crate::tui::action::Action::ShowPlaybackPicker(
- crate::providers::models::PlaybackSource::bare(
- crate::providers::models::ProviderKind::MovieBox,
- "https://example.com/stream.m3u8",
- None,
- ),
- ))
- .await;
+ app.dispatch_playback_or_notify(source);
assert!(!app.state.is_resolving_playback);
+ assert!(app.state.pending_playback_source.is_none());
+ assert!(!app.state.player_picker_popup);
+ assert!(!app.state.notifications.is_empty());
}
+ #[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![
+ crate::tui::state::PlayerKind::Mpv,
+ crate::tui::state::PlayerKind::Vlc,
+ ];
+ app.state.default_player = Some("vlc".to_string());
+
+ let source = crate::providers::models::PlaybackSource {
+ provider: crate::providers::models::ProviderKind::MovieBox,
+ url: "https://example.com/index.mpd".to_string(),
+ headers: vec![("Cookie".to_string(), "CloudFront-Policy=test".to_string())],
+ subtitle: None,
+ source_label: "Multi-Res".to_string(),
+ };
+
+ let resolution = app.resolve_playback_player(&source);
+ assert_eq!(
+ resolution,
+ super::PlaybackResolution::ExplicitPlayerIncompatible {
+ chosen: crate::tui::state::PlayerKind::Vlc,
+ compatible_alternatives: vec![crate::tui::state::PlayerKind::Mpv],
+ }
+ );
+ app.state.is_resolving_playback = true;
+ app.dispatch_playback_or_notify(source);
+
+ assert!(!app.state.is_resolving_playback);
+ assert!(app.state.pending_playback_source.is_none());
+ assert!(!app.state.player_picker_popup);
+
+ let notification = app.state.notifications.back().expect("notification posted");
+ assert_eq!(notification.title, "VLC Incompatible");
+ assert!(
+ notification
+ .message
+ .contains("VLC cannot play this MovieBox stream")
+ );
+ assert!(notification.message.contains("mpv"));
+ }
#[tokio::test]
async fn test_playback_resolving_lock_resets_on_player_crash() {
let mut app = crate::tui::app::App::new();
diff --git a/src/tui/app/run.rs b/src/tui/app/run.rs
index 35c34ea..e0916c1 100644
--- a/src/tui/app/run.rs
+++ b/src/tui/app/run.rs
@@ -137,14 +137,10 @@ impl App {
pub(super) async fn probe_terminal(&mut self) {
use ratatui_image::picker::{Capability, ProtocolType};
- self.state.image_probe_attempts = self.state.image_probe_attempts.saturating_add(1);
- self.state.last_image_probe = Some(std::time::Instant::now());
-
match Self::forced_protocol() {
Some(ForcedProtocol::None) => {
self.state.image_supported = false;
self.state.image_picker = None;
- self.state.initial_probe_failed = false;
return;
}
forced => {
@@ -225,7 +221,6 @@ impl App {
if matches!(picker.protocol_type(), ProtocolType::Halfblocks) {
self.state.image_supported = false;
self.state.image_picker = None;
- self.state.initial_probe_failed = !capabilities_empty;
return;
}
self.accept_picker(picker);
@@ -238,7 +233,6 @@ impl App {
}
self.state.image_picker = Some(picker);
self.state.image_supported = true;
- self.state.initial_probe_failed = false;
}
async fn query_picker(&self) -> Option<ratatui_image::picker::Picker> {
@@ -459,10 +453,9 @@ impl App {
Action::PlayStream
| Action::ShowSubtitlePopup(..)
| Action::ShowDownloadSubtitlePopup(..)
- | Action::ShowPlaybackPicker(..)
- | Action::ShowPlayerPicker(..)
| Action::LaunchMpv(..)
| Action::LaunchPlayback(..)
+ | Action::DispatchPlayback(..)
| Action::LaunchPlayer(..)
| Action::MarkWatched(..)
| Action::UpdateProgress { .. }
@@ -735,19 +728,14 @@ impl App {
.iter()
.map(|k| k.label().to_string())
.collect::<Vec<_>>();
- let (title, confirm_label) = if self.state.settings_player_picker {
- ("Default Media Player", "Select")
- } else {
- ("Open with", "Open")
- };
crate::tui::overlay::picker(
frame,
area,
&items,
&mut self.state.player_picker_state,
crate::tui::overlay::PickerSpec {
- title,
- confirm_label,
+ title: "Default Media Player",
+ confirm_label: "Select",
minimum_width: 24,
},
&self.theme,
diff --git a/src/tui/app/search.rs b/src/tui/app/search.rs
index d72e493..8051457 100644
--- a/src/tui/app/search.rs
+++ b/src/tui/app/search.rs
@@ -244,11 +244,13 @@ impl App {
if raw_arg.eq_ignore_ascii_case("reset") || raw_arg.eq_ignore_ascii_case("default")
{
+ let default_path =
+ crate::logging::sanitize_path(self.resolve_download_base_dir());
if self.state.download_dir.is_none() {
self.state.notify(
NotificationKind::Info,
"Download Directory",
- "Already using system default (~/Downloads/MovieBox-TUI)",
+ format!("Already using system default ({default_path})"),
);
} else {
self.state.download_dir = None;
@@ -256,7 +258,7 @@ impl App {
self.state.notify(
NotificationKind::Success,
"Download Directory",
- "Reset to default (~/Downloads/MovieBox-TUI)",
+ format!("Reset to default ({default_path})"),
);
}
return Some(true);
diff --git a/src/tui/app/system.rs b/src/tui/app/system.rs
index 9540fd1..0fba097 100644
--- a/src/tui/app/system.rs
+++ b/src/tui/app/system.rs
@@ -108,15 +108,6 @@ impl App {
}
Action::FocusChange => {
- if self.state.initial_probe_failed
- && self.state.image_probe_attempts < 3
- && self
- .state
- .last_image_probe
- .is_none_or(|probe| probe.elapsed() >= std::time::Duration::from_secs(30))
- {
- self.probe_terminal().await;
- }
self.prepare_image_soft_refresh();
}
@@ -448,9 +439,6 @@ impl App {
if !self.state.available_players.is_empty() {
self.state.settings_player_picker = true;
self.state.player_picker_popup = true;
- self.state.player_picker_playback = None;
- self.state.player_picker_link = None;
- self.state.player_picker_subtitle = None;
let selected_idx =
self.state
.default_player
diff --git a/src/tui/app/tv.rs b/src/tui/app/tv.rs
index 6febd52..0f1daf2 100644
--- a/src/tui/app/tv.rs
+++ b/src/tui/app/tv.rs
@@ -9,15 +9,11 @@ impl App {
self.state.show_settings_popup = false;
self.state.settings_download_dir_input = None;
self.state.player_picker_popup = false;
- self.state.player_picker_link = None;
- self.state.player_picker_subtitle = None;
- self.state.player_picker_playback = None;
self.state.settings_player_picker = false;
self.state.subtitle_popup = false;
self.state.is_download_subtitle_popup = false;
self.state.pending_play_link = None;
- self.state.pending_open_with = false;
self.state.subtitle_list.clear();
self.state.subtitle_list_state.select(None);
self.state.show_season_download_confirm = false;
diff --git a/src/tui/state.rs b/src/tui/state.rs
index 7067fed..d261049 100644
--- a/src/tui/state.rs
+++ b/src/tui/state.rs
@@ -186,7 +186,6 @@ pub struct PlaybackState {
pub available_players: Vec<PlayerKind>,
pub pending_play_link: Option<String>,
pub pending_playback_source: Option<crate::providers::models::PlaybackSource>,
- pub pending_open_with: bool,
}
#[derive(Debug, Default)]
@@ -264,9 +263,6 @@ pub struct AppState {
pub show_theme_popup: bool,
pub active_theme_kind: String,
pub theme_is_auto: bool,
- pub image_probe_attempts: u8,
- pub last_image_probe: Option<std::time::Instant>,
- pub initial_probe_failed: bool,
pub original_theme_kind: Option<String>,
pub theme_list_state: ListState,
pub show_browse_popup: bool,
@@ -303,9 +299,6 @@ pub struct AppState {
pub last_resize_time: Option<(std::time::Instant, u16, u16)>,
pub player_picker_popup: bool,
pub player_picker_state: ListState,
- pub player_picker_link: Option<String>,
- pub player_picker_subtitle: Option<String>,
- pub player_picker_playback: Option<crate::providers::models::PlaybackSource>,
pub settings_player_picker: bool,
pub available_players: Vec<PlayerKind>,
pub default_player: Option<String>,
@@ -344,7 +337,6 @@ pub struct AppState {
pub subtitle_list_state: ListState,
pub pending_play_link: Option<String>,
pub pending_playback_source: Option<crate::providers::models::PlaybackSource>,
- pub pending_open_with: bool,
pub basic_terminal: bool,
pub bdix_enabled: bool,
pub streaming_enabled: bool,
@@ -429,9 +421,6 @@ impl Default for AppState {
poster_image: None,
active_theme_kind: String::new(),
theme_is_auto: true,
- image_probe_attempts: 0,
- last_image_probe: None,
- initial_probe_failed: false,
original_theme_kind: None,
show_theme_popup: false,
theme_list_state: ListState::default(),
@@ -467,9 +456,6 @@ impl Default for AppState {
last_resize_time: None,
player_picker_popup: false,
player_picker_state: ListState::default(),
- player_picker_link: None,
- player_picker_subtitle: None,
- player_picker_playback: None,
settings_player_picker: false,
available_players: Vec::new(),
default_player: None,
@@ -509,7 +495,6 @@ impl Default for AppState {
subtitle_list_state: ListState::default(),
pending_play_link: None,
pending_playback_source: None,
- pending_open_with: false,
bdix_enabled: false,
streaming_enabled: true,
is_tv_mode: false,
diff --git a/src/tui/terminal.rs b/src/tui/terminal.rs
index cf88b74..fc6acee 100644
--- a/src/tui/terminal.rs
+++ b/src/tui/terminal.rs
@@ -13,12 +13,45 @@ pub fn should_query_images() -> bool {
{
return false;
}
+ if let Ok(forced) = std::env::var("MOVIEBOX_IMAGE_PROTOCOL") {
+ let forced = forced.trim();
+ if forced.eq_ignore_ascii_case("none")
+ || forced.eq_ignore_ascii_case("off")
+ || forced.eq_ignore_ascii_case("false")
+ {
+ return false;
+ }
+ if !forced.is_empty() {
+ return true;
+ }
+ }
if std::env::var("TMUX").is_ok() && std::env::var("MOVIEBOX_IMAGE_PROTOCOL").is_err() {
return false;
}
+ if std::env::var("TERM_PROGRAM").is_ok_and(|v| v == "Apple_Terminal") {
+ return false;
+ }
let term = env("TERM");
-
- term != "dumb" && term != "linux"
+ if term == "dumb"
+ || term == "linux"
+ || term == "cygwin"
+ || term.starts_with("vt")
+ || term.starts_with("cons")
+ {
+ return false;
+ }
+ #[cfg(target_os = "windows")]
+ {
+ let is_modern_terminal = std::env::var("WT_SESSION").is_ok()
+ || std::env::var("TERM_PROGRAM").is_ok()
+ || std::env::var("ALACRITTY_LOG").is_ok()
+ || std::env::var("WEZTERM_EXECUTABLE").is_ok()
+ || std::env::var("GHOSTTY_RESOURCES_DIR").is_ok();
+ if !is_modern_terminal {
+ return false;
+ }
+ }
+ true
}
pub fn background_is_light() -> bool {
@@ -37,3 +70,28 @@ pub fn background_is_light() -> bool {
pub fn set_window_title(title: &str) -> std::io::Result<()> {
crossterm::execute!(std::io::stdout(), crossterm::terminal::SetTitle(title))
}
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_should_query_images_guards() {
+ unsafe {
+ std::env::set_var("MOVIEBOX_NO_IMAGE", "1");
+ assert!(!should_query_images());
+ std::env::remove_var("MOVIEBOX_NO_IMAGE");
+
+ std::env::set_var("MOVIEBOX_IMAGE_PROTOCOL", "none");
+ assert!(!should_query_images());
+ std::env::remove_var("MOVIEBOX_IMAGE_PROTOCOL");
+
+ std::env::set_var("TERM_PROGRAM", "Apple_Terminal");
+ assert!(!should_query_images());
+ std::env::remove_var("TERM_PROGRAM");
+
+ std::env::set_var("TERM", "dumb");
+ assert!(!should_query_images());
+ std::env::remove_var("TERM");
+ }
+ }
+}