Skip to content

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

chore: extend network timeout, remove unused log screen

Samir Hossainse45b076149bf
diff --git a/src/providers/moviebox/client.rs b/src/providers/moviebox/client.rs
index 16a004c..607a0d4 100644
--- a/src/providers/moviebox/client.rs
+++ b/src/providers/moviebox/client.rs
@@ -49,7 +49,7 @@ impl Default for MovieBoxClient {
impl MovieBoxClient {
pub fn new() -> Self {
let client = reqwest::Client::builder()
- .timeout(std::time::Duration::from_secs(5))
+ .timeout(std::time::Duration::from_secs(12))
.connect_timeout(std::time::Duration::from_secs(3))
.build()
.expect("Failed to build reqwest client; TLS backend may be missing");
diff --git a/src/providers/moviebox/mod.rs b/src/providers/moviebox/mod.rs
index 491846f..e6b59c4 100644
--- a/src/providers/moviebox/mod.rs
+++ b/src/providers/moviebox/mod.rs
@@ -141,8 +141,19 @@ impl MovieBoxClient {
Err(ScraperError::ApiStatus(404))
}
} else {
+ let mut seen_links = std::collections::HashSet::new();
+ let mut unique_list = Vec::new();
+ for item in all_list {
+ if let Some(link) = item.get("resourceLink").and_then(|l| l.as_str()) {
+ if seen_links.insert(link.to_string()) {
+ unique_list.push(item);
+ }
+ } else {
+ unique_list.push(item);
+ }
+ }
let mut combined = serde_json::Map::new();
- combined.insert("list".to_string(), serde_json::Value::Array(all_list));
+ combined.insert("list".to_string(), serde_json::Value::Array(unique_list));
Ok(serde_json::Value::Object(combined))
}
}
diff --git a/src/tui/app.rs b/src/tui/app.rs
index 80daf72..ca7f54f 100644
--- a/src/tui/app.rs
+++ b/src/tui/app.rs
@@ -124,7 +124,7 @@ impl App {
}
self.state.image_picker = Some(picker);
- std::thread::sleep(std::time::Duration::from_millis(30));
+ tokio::time::sleep(std::time::Duration::from_millis(30)).await;
while crossterm::event::poll(std::time::Duration::ZERO).unwrap_or(false) {
let _ = crossterm::event::read();
}
@@ -254,10 +254,8 @@ impl App {
Action::FocusChange => {
self.state.poster_protocol = None;
self.state.search_poster_protocols.clear();
- self.state.selected_resources = None;
- self.state.resource_list_state.select(None);
if self.state.image_picker.is_some() {
- std::thread::sleep(std::time::Duration::from_millis(30));
+ tokio::time::sleep(std::time::Duration::from_millis(30)).await;
while crossterm::event::poll(std::time::Duration::ZERO).unwrap_or(false) {
let _ = crossterm::event::read();
}
@@ -267,7 +265,7 @@ impl App {
self.state.poster_protocol = None;
self.state.search_poster_protocols.clear();
if self.state.image_picker.is_some() {
- std::thread::sleep(std::time::Duration::from_millis(30));
+ tokio::time::sleep(std::time::Duration::from_millis(30)).await;
while crossterm::event::poll(std::time::Duration::ZERO).unwrap_or(false) {
let _ = crossterm::event::read();
}
@@ -281,9 +279,6 @@ impl App {
KeyCode::Char('c') => {
self.action_sender.send(Action::Quit).ok();
return Some(());
- }
- KeyCode::Char('l') => {
-
}
_ => {}
}
@@ -409,6 +404,13 @@ impl App {
KeyCode::Char('d') | KeyCode::Char('D') => {
self.action_sender.send(Action::DownloadStream).ok();
}
+ KeyCode::Char('R') => {
+ if let Some(id) = self.state.active_subject_id.clone() {
+ let se = if self.state.available_seasons.is_empty() { 0 } else { self.state.selected_season };
+ let ep = if self.state.available_seasons.is_empty() { 0 } else { self.state.selected_episode };
+ self.action_sender.send(Action::FetchResources { subject_id: id, season: se, episode: ep }).ok();
+ }
+ }
KeyCode::Char('?') => {
self.action_sender.send(Action::ToggleHelp).ok();
}
@@ -470,7 +472,6 @@ impl App {
}
_ => {}
},
- _ => {}
},
}
}
@@ -509,6 +510,7 @@ impl App {
}
Screen::Details => {
self.state.active_screen = Screen::Home;
+ self.state.is_loading = false;
self.state.language_chosen = false;
self.state.status_message =
"Select a movie/series and press Enter".to_string();
@@ -1057,7 +1059,6 @@ impl App {
}
}
},
- _ => {}
}
}
Action::TabPane => {
@@ -1217,7 +1218,6 @@ impl App {
}
}
},
- _ => {}
}
}
Action::MoveLeft => {
@@ -1367,7 +1367,6 @@ impl App {
Action::FetchDetails(id) => {
self.state.poster_protocol = None;
self.state.is_loading = true;
- self.state.stream_cache.clear();
let client = self.client.clone();
let sender = self.action_sender.clone();
let id_clone = id.clone();
@@ -1511,6 +1510,8 @@ impl App {
}
Action::PreviewFailure(err) => {
self.state.preview_loading = false;
+ self.state.status_message = format!("Preview failed: {}", err);
+ self.state.status_timer = 150;
}
Action::CopyLink => {
@@ -1632,6 +1633,9 @@ impl App {
}
}
Action::DownloadStream => {
+ if self.state.download_progress.is_some() {
+ return None;
+ }
if self.state.active_screen == Screen::Details {
let link_opt = self.get_selected_link();
let title = self
@@ -2323,30 +2327,12 @@ impl App {
}
Action::ShowPlayerPicker(link, subtitle) => {
- let mut players = Vec::new();
- if std::path::Path::new("/Applications/IINA.app").exists()
- || std::process::Command::new("which").arg("iina").output().map(|o| o.status.success()).unwrap_or(false)
- {
- players.push(crate::tui::state::PlayerKind::Iina);
- }
- if std::path::Path::new("/Applications/mpv.app").exists()
- || std::process::Command::new("which").arg("mpv").output().map(|o| o.status.success()).unwrap_or(false)
- {
- players.push(crate::tui::state::PlayerKind::Mpv);
- }
- if std::path::Path::new("/Applications/VLC.app").exists()
- || std::process::Command::new("which").arg("vlc").output().map(|o| o.status.success()).unwrap_or(false)
- {
- players.push(crate::tui::state::PlayerKind::Vlc);
- }
-
- if players.is_empty() {
+ if self.state.available_players.is_empty() {
self.state.toast_message =
Some("✗ No media player found. Install mpv, IINA, or VLC.".to_string());
self.state.toast_timer = 150;
return None;
}
- self.state.available_players = players;
self.state.player_picker_popup = true;
self.state.player_picker_link = Some(link);
self.state.player_picker_subtitle = subtitle;
diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rs
index 7497c89..9408e10 100644
--- a/src/tui/screens/details.rs
+++ b/src/tui/screens/details.rs
@@ -102,11 +102,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.and_then(|c| c.as_str())
.filter(|s| !s.is_empty())
.unwrap_or("N/A");
- let _content_rating = details_json
- .get("contentRating")
- .and_then(|c| c.as_str())
- .filter(|s| !s.is_empty())
- .unwrap_or("N/A");
+
let imdb_rating = details_json
.get("imdbRatingValue")
.and_then(|r| {
diff --git a/src/tui/screens/logs.rs b/src/tui/screens/logs.rs
deleted file mode 100644
index 240baa8..0000000
--- a/src/tui/screens/logs.rs
+++ /dev/null
@@ -1,46 +0,0 @@
-use crate::tui::{state::AppState, theme::Theme};
-use ratatui::{
- Frame,
- layout::Rect,
- widgets::{Block, Borders, Clear, List, ListItem},
-};
-
-pub fn draw(frame: &mut Frame, area: Rect, state: &AppState, theme: &Theme) {
- let popup_layout = ratatui::layout::Layout::default()
- .direction(ratatui::layout::Direction::Vertical)
- .constraints([
- ratatui::layout::Constraint::Percentage(20),
- ratatui::layout::Constraint::Percentage(60),
- ratatui::layout::Constraint::Percentage(20),
- ])
- .split(area);
-
- let popup_area = ratatui::layout::Layout::default()
- .direction(ratatui::layout::Direction::Horizontal)
- .constraints([
- ratatui::layout::Constraint::Percentage(15),
- ratatui::layout::Constraint::Percentage(70),
- ratatui::layout::Constraint::Percentage(15),
- ])
- .split(popup_layout[1])[1];
-
- frame.render_widget(Clear, popup_area);
-
- let list_items: Vec<ListItem> = state
- .logs
- .iter()
- .map(|log| ListItem::new(log.as_str()))
- .collect();
-
- let logs_block = Block::default()
- .borders(Borders::ALL)
- .title(" Trace Log Console [Press 'l' to toggle] ")
- .title_style(theme.title)
- .border_style(theme.border_focus);
-
- let logs_list = List::new(list_items)
- .block(logs_block)
- .style(theme.text_dim);
-
- frame.render_widget(logs_list, popup_area);
-}
diff --git a/src/tui/state.rs b/src/tui/state.rs
index 40295d1..998e38c 100644
--- a/src/tui/state.rs
+++ b/src/tui/state.rs
@@ -163,7 +163,25 @@ impl Default for AppState {
player_picker_state: ListState::default(),
player_picker_link: None,
player_picker_subtitle: None,
- available_players: Vec::new(),
+ available_players: {
+ let mut players = Vec::new();
+ if std::path::Path::new("/Applications/IINA.app").exists()
+ || std::process::Command::new("which").arg("iina").output().map(|o| o.status.success()).unwrap_or(false)
+ {
+ players.push(PlayerKind::Iina);
+ }
+ if std::path::Path::new("/Applications/mpv.app").exists()
+ || std::process::Command::new("which").arg("mpv").output().map(|o| o.status.success()).unwrap_or(false)
+ {
+ players.push(PlayerKind::Mpv);
+ }
+ if std::path::Path::new("/Applications/VLC.app").exists()
+ || std::process::Command::new("which").arg("vlc").output().map(|o| o.status.success()).unwrap_or(false)
+ {
+ players.push(PlayerKind::Vlc);
+ }
+ players
+ },
is_loading: false,
status_message: String::new(),
status_timer: 0,