Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
fix(player): resolve android intent stream compatibility and forward extras
Samir Hossains750738d829ae
diff --git a/.github/workflows/build-android.yml b/.github/workflows/build-android.ymlindex 75752c3..38f597f 100644--- a/.github/workflows/build-android.yml+++ b/.github/workflows/build-android.yml@@ -7,6 +7,10 @@ on:description: "Release tag to attach the Android binary to"required: truedefault: "v0.1.16"+ git_ref:+ description: "Git ref (branch, tag, or commit SHA) to build from"+ required: false+ default: "main"permissions:contents: write@@ -19,7 +23,7 @@ jobs:steps:- uses: actions/checkout@v7with:- ref: ${{ github.event.inputs.release_tag }}+ ref: ${{ github.event.inputs.git_ref || github.event.inputs.release_tag }}- name: Install Rustuses: dtolnay/rust-toolchain@stablediff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4f1d07a..770c8eb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -17,6 +17,12 @@- Added automated GitHub Actions deployment workflow (`.github/workflows/pages.yml`) publishing the documentation site to GitHub Pages on every push to `main`.- Added documentation build integrity validation step in CI hygiene pipeline (`.github/workflows/ci.yml`).+### Fixed+- **Android Intent Player Stream Compatibility**:+ - Eliminated blanket player incompatibility errors on Android: unauthenticated streams (CircleFTP, DhakaFlix, IPTV, direct streams) and streams carrying standard `Referer`/`User-Agent` headers (4KHDHub) now dispatch directly to Android video players via `termux-open` or `am start`.+ - Added empty-header guard to `supports_headers`, ensuring streams without authentication requirements are never falsely rejected as incompatible.+ - Forwarded `User-Agent`, `Referer`, and subtitles (`subtitles_location` and `subs`) as intent extras when dispatching playback via `am` or `termux-am`.+ - Prevented circular provider switch prompts when playing 4KHDHub streams by tailoring notification hints based on the active provider.## [0.1.16] - 2026-09-05### Addeddiff --git a/docs/cross-platform.md b/docs/cross-platform.mdindex 34ef92d..20f30d3 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%`; path-safe file stems; static MSVC CRT linking (`+crt-static`) for zero-dependency standalone binaries; handle-safe atomic download replacement (dropping file handles before renames); background update helper spawned with `CREATE_NO_WINDOW` (`0x08000000`). || Linux | Flatpak mpv/VLC supported (`flatpak run …`); xdg data/cache dirs. |-| Android (Termux) | Targets `aarch64-linux-android` linked against the Android NDK (Clang API 24+) and system Bionic `libc.so`, producing a native ELF executable with a valid `PT_PHDR` program header table and `/system/bin/linker64` dynamic loader. This eliminates `Could not find a PHDR: broken executable?` crashes and executes natively without on-device compilation. Includes a pure-Rust DNS resolver that reads system configuration and falls back to public resolvers (Cloudflare, Google, Quad9) for zero-config name resolution, 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. |+| Android (Termux) | Targets `aarch64-linux-android` linked against the Android NDK (Clang API 24+) and system Bionic `libc.so`, producing a native ELF executable with a valid `PT_PHDR` program header table and `/system/bin/linker64` dynamic loader. This eliminates `Could not find a PHDR: broken executable?` crashes and executes natively without on-device compilation. Includes a pure-Rust DNS resolver that reads system configuration and falls back to public resolvers (Cloudflare, Google, Quad9) for zero-config name resolution, 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 supports unauthenticated streams (CircleFTP, DhakaFlix, IPTV) and standard CDN streams (4KHDHub); streams requiring signed CloudFront cookies (MovieBox) require in-terminal `mpv`. 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 258ca09..6578269 100644--- a/docs/known-issues.md+++ b/docs/known-issues.md@@ -5,16 +5,16 @@ Tracked here so future work and issue reports reference the same facts.## Latent / by-design- **`supports_headers` is compatibility policy, not just a parser guard.** Sources that- carry playback headers already exercise it for Android intent playback, and any future- provider that needs headers beyond `referer`/`user-agent` will also trip it for VLC.- Keep `player.rs::supports_headers` in sync with `vlc_command`'s filter.+ carry authentication headers (e.g. MovieBox CloudFront signed cookies) exercise it for Android intent and VLC playback.+ Android intent and VLC players support unauthenticated streams (CircleFTP, DhakaFlix, IPTV, direct streams) as well as streams+ with standard `referer`/`user-agent` headers (4KHDHub). Streams requiring custom cookies or auth tokens trip the compatibility+ gate and guide the user to mpv. Keep `player.rs::supports_headers` in sync with VLC and Android opener capabilities.- **BDIX clients use nested `if let Ok` pyramids** in search handling; they work andare logged, but are harder to read. Flattening is deferred (behavior-neutral refactorwith moderate churn).- **MovieBox request signing** hardcodes an API secret and spoofs a device identity in`crypto.rs`. This is inherent to the scraper; treat the module as one unit.-- **Android intent playback** cannot attach subtitles (a `VIEW` intent has no subtitle- mechanism); subtitles are ignored for the Android player.+- **Android intent playback** forwards `User-Agent`, `Referer`, and subtitles (`subtitles_location`/`subs`) when using `am` or `termux-am`. Chooser-based launches via `termux-open` open the raw video URL directly.## Environment-dependentdiff --git a/docs/players.md b/docs/players.mdindex 5ba80aa..ce34c07 100644--- a/docs/players.md+++ b/docs/players.md@@ -21,7 +21,7 @@ Resolution caches detected paths across runs while allowing newly installed play| 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 / 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`). |+| Android / Termux | `termux-open --chooser --content-type video/* <url>` (or `termux-open-url` / `termux-am`) | Opens an app chooser on the device. When launched via `termux-am` or `am`, forwards `User-Agent`, `Referer`, and subtitles (`subtitles_location`/`subs`). |Window size is derived from the live terminal size times the font cell size reportedby the image picker, then clamped to a fixed range.@@ -31,8 +31,8 @@ by the image picker, then clamped to a fixed range.Playback sources (for example 4KHD and MovieBox) may carry `Referer`/`User-Agent` 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`.+while VLC maps them to `--http-referrer` / `--http-user-agent`. Android intent playback forwards `Referer`/`User-Agent` extras when using `am`/`termux-am`, and supports unauthenticated streams (CircleFTP, DhakaFlix, IPTV) and CDN streams natively.+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 or Android Player attempting to play signed MovieBox DASH manifests with CloudFront 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@@ -40,6 +40,7 @@ The `supports_headers` gate in `app/playback.rs` validates whether a player can- VLC and IINA download the subtitle to a temp file first, preserving the URL'sextension (srt/vtt/ass/…), and pass the local path. The download applies the sourceheaders. On failure a status is shown and playback continues without subtitles.+- Android intent playback passes subtitle paths to `am`/`termux-am` via `subtitles_location` and `subs` intent extras.- Temp files are cleaned up after the player exits and purged at startup if stale.## Playback Tracking & Resumediff --git a/src/player.rs b/src/player.rsindex 3d1093b..72b3bb7 100644--- a/src/player.rs+++ b/src/player.rs@@ -64,17 +64,20 @@ pub fn detect() -> Vec<PlayerKind> {}pub fn supports_headers(kind: PlayerKind, headers: &[(String, String)]) -> bool {- if kind == PlayerKind::AndroidIntent {- return false;+ if headers.is_empty() {+ return true;}#[cfg(target_os = "macos")]if kind == PlayerKind::Iina && !iina_cli_exists() {return false;}- kind != PlayerKind::Vlc- || headers.iter().all(|(name, _)| {+ match kind {+ PlayerKind::Mpv => true,+ PlayerKind::Iina => true,+ PlayerKind::Vlc | PlayerKind::AndroidIntent => headers.iter().all(|(name, _)| {name.eq_ignore_ascii_case("referer") || name.eq_ignore_ascii_case("user-agent")- })+ }),+ }}pub fn command(@@ -98,7 +101,7 @@ pub fn command(),PlayerKind::Iina => iina_command(url, subtitle, headers, window, resume_seconds, tracker),PlayerKind::Vlc => vlc_command(url, subtitle, headers, window, resume_seconds),- PlayerKind::AndroidIntent => android_intent_command(url),+ PlayerKind::AndroidIntent => android_intent_command(url, subtitle, headers),}}@@ -218,7 +221,29 @@ fn android_opener() -> Option<AndroidOpener> {detected}-fn android_intent_command(url: &str) -> Command {+fn append_android_intent_extras(+ cmd: &mut Command,+ subtitle: Option<&str>,+ headers: &[(String, String)],+) {+ if let Some(sub) = subtitle {+ cmd.arg("-e").arg("subtitles_location").arg(sub);+ cmd.arg("-e").arg("subs").arg(sub);+ }+ for (name, value) in headers {+ if name.eq_ignore_ascii_case("user-agent") {+ cmd.arg("-e").arg("User-Agent").arg(value);+ } else if name.eq_ignore_ascii_case("referer") {+ cmd.arg("-e").arg("Referer").arg(value);+ }+ }+}++fn android_intent_command(+ url: &str,+ subtitle: Option<&str>,+ headers: &[(String, String)],+) -> Command {let mut command = match android_opener() {Some(AndroidOpener::TermuxOpen(path)) => {let mut cmd = Command::new(path);@@ -242,6 +267,7 @@ fn android_intent_command(url: &str) -> Command {.arg(url).arg("-t").arg("video/*");+ append_android_intent_extras(&mut cmd, subtitle, headers);cmd}Some(AndroidOpener::SystemAm(path)) => {@@ -255,6 +281,7 @@ fn android_intent_command(url: &str) -> Command {.arg(url).arg("-t").arg("video/*");+ append_android_intent_extras(&mut cmd, subtitle, headers);cmd}None => {@@ -1349,11 +1376,21 @@ mod tests {PlayerKind::Vlc,&[("referer".into(), "https://example.test/".into())]));+ assert!(supports_headers(PlayerKind::AndroidIntent, &[]));+ assert!(supports_headers(+ PlayerKind::AndroidIntent,+ &[+ ("referer".into(), "https://example.test/".into()),+ ("user-agent".into(), "TestAgent/1.0".into())+ ]+ ));+ assert!(supports_headers(PlayerKind::Vlc, &[]));+ assert!(supports_headers(PlayerKind::Mpv, &headers));}#[test]fn test_android_intent_command_structure() {- let cmd = android_intent_command("https://example.test/video.mp4");+ let cmd = android_intent_command("https://example.test/video.mp4", None, &[]);let args = cmd.get_args().map(|a| a.to_string_lossy().into_owned())diff --git a/src/tui/app/playback.rs b/src/tui/app/playback.rsindex 7091eb5..fb7411d 100644--- a/src/tui/app/playback.rs+++ b/src/tui/app/playback.rs@@ -96,15 +96,29 @@ impl App {.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- )+ if source.provider == ProviderKind::FourKHdHub {+ format!(+ "{} cannot play this {} stream due to required authentication headers. Set {} as default in /settings.",+ chosen_name, provider_name, alternatives_str+ )+ } else {+ 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- )+ if source.provider == ProviderKind::FourKHdHub {+ format!(+ "{} cannot play this {} stream due to required authentication headers. Install a compatible player (mpv).",+ chosen_name, provider_name+ )+ } 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,@@ -121,11 +135,16 @@ impl App {.collect::<Vec<_>>().join(", ");let provider_name = source.provider.label();+ let action_hint = if source.provider == ProviderKind::FourKHdHub {+ "Install mpv."+ } else {+ "Install mpv or press Ctrl+P for 4KHDHub."+ };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."+ "None of your detected players ({players_str}) support authentication headers required by {provider_name} streams. {action_hint}"),);}@@ -931,4 +950,52 @@ mod tests {assert!(!app.state.is_resolving_playback);assert!(!app.state.is_playing);}+ #[tokio::test]+ async fn test_android_player_allows_unauthenticated_and_referer_streams() {+ let mut app = crate::tui::app::App::new();+ app.state.available_players = vec![crate::tui::state::PlayerKind::AndroidIntent];+ app.state.default_player = Some("android".to_string());++ let bdix_source = crate::providers::models::PlaybackSource {+ provider: crate::providers::models::ProviderKind::BdixCircleFtp,+ url: "http://10.16.100.244/movies/film.mkv".to_string(),+ headers: vec![],+ subtitle: None,+ source_label: "CircleFTP".to_string(),+ };+ assert_eq!(+ app.resolve_playback_player(&bdix_source),+ super::PlaybackResolution::Available(crate::tui::state::PlayerKind::AndroidIntent)+ );++ let fourk_source = crate::providers::models::PlaybackSource {+ provider: crate::providers::models::ProviderKind::FourKHdHub,+ url: "https://r2.example.com/stream.mkv".to_string(),+ headers: vec![+ ("Referer".to_string(), "https://hubcloud.one/".to_string()),+ ("User-Agent".to_string(), "Mozilla/5.0".to_string()),+ ],+ subtitle: None,+ source_label: "1080p".to_string(),+ };+ assert_eq!(+ app.resolve_playback_player(&fourk_source),+ super::PlaybackResolution::Available(crate::tui::state::PlayerKind::AndroidIntent)+ );++ let auth_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(),+ };+ assert_eq!(+ app.resolve_playback_player(&auth_source),+ super::PlaybackResolution::ExplicitPlayerIncompatible {+ chosen: crate::tui::state::PlayerKind::AndroidIntent,+ compatible_alternatives: vec![],+ }+ );+ }}