Skip to content

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

fix(providers): add rate-limit backoff and accurate stream error diagnostics

Samir Hossains442d135ce592
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d370893..d5a08c1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,17 @@
# Changelog
+## [Unreleased]
+
+### Fixed
+- **Transparent Stream & Search Diagnostics**:
+ - Replaced misleading generic `"No matches"` and `"Rate Limit"` errors with truthful, contextual diagnostics: `"No stream sources available on {provider}"`, `"Network connection failed to {provider}"`, `"Rate limited by {provider}"`, and `"Episode S{season}E{episode} is not listed on {provider}"`.
+ - Added helpful actionable hints (`Press Ctrl+P to try another provider, or r to refresh`).
+- **Rate-Limiting & Concurrency Hardening**:
+ - Added HTTP 429 `Retry-After` header parsing with bounded exponential backoff in `MovieBoxClient`.
+ - Added semaphore concurrency limiting (`Semaphore::new(2)`) during parallel episode page resolution to prevent burst requests from tripping provider rate limiters.
+- **Selector Tab Preservation in Standard Displays**:
+ - Maintained visibility of Audio Languages, Seasons, and Episodes selector tabs side-by-side in standard ~80-column terminals when focusing Streams, preventing tabs from disappearing when 0 streams are available.
+
## [0.1.12] - 2026-08-15
### Added
@@ -108,74 +120,5 @@
### Refactored
- **Domain Modularization**: Split the application monolith into cohesive domain modules (`network`, `playback`, `download`, `requests`, `navigation`, `tv`, `system`, `keyboard`).
-- **Provider Architecture**: Introduced typed contract models and unified `Provider` / `ReleaseProvider` seams.
-
-### Fixed
-- Added request generation IDs to invalidate stale asynchronous network and preview responses.
-- Hardened MovieBox HMAC-MD5 request signing and runtime token initialization.
-- Preserved upstream subtitle sidecar file extensions (`.srt`, `.vtt`, `.ass`, `.sub`).
-
-## [0.1.10] - 2026-08-06
-
-### Added
-- **BDIX Integration**: Added CircleFTP and DhakaFlix provider scrapers with isolated cache namespaces.
-- **Native Android Support**: Added Android Intent media player dispatch and shared storage download directory detection.
-- **BDIX Commands**: Added `/enable-bdix` and `/disable-bdix` slash commands with search autocomplete.
-
-### Fixed
-- Fixed subtitle loading in IINA player.
-- Fixed help menu text truncation on small terminal viewports.
-
-## [0.1.9] - 2026-08-05
-
-### Added
-- **Watch History**: Added persistent watch history tracking via `/history` with automatic deduplication.
-- **Update Checker**: Added in-app update notification popup with release information.
-- **Subtitle Caching**: Added caching layer for MovieBox stream subtitles.
-
-### Fixed
-- Updated 4kHDHub mirror resolution for new HubCloud domains and anti-bot challenges.
-- Prevented playback resolution request spam on rapid navigation keystrokes.
-
-## [0.1.8] - 2026-08-02
-
-### Added
-- **Theme Switcher**: Added interactive theme picker popup with configuration persistence in `config.json`.
-- **Homebrew Support**: Created official Homebrew tap formula with automated release updates.
-- **Flatpak Support**: Added automatic detection for Flatpak-installed mpv and VLC players on Linux.
-
-### Performance
-- Migrated TUI event loop to bounded asynchronous channels.
-- Added disk caching for provider media details during list preview loading.
-
-## [0.1.7] - 2026-07-31
-
-### Added
-- **4KHDHub Provider**: Added secondary 4K content provider with HubCloud mirror resolver and preflight validation.
-- **Bi-directional Navigation**: Added `Tab` and `Shift+Tab` pane switching on the Details screen.
-- **Stream Caching**: Added in-memory stream caching with atomic disk writes.
-- **Terminal Capabilities**: Added Sixel graphics and adaptive terminal layout detection.
-
-### Fixed
-- Managed temporary subtitle file lifecycle with delayed cleanup after player process initialization.
-- Centered poster images vertically on wide terminal viewports.
-
-## [0.1.6] - 2026-07-26
-
-### Added
-- **Live TV (IPTV) Mode**: Added IPTV live channel streaming with M3U parser and category groupings.
-- **Confirmation Dialogs**: Added confirmation modals for season and episode downloads.
-- **Player Picker**: Added interactive media player picker popup (`o` key).
-- **Linux ARM64**: Added native build and install support for aarch64 Linux systems.
-
-### Fixed
-- Enhanced download engine with HTTP range requests, timeout handling, and chunk validation.
-
-## [0.1.5] - 2026-07-23
-
-### Added
-- Initial tagged release:
- - Search, browse, stream, and download movies, series, and anime.
- - External player integration for mpv, VLC, and IINA.
- - Subtitle track picker and automated downloading.
- - Basic terminal ASCII fallback mode.
+- **State Decomposition**: Split the monolithic application state into specialized domain state structs.
+- **Strict Verification Gates**: Enforced workspace lint checks, static analysis, and testing.
diff --git a/src/providers/moviebox/client.rs b/src/providers/moviebox/client.rs
index 74ec413..60c81d0 100644
--- a/src/providers/moviebox/client.rs
+++ b/src/providers/moviebox/client.rs
@@ -150,10 +150,12 @@ impl MovieBoxClient {
body: Option<&str>,
) -> Result<Value, ScraperError> {
let start_idx = self.active_base_idx.load(Ordering::Relaxed);
+ let mut backoff_ms: u64 = 50;
for i in 0..HOST_POOL.len() {
if i > 0 {
- tokio::time::sleep(std::time::Duration::from_millis(50)).await;
+ tokio::time::sleep(std::time::Duration::from_millis(backoff_ms)).await;
+ backoff_ms = 50;
}
let idx = (start_idx + i) % HOST_POOL.len();
let base = HOST_POOL[idx];
@@ -194,6 +196,15 @@ impl MovieBoxClient {
"moviebox host {idx} returned retryable status {status}: {}",
crate::logging::sanitize_url(&url)
);
+ if status == 429 {
+ backoff_ms = resp
+ .headers()
+ .get(reqwest::header::RETRY_AFTER)
+ .and_then(|v| v.to_str().ok())
+ .and_then(|v| v.parse::<u64>().ok())
+ .map(|secs| secs.saturating_mul(1000).min(3000))
+ .unwrap_or(400);
+ }
continue;
}
diff --git a/src/tui/app/requests.rs b/src/tui/app/requests.rs
index b322184..5e415d7 100644
--- a/src/tui/app/requests.rs
+++ b/src/tui/app/requests.rs
@@ -1425,6 +1425,7 @@ impl App {
let mut all_items: Vec<serde_json::Value> = Vec::new();
let mut found_target = false;
+ let mut any_fetch_failed = false;
if is_movie {
let mut page = 1usize;
@@ -1452,10 +1453,14 @@ impl App {
break;
}
}
- _ => break,
+ _ => {
+ any_fetch_failed = true;
+ break;
+ }
}
}
} else {
+ let concurrency_limit = std::sync::Arc::new(tokio::sync::Semaphore::new(2));
let mut page = estimated_page;
'outer: loop {
if cancel_token.load(std::sync::atomic::Ordering::Relaxed) {
@@ -1473,9 +1478,11 @@ impl App {
let c = client.clone();
let id = id_clone.clone();
let ct = cancel_token.clone();
+ let permit = concurrency_limit.clone();
page_handles.push(tokio::spawn(async move {
+ let _permit = permit.acquire_owned().await.ok();
if ct.load(std::sync::atomic::Ordering::Relaxed) {
- return (Vec::new(), serde_json::json!({}));
+ return (Vec::new(), serde_json::json!({}), false);
}
match tokio::time::timeout(
std::time::Duration::from_secs(15),
@@ -1483,8 +1490,8 @@ impl App {
)
.await
{
- Ok(Ok((items, pager))) => (items, pager),
- _ => (Vec::new(), serde_json::json!({})),
+ Ok(Ok((items, pager))) => (items, pager, true),
+ _ => (Vec::new(), serde_json::json!({}), false),
}
}));
}
@@ -1492,7 +1499,10 @@ impl App {
let mut page_empty = true;
let mut has_more = false;
for handle in page_handles {
- if let Ok((items, pager)) = handle.await {
+ if let Ok((items, pager, ok)) = handle.await {
+ if !ok {
+ any_fetch_failed = true;
+ }
if !items.is_empty() {
page_empty = false;
}
@@ -1535,12 +1545,16 @@ impl App {
};
if !target_ok || all_items.is_empty() {
- let err_msg = if all_items.is_empty() {
- "No matches"
+ let provider_name = context.provider.label();
+ let err_msg = if any_fetch_failed && all_items.is_empty() {
+ format!("Network connection failed to {provider_name}")
+ } else if any_fetch_failed {
+ format!("Rate limited by {provider_name}")
+ } else if all_items.is_empty() {
+ format!("No stream sources available on {provider_name}")
} else {
- "Rate Limit"
- }
- .into();
+ format!("Episode S{season}E{episode} is not listed on {provider_name}")
+ };
sender
.send(Action::EpisodeStreamsFailed(
context, request_id, id_clone, season, episode, err_msg,
diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rs
index f9cbef7..1482651 100644
--- a/src/tui/screens/details.rs
+++ b/src/tui/screens/details.rs
@@ -451,16 +451,15 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
available_selector_panes.push(crate::tui::state::DetailsPane::Episodes);
}
- let visible_selector_panes =
- if matches!(tier, DetailsLayoutTier::Narrow | DetailsLayoutTier::Tiny) {
- available_selector_panes
- .iter()
- .copied()
- .filter(|pane| *pane == state.details_pane)
- .collect::<Vec<_>>()
- } else {
- available_selector_panes
- };
+ let visible_selector_panes = if matches!(tier, DetailsLayoutTier::Tiny) {
+ available_selector_panes
+ .iter()
+ .copied()
+ .filter(|pane| *pane == state.details_pane)
+ .collect::<Vec<_>>()
+ } else {
+ available_selector_panes
+ };
let selector_height = if visible_selector_panes.is_empty() {
0
@@ -979,10 +978,18 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.and_then(|d| d.get("dubs"))
.and_then(|d| d.as_array())
.is_some_and(|a| a.len() > 1);
+ let provider_label = state
+ .active_subject_id
+ .as_deref()
+ .map(|id| subject_provider(state, id).label())
+ .unwrap_or_else(|| state.active_provider.label());
+
let msg = if has_multiple_dubs && !state.language_chosen {
- "Choose an audio track to load streams."
+ "Choose an audio track to load streams.".to_string()
} else {
- "No streams found — press r to retry."
+ format!(
+ "No stream sources found on {provider_label} — press Ctrl+P to try another provider, or r to retry."
+ )
};
let inner = streams_block.inner(streams_area);
@@ -1009,7 +1016,11 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let msg = if waiting_for_language {
"Choose an audio track to load streams.".to_string()
} else if let Some(error) = &state.stream_error {
- format!("{error} — press r to retry.")
+ if error.contains("No stream sources") || error.contains("not listed") {
+ format!("{error}.\nPress Ctrl+P to try another provider, or r to refresh.")
+ } else {
+ format!("{error} — press r to retry or Ctrl+P to switch provider.")
+ }
} else {
let dots = match (state.tick_count / 4) % 4 {
0 => "",
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index c363d54..d35592c 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -179,11 +179,18 @@ fn render_search_state(
}
SearchViewState::Error => {
let symbol = if state.basic_terminal { "!" } else { "×" };
+ let err_text = state.search_error.as_deref().unwrap_or_else(|| {
+ if !state.status_message.is_empty() {
+ &state.status_message
+ } else {
+ "Search request failed"
+ }
+ });
Line::from(vec![
Span::styled(format!("{symbol} "), theme.error),
Span::styled(
crate::tui::text::truncate_width(
- &state.status_message,
+ err_text,
card_width.saturating_sub(4) as usize,
),
theme.error,