Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
fix(player): resolve termux android openers and remove illegal system am fallback
Samir Hossains7de40b395211
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a6a8161..18d2277 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -19,6 +19,7 @@- **Cross-platform release validation**: Run all-feature locked builds/tests, binary startup smoke tests, Unix and Windows installer syntax checks, and release-target builds in CI.- **Release artifact smoke tests**: Execute each native release target's produced binary on its CI runner before archiving.- **Documentation accuracy**: Document Android intent limitations, the actual Termux binary model, macOS-only IINA support, native runtime verification requirements, and the current automated test count.+- **Termux player opener resolution**: Resolve `termux-open`, `termux-open-url`, and `termux-am` directly in `$PREFIX/bin` and static Termux paths; remove broken `/system/bin/am` fallback in unrooted Termux that crashed with Permission Denied (exit code 126).- **Termux dependency path**: Remove the Android platform-verifier dependency path that caused the v0.1.12 startup panic; real-device confirmation remains required.## [0.1.13] - 2026-08-21diff --git a/README.md b/README.mdindex 38f772b..b48e0a1 100644--- a/README.md+++ b/README.md@@ -94,11 +94,13 @@ Or manual installation:### Android (Termux)-Using the automated installer (installs prebuilt static ARM64 binary into `$PREFIX/bin`):+Install Termux tools and run the automated installer:```bash+pkg update && pkg install termux-toolscurl -fsSL https://raw.githubusercontent.com/mesamirh/MovieBox-Tui/main/install.sh -o install.sh && bash install.shtermux-setup-storage```+*(Installing `termux-tools` provides `termux-open`, allowing MovieBox-TUI to automatically launch your preferred Android video player app like VLC, MX Player, or Nova).**(Or compile natively via Cargo: `pkg install rust && cargo install moviebox-tui --locked`)*diff --git a/docs/cross-platform.md b/docs/cross-platform.mdindex ae00f75..285dee7 100644--- a/docs/cross-platform.md+++ b/docs/cross-platform.md@@ -15,7 +15,7 @@ the release checks in [`release-checklist.md`](release-checklist.md).| macOS | IINA preferred player (via the installed IINA `iina-cli`); VLC/mpv `.app` paths detected. `process_group(0)` on spawn. || Windows | mpv/VLC detected via Program Files + `%LOCALAPPDATA%`; players spawned with `CREATE_NO_WINDOW`; path-safe file stems; static MSVC CRT linking (`+crt-static`) for zero-dependency standalone binaries. || Linux | Flatpak mpv/VLC supported (`flatpak run …`); xdg data/cache dirs. |-| Android (Termux) | Uses the Linux ARM64 binary and dynamically checks for `/system/bin/am` or `termux-open`; playback strips `LD_LIBRARY_PATH` and `LD_PRELOAD` before launching the chooser. Android intent playback cannot forward stream headers or attach subtitles. Real-device chooser behavior is a release prerequisite; Proot/Termux X11 behavior is unsupported unless separately tested. |+| Android (Termux) | Uses the Linux ARM64 binary and dynamically checks for `termux-open`, `termux-open-url`, `termux-am`, or in-terminal `mpv`; playback strips `LD_LIBRARY_PATH` and `LD_PRELOAD` before launching the chooser. Android intent playback cannot forward stream headers or attach subtitles. Real-device chooser behavior is a release prerequisite; Proot/Termux X11 behavior is unsupported unless separately tested. |## Terminal capabilitiesdiff --git a/docs/known-issues.md b/docs/known-issues.mdindex ce59b0c..b472e7c 100644--- a/docs/known-issues.md+++ b/docs/known-issues.md@@ -29,6 +29,6 @@ Tracked here so future work and issue reports reference the same facts.## Verification-- Automated testing is enforced via `cargo test --all-features --locked` covering 171 unit and integration tests across 16 test suites (see [`docs/testing.md`](testing.md)). The count is updated when tests change; it does not replace real-player and real-device verification.+- Automated testing is enforced via `cargo test --all-features --locked` covering 172 unit and integration tests across 16 test suites (see [`docs/testing.md`](testing.md)). The count is updated when tests change; it does not replace real-player and real-device verification.- Static correctness is enforced by strict compiler type checking, the lint gate (`cargo clippy --all-targets --all-features --locked -- -D warnings`), formatting (`cargo fmt --check`), dependency vulnerability scanning (`cargo audit`), and packaging verification (`cargo package --locked`).- Runtime and platform-specific behavior (terminal resize, focus handling, external player launch, and Termux chooser) are verified through the release checklist in [`release-checklist.md`](release-checklist.md).diff --git a/docs/players.md b/docs/players.mdindex e3c3be0..2d11cdb 100644--- a/docs/players.md+++ b/docs/players.md@@ -10,7 +10,7 @@ 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).-- Android/Termux: the Android intent fallback is attempted last when `termux-open` or `am` is available.+- 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 beforced via `MOVIEBOX_PLAYER` env or `default_player` in config (e.g. `mpv`, `iina`,@@ -25,7 +25,7 @@ detected player and saves the chosen player as the next default unless| mpv | `mpv --autofit=WxH --geometry=50%:50% --idle=no --keep-open=no [--start=..] [--script=..] [--script-opts=..] [--http-header-fields=..] [--sub-file=..] <url>` | Window sized to the terminal. Injects `moviebox_tracker.lua` for position tracking and resume. Flatpak mpv is launched via `flatpak run`. || VLC | `vlc --width=W --height=H --play-and-exit [--start-time=..] [--http-referrer=..] [--http-user-agent=..] [--sub-file=..] <url>` | Supports start time resume via `--start-time`. || IINA | `iina-cli --keep-running --no-stdin --mpv-autofit=.. [--mpv-start=..] --mpv-http-header-fields=.. --mpv-sub-files=.. <url>` | Uses the installed IINA `iina-cli`; falls back to `open -a IINA <url>` only if the CLI is absent. |-| Android / Proot | `termux-open --chooser --content-type video/* <url>` (or absolute `/system/bin/am start` fallback, ensuring `.so` injections are dropped) | Opens an app chooser on the device. Device-specific chooser behavior should be confirmed for each release. |+| Android / Termux | `termux-open --chooser --content-type video/* <url>` (or `termux-open-url` / `termux-am`) | Opens an app chooser on the device. Requires `termux-tools` (or `termux-am`). |Window size is derived from the live terminal size times the font cell size reportedby the image picker, then clamped to a fixed range.diff --git a/install.sh b/install.shindex e5c5033..dbfdc1f 100755--- a/install.sh+++ b/install.sh@@ -514,6 +514,8 @@ elif command -v iina >/dev/null 2>&1 || command -v iina-cli >/dev/null 2>&1; thePLAYER_DETECTED="IINA"elif command -v vlc >/dev/null 2>&1; thenPLAYER_DETECTED="VLC"+elif command -v termux-open >/dev/null 2>&1; then+ PLAYER_DETECTED="Android Player (termux-open)"fiprintf "\n"@@ -522,6 +524,8 @@ printf " %b•%b %bBinary:%b %b%s%b\n" "$C_MUTED" "$C_RESET" "$C_MUTED" "$C_REif [ -n "$PLAYER_DETECTED" ]; thenprintf " %b•%b %bPlayer:%b %b%s (ready)%b\n" "$C_MUTED" "$C_RESET" "$C_MUTED" "$C_RESET" "$C_GREEN" "$PLAYER_DETECTED" "$C_RESET"+elif [ "$IS_TERMUX" -eq 1 ]; then+ printf " %b•%b %bPlayer:%b %bNone detected (run 'pkg install termux-tools')%b\n" "$C_MUTED" "$C_RESET" "$C_MUTED" "$C_RESET" "$C_SAPPHIRE" "$C_RESET"elseprintf " %b•%b %bPlayer:%b %bNone detected (mpv, VLC, or IINA recommended)%b\n" "$C_MUTED" "$C_RESET" "$C_MUTED" "$C_RESET" "$C_SAPPHIRE" "$C_RESET"fi@@ -535,7 +539,11 @@ printf " %bTo start streaming:%b\n" "$C_TEXT" "$C_RESET"printf " %b$ moviebox-tui%b\n\n" "$C_GREEN" "$C_RESET"if [ -z "$PLAYER_DETECTED" ]; then- printf " %bℹ%b Note: A media player (mpv, VLC, or IINA) is recommended for video playback.\n\n" "$C_SAPPHIRE" "$C_RESET"+ if [ "$IS_TERMUX" -eq 1 ]; then+ printf " %bℹ%b Note: Run %b'pkg install termux-tools'%b to enable video playback on Termux.\n\n" "$C_SAPPHIRE" "$C_RESET" "$C_BOLD" "$C_RESET"+ else+ printf " %bℹ%b Note: A media player (mpv, VLC, or IINA) is recommended for video playback.\n\n" "$C_SAPPHIRE" "$C_RESET"+ fifiif [ -n "$SHELL_MODIFIED" ]; thendiff --git a/src/player.rs b/src/player.rsindex 62b7ebb..b108b30 100644--- a/src/player.rs+++ b/src/player.rs@@ -56,12 +56,7 @@ pub fn detect() -> Vec<PlayerKind> {players.push(PlayerKind::Vlc);}- let is_android = cfg!(target_os = "android")- || std::path::Path::new("/system/bin/am").exists()- || executable_on_path("termux-open")- || executable_on_path("am");-- if is_android {+ if android_opener().is_some() {players.push(PlayerKind::AndroidIntent);}@@ -124,34 +119,140 @@ fn build_player_process_command(executable: &str) -> Command {}}-fn android_intent_command(url: &str) -> Command {- let mut command;- if executable_on_path("termux-open") {- command = Command::new("termux-open");- command- .arg("--chooser")- .arg("--content-type")- .arg("video/*")- .arg(url);- } else {- let am_path = if std::path::Path::new("/system/bin/am").exists() {- "/system/bin/am"+enum AndroidOpener {+ TermuxOpen(String),+ TermuxOpenUrl(String),+ TermuxAm(String),+ SystemAm(String),+}++fn is_termux_env() -> bool {+ 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> {+ if let Some(custom) = configured_executable("MOVIEBOX_ANDROID_PLAYER_PATH") {+ if custom.ends_with("termux-open-url") {+ return Some(AndroidOpener::TermuxOpenUrl(custom));+ } else if custom.ends_with("termux-am") || custom.ends_with("/am") {+ return Some(AndroidOpener::TermuxAm(custom));} else {- "am"- };- command = Command::new(am_path);- command- .arg("start")- .arg("--user")- .arg("0")- .arg("-a")- .arg("android.intent.action.VIEW")- .arg("-d")- .arg(url)- .arg("-t")- .arg("video/*");+ return Some(AndroidOpener::TermuxOpen(custom));+ }+ }++ let is_termux = is_termux_env();++ if let Ok(prefix) = std::env::var("PREFIX") {+ let termux_open = format!("{prefix}/bin/termux-open");+ if Path::new(&termux_open).is_file() {+ return Some(AndroidOpener::TermuxOpen(termux_open));+ }+ let termux_open_url = format!("{prefix}/bin/termux-open-url");+ if Path::new(&termux_open_url).is_file() {+ return Some(AndroidOpener::TermuxOpenUrl(termux_open_url));+ }+ let termux_am = format!("{prefix}/bin/termux-am");+ if Path::new(&termux_am).is_file() {+ return Some(AndroidOpener::TermuxAm(termux_am));+ }+ let am_bin = format!("{prefix}/bin/am");+ if Path::new(&am_bin).is_file() {+ return Some(AndroidOpener::TermuxAm(am_bin));+ }}+ let termux_open_static = "/data/data/com.termux/files/usr/bin/termux-open";+ if Path::new(termux_open_static).is_file() {+ return Some(AndroidOpener::TermuxOpen(termux_open_static.to_string()));+ }+ let termux_open_url_static = "/data/data/com.termux/files/usr/bin/termux-open-url";+ if Path::new(termux_open_url_static).is_file() {+ return Some(AndroidOpener::TermuxOpenUrl(+ termux_open_url_static.to_string(),+ ));+ }+ let termux_am_static = "/data/data/com.termux/files/usr/bin/termux-am";+ if Path::new(termux_am_static).is_file() {+ return Some(AndroidOpener::TermuxAm(termux_am_static.to_string()));+ }+ let termux_am_bin_static = "/data/data/com.termux/files/usr/bin/am";+ if Path::new(termux_am_bin_static).is_file() {+ return Some(AndroidOpener::TermuxAm(termux_am_bin_static.to_string()));+ }++ if let Some(path) = find_in_path("termux-open") {+ return Some(AndroidOpener::TermuxOpen(path));+ }+ if let Some(path) = find_in_path("termux-open-url") {+ return Some(AndroidOpener::TermuxOpenUrl(path));+ }+ if let Some(path) = find_in_path("termux-am") {+ return Some(AndroidOpener::TermuxAm(path));+ }++ if !is_termux {+ if Path::new("/system/bin/am").is_file() {+ return Some(AndroidOpener::SystemAm("/system/bin/am".to_string()));+ }+ if let Some(path) = find_in_path("am") {+ return Some(AndroidOpener::SystemAm(path));+ }+ }++ None+}++fn android_intent_command(url: &str) -> Command {+ let mut command = match android_opener() {+ Some(AndroidOpener::TermuxOpen(path)) => {+ let mut cmd = Command::new(path);+ cmd.arg("--chooser")+ .arg("--content-type")+ .arg("video/*")+ .arg(url);+ cmd+ }+ Some(AndroidOpener::TermuxOpenUrl(path)) => {+ let mut cmd = Command::new(path);+ cmd.arg(url);+ cmd+ }+ Some(AndroidOpener::TermuxAm(path)) => {+ let mut cmd = Command::new(path);+ cmd.arg("start")+ .arg("-a")+ .arg("android.intent.action.VIEW")+ .arg("-d")+ .arg(url)+ .arg("-t")+ .arg("video/*");+ cmd+ }+ Some(AndroidOpener::SystemAm(path)) => {+ let mut cmd = Command::new(path);+ cmd.arg("start")+ .arg("--user")+ .arg("0")+ .arg("-a")+ .arg("android.intent.action.VIEW")+ .arg("-d")+ .arg(url)+ .arg("-t")+ .arg("video/*");+ cmd+ }+ None => {+ let mut cmd = Command::new("termux-open");+ cmd.arg("--chooser")+ .arg("--content-type")+ .arg("video/*")+ .arg(url);+ cmd+ }+ };+command.env_remove("LD_LIBRARY_PATH");command.env_remove("LD_PRELOAD");@@ -384,6 +485,10 @@ fn mpv_executable() -> Option<String> {#[cfg(target_os = "linux")]{+ if let Ok(prefix) = std::env::var("PREFIX") {+ candidates.push(format!("{prefix}/bin/mpv"));+ }+ candidates.push("/data/data/com.termux/files/usr/bin/mpv".to_string());if let Some(home) = dirs::home_dir() {candidates.push(home.join(".local/share/flatpak/exports/bin/io.mpv.Mpv")@@ -469,6 +574,10 @@ fn vlc_executable() -> Option<String> {#[cfg(target_os = "linux")]{+ if let Ok(prefix) = std::env::var("PREFIX") {+ candidates.push(format!("{prefix}/bin/vlc"));+ }+ candidates.push("/data/data/com.termux/files/usr/bin/vlc".to_string());if let Some(home) = dirs::home_dir() {candidates.push(home.join(".local/share/flatpak/exports/bin/org.videolan.VLC")@@ -711,4 +820,14 @@ mod tests {&[("referer".into(), "https://example.test/".into())]));}++ #[test]+ fn test_android_intent_command_structure() {+ let cmd = android_intent_command("https://example.test/video.mp4");+ let args = cmd+ .get_args()+ .map(|a| a.to_string_lossy().into_owned())+ .collect::<Vec<_>>();+ assert!(args.contains(&"https://example.test/video.mp4".to_string()));+ }}