Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
fix(download): honor selected stream resolution for dash downloads
Samir Hossains7ca74825d697
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a0aab7a..13e5ea6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,13 @@- Added `vlc_path`, `mpv_path`, and `iina_path` fields to `Config` in `src/config.rs` and `src/tui/state.rs`.- Supported persisted custom player paths with automatic static path cache invalidation upon configuration updates.++### Changed+- **Streamlined Download Failure Notifications**:+ - Replaced verbose, truncated DASH download failure guidance with terse, actionable commands (`Run: winget install yt-dlp.yt-dlp Gyan.FFmpeg`).+ - Removed misleading "Partial file preserved" prefix on pre-download failures in `src/tui/app/download.rs`.+ - Scaled notification toast card width to the widest line across multi-line messages in `src/tui/overlay.rs`.+ - Threaded selected stream resolution constraint (`bestvideo[height<={h}]...`) to `yt-dlp` in `src/tui/app/download.rs`, ensuring DASH downloads fetch the highlighted quality rather than forcing 1080p.### Fixed- **Streaming Proxy & Sidecar Lifecycle**:- Enforced fail-closed target host verification in `src/proxy.rs`, rejecting requests with `403 Forbidden` if `target_host` is missing or unverified.diff --git a/docs/downloads.md b/docs/downloads.mdindex 206aa14..96cf467 100644--- a/docs/downloads.md+++ b/docs/downloads.md@@ -30,3 +30,14 @@ Upon completion, temporary sidecars are verified and renamed atomically to the t## Header ForwardingAuthenticated streams (such as MovieBox DASH manifests or 4KHDHub mirrors) automatically forward required headers (`User-Agent`, `Referer`, signed CloudFront cookies) to download workers, ensuring CDN transfers complete without `403 Forbidden` errors.++## DASH Streams (`yt-dlp`)++MovieBox DASH streams require `yt-dlp` and `ffmpeg` to download and mux adaptive video/audio representations:++- **Windows**: `winget install yt-dlp.yt-dlp Gyan.FFmpeg`+- **macOS**: `brew install yt-dlp ffmpeg`+- **Android (Termux)**: `pkg install yt-dlp ffmpeg`+- **Linux**: Install `yt-dlp` and `ffmpeg` via system package manager.++All other providers (4KHDHub, BDIX, DhakaFlix, CircleFTP, TV mode) download directly through the internal HTTP engine.diff --git a/src/tui/action.rs b/src/tui/action.rsindex a88dbef..a2a683f 100644--- a/src/tui/action.rs+++ b/src/tui/action.rs@@ -79,7 +79,12 @@ pub enum Action {SelectBrowse(crate::tui::state::BrowsePreset),SelectAddonCatalog(crate::providers::addons::models::AddonCatalogTarget),DownloadStream(Option<String>),- StartDownload(Option<String>, Option<String>, Vec<(String, String)>),+ StartDownload(+ Option<String>,+ Option<String>,+ Vec<(String, String)>,+ Option<u64>,+ ),UpdateDownload(Option<f64>, Option<String>),DownloadCompleted(String),DownloadFailed(String),diff --git a/src/tui/app/download.rs b/src/tui/app/download.rsindex 1ade760..6d1fede 100644--- a/src/tui/app/download.rs+++ b/src/tui/app/download.rs@@ -12,6 +12,7 @@ impl App {subtitle_url: Option<String>,link: Option<String>,headers: Vec<(String, String)>,+ max_height: Option<u64>,) {if self.state.download_progress.is_some() || self.state.active_screen != Screen::Details {return;@@ -265,8 +266,9 @@ impl App {cmd.arg("--add-header").arg(format!("{clean_k}: {clean_v}"));}}+ let format_spec = ytdlp_format_selector(max_height);cmd.arg("-f")- .arg("bestvideo+bestaudio/best")+ .arg(format_spec).arg("--newline").arg("--part").arg("-o")@@ -537,11 +539,13 @@ impl App {|| release.provider == ProviderKind::BdixDhakaFlix{let sender_clone = self.action_sender.clone();+ let max_height = Some(release.resolution_u64()).filter(|&h| h > 0);sender_clone.send(Action::StartDownload(subtitle_url,Some(first_mirror.resolver_url.clone()),first_mirror.headers.clone(),+ max_height,)).ok();return None;@@ -571,11 +575,14 @@ impl App {.await;match result {Ok(Ok(source)) => {+ let max_height =+ Some(release.resolution_u64()).filter(|&h| h > 0);sender.send(Action::StartDownload(subtitle_url,Some(source.url),source.headers,+ max_height,)).ok();}@@ -600,7 +607,7 @@ impl App {});} else {self.action_sender- .send(Action::StartDownload(subtitle_url, None, Vec::new()))+ .send(Action::StartDownload(subtitle_url, None, Vec::new(), None)).ok();}} else {@@ -611,15 +618,24 @@ impl App {.and_then(|r| r.mirrors.first()).map(|m| m.headers.clone()).unwrap_or_default();+ let max_height = release+ .as_ref()+ .map(|r| r.resolution_u64())+ .filter(|&h| h > 0);self.action_sender- .send(Action::StartDownload(subtitle_url, link, headers))+ .send(Action::StartDownload(+ subtitle_url,+ link,+ headers,+ max_height,+ )).ok();}return None;}- Action::StartDownload(subtitle_url, link, headers) => {+ Action::StartDownload(subtitle_url, link, headers, max_height) => {self.state.is_resolving_playback = false;- self.start_resilient_download(subtitle_url, link, headers);+ self.start_resilient_download(subtitle_url, link, headers, max_height);return None;}Action::DownloadEpisode => {@@ -793,11 +809,8 @@ impl App {format!("{completed}/{total} files finished before error: {error}"),);} else {- self.state.notify(- NotificationKind::Error,- "Download failed",- format!("Partial file preserved. {error}"),- );+ self.state+ .notify(NotificationKind::Error, "Download failed", error);}self.state.download_queue.clear();self.state.download_queue_total = 0;@@ -998,15 +1011,25 @@ async fn prepare_target_dir(}pub(crate) fn yt_dlp_missing_guidance() -> String {if crate::updater::artifact::is_termux_environment() {- "MovieBox DASH streams require yt-dlp. Please install yt-dlp and ffmpeg on your device (e.g. 'pkg install yt-dlp ffmpeg') to download these streams.".to_string()+ "DASH streams require yt-dlp & ffmpeg.\nRun: pkg install yt-dlp ffmpeg".to_string()} else if cfg!(target_os = "macos") {- "MovieBox DASH streams require yt-dlp. Please install yt-dlp and ffmpeg on your Mac (e.g. 'brew install yt-dlp ffmpeg') to download these streams.".to_string()+ "DASH streams require yt-dlp & ffmpeg.\nRun: brew install yt-dlp ffmpeg".to_string()} else if cfg!(target_os = "windows") {- "MovieBox DASH streams require yt-dlp. Please install yt-dlp and ffmpeg on your system (e.g. 'winget install yt-dlp.yt-dlp Gyan.FFmpeg') to download these streams.".to_string()+ "DASH streams require yt-dlp & ffmpeg.\nRun: winget install yt-dlp.yt-dlp Gyan.FFmpeg"+ .to_string()} else if cfg!(target_os = "linux") {- "MovieBox DASH streams require yt-dlp. Please install yt-dlp and ffmpeg via your system package manager to download these streams.".to_string()+ "DASH streams require yt-dlp & ffmpeg.\nInstall via system package manager".to_string()+ } else {+ "DASH streams require yt-dlp & ffmpeg.".to_string()+ }+}+pub(crate) fn ytdlp_format_selector(max_height: Option<u64>) -> String {+ if let Some(height) = max_height.filter(|&h| h > 0) {+ format!(+ "bestvideo[height<={height}]+bestaudio/best[height<={height}]/bestvideo+bestaudio/best"+ )} else {- "MovieBox DASH streams require yt-dlp. Please install yt-dlp and ffmpeg on your system to download these streams.".to_string()+ "bestvideo+bestaudio/best".to_string()}}@@ -1093,6 +1116,7 @@ pub(crate) fn parse_ytdlp_progress(line: &str) -> Option<(f64, String)> {#[cfg(test)]mod tests {+ use super::*;use crate::providers::models::{ProviderKind, Release, SourceMirror};use crate::tui::action::Action;use crate::tui::app::App;@@ -1195,8 +1219,11 @@ mod tests {#[test]fn test_yt_dlp_missing_guidance_contains_platform_hint() {let guidance = super::yt_dlp_missing_guidance();- assert!(guidance.contains("MovieBox DASH streams require yt-dlp"));- assert!(guidance.contains("install yt-dlp and ffmpeg"));+ assert!(guidance.contains("DASH streams require yt-dlp & ffmpeg"));+ #[cfg(target_os = "macos")]+ assert!(guidance.contains("brew install yt-dlp ffmpeg"));+ #[cfg(target_os = "windows")]+ assert!(guidance.contains("winget install yt-dlp.yt-dlp Gyan.FFmpeg"));}#[tokio::test]@@ -1230,7 +1257,8 @@ mod tests {let dispatched = app.action_receiver.try_recv().expect("action dispatched");match dispatched {- Action::StartDownload(_, link, headers) => {+ Action::StartDownload(_, link, headers, max_height) => {+ assert_eq!(max_height, Some(1080));assert_eq!(link.as_deref(),Some("https://example.com/dash/123/index.mpd")@@ -1244,6 +1272,129 @@ mod tests {other => panic!("expected StartDownload, got {:?}", other),}}+ #[tokio::test]+ async fn test_download_stream_respects_highlighted_resolution() {+ let mut app = App::new();+ app.state.active_provider = ProviderKind::MovieBox;+ app.state.active_screen = Screen::Details;+ app.state.selected_resources = vec![+ Release {+ provider: ProviderKind::MovieBox,+ filename: "Ek Deewane Ki Deewaniyat 1080p HEVC".to_string(),+ quality: Some("1080p".to_string()),+ codec: Some("hevc".to_string()),+ language: None,+ size_bytes: Some(1_600_000_000),+ season: None,+ episode: None,+ mirrors: vec![SourceMirror {+ label: "1080p HEVC".to_string(),+ resolver_url: "https://example.com/dash/123/index.mpd".to_string(),+ headers: vec![],+ direct_file: true,+ }],+ resource_id: Some("123".to_string()),+ },+ Release {+ provider: ProviderKind::MovieBox,+ filename: "Ek Deewane Ki Deewaniyat 720p HEVC".to_string(),+ quality: Some("720p".to_string()),+ codec: Some("hevc".to_string()),+ language: None,+ size_bytes: Some(839_000_000),+ season: None,+ episode: None,+ mirrors: vec![SourceMirror {+ label: "720p HEVC".to_string(),+ resolver_url: "https://example.com/dash/123/index.mpd".to_string(),+ headers: vec![],+ direct_file: true,+ }],+ resource_id: Some("123".to_string()),+ },+ Release {+ provider: ProviderKind::MovieBox,+ filename: "Ek Deewane Ki Deewaniyat 480p HEVC".to_string(),+ quality: Some("480p".to_string()),+ codec: Some("hevc".to_string()),+ language: None,+ size_bytes: Some(438_000_000),+ season: None,+ episode: None,+ mirrors: vec![SourceMirror {+ label: "480p HEVC".to_string(),+ resolver_url: "https://example.com/dash/123/index.mpd".to_string(),+ headers: vec![],+ direct_file: true,+ }],+ resource_id: Some("123".to_string()),+ },+ ];++ app.state.resource_list_state.select(Some(2));+ assert_eq!(+ app.get_selected_release().unwrap().quality.as_deref(),+ Some("480p")+ );++ app.handle_download(Action::DownloadStream(None)).await;++ let dispatched = app.action_receiver.try_recv().expect("action dispatched");+ match dispatched {+ Action::StartDownload(_, link, _, max_height) => {+ assert_eq!(+ link.as_deref(),+ Some("https://example.com/dash/123/index.mpd")+ );+ assert_eq!(max_height, Some(480));+ let format_spec = ytdlp_format_selector(max_height);+ assert_eq!(+ format_spec,+ "bestvideo[height<=480]+bestaudio/best[height<=480]/bestvideo+bestaudio/best"+ );+ }+ other => panic!("expected StartDownload, got {:?}", other),+ }+ app.state.is_resolving_playback = false;+ app.state.resource_list_state.select(Some(1));+ assert_eq!(+ app.get_selected_release().unwrap().quality.as_deref(),+ Some("720p")+ );++ app.handle_download(Action::DownloadStream(None)).await;++ let dispatched = app.action_receiver.try_recv().expect("action dispatched");+ match dispatched {+ Action::StartDownload(_, _, _, max_height) => {+ assert_eq!(max_height, Some(720));+ let format_spec = ytdlp_format_selector(max_height);+ assert_eq!(+ format_spec,+ "bestvideo[height<=720]+bestaudio/best[height<=720]/bestvideo+bestaudio/best"+ );+ }+ other => panic!("expected StartDownload, got {:?}", other),+ }+ }++ #[test]+ fn test_ytdlp_format_selector_specs() {+ assert_eq!(+ ytdlp_format_selector(Some(480)),+ "bestvideo[height<=480]+bestaudio/best[height<=480]/bestvideo+bestaudio/best"+ );+ assert_eq!(+ ytdlp_format_selector(Some(720)),+ "bestvideo[height<=720]+bestaudio/best[height<=720]/bestvideo+bestaudio/best"+ );+ assert_eq!(+ ytdlp_format_selector(Some(1080)),+ "bestvideo[height<=1080]+bestaudio/best[height<=1080]/bestvideo+bestaudio/best"+ );+ assert_eq!(ytdlp_format_selector(None), "bestvideo+bestaudio/best");+ assert_eq!(ytdlp_format_selector(Some(0)), "bestvideo+bestaudio/best");+ }#[test]fn test_download_directory_and_filename_conventions() {let base_dir = std::path::PathBuf::from("/tmp/MovieBox-TUI");diff --git a/src/tui/overlay.rs b/src/tui/overlay.rsindex bd9d9e0..7baaa92 100644--- a/src/tui/overlay.rs+++ b/src/tui/overlay.rs@@ -460,7 +460,13 @@ pub fn notifications(let title_w = crate::tui::text::width(¬ification.title).saturating_add(6);let badge_w = crate::tui::text::width(badge).saturating_add(6);let raw_msg_w = if has_message {- crate::tui::text::width(¬ification.message).saturating_add(6)+ notification+ .message+ .lines()+ .map(|line| crate::tui::text::width(line.trim()))+ .max()+ .unwrap_or(0)+ .saturating_add(6)} else {0};@@ -700,7 +706,13 @@ pub fn notification_rects(let title_w = crate::tui::text::width(¬ification.title).saturating_add(6);let badge_w = crate::tui::text::width(badge).saturating_add(6);let raw_msg_w = if has_message {- crate::tui::text::width(¬ification.message).saturating_add(6)+ notification+ .message+ .lines()+ .map(|line| crate::tui::text::width(line.trim()))+ .max()+ .unwrap_or(0)+ .saturating_add(6)} else {0};@@ -1088,6 +1100,21 @@ mod tests {assert!(rects[0].1.height >= 5);}#[test]+ fn test_notification_rects_multiline_width_scales_to_longest_line() {+ let mut queue = std::collections::VecDeque::new();+ queue.push_back(Notification::new(+ NotificationKind::Error,+ "Download failed",+ "DASH streams require yt-dlp & ffmpeg.\nRun: winget install yt-dlp.yt-dlp Gyan.FFmpeg",+ ));+ let area = Rect::new(0, 0, 100, 30);+ let rects = notification_rects(area, &queue, false, false);+ assert_eq!(rects.len(), 1);+ assert!(rects[0].1.width >= 48);+ assert!(rects[0].1.width <= 64);+ assert_eq!(rects[0].1.height, 5);+ }+ #[test]fn test_addon_manager_layout_anchors_at_search_bar_position() {let standard_area = Rect::new(0, 0, 80, 24);let layout = addon_manager_layout(standard_area, 2, 10, false);