Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
feat: implement intelligent search deduplication, improve stream resolution tracking, and enhance TUI home screen aesthetics
Samir Hossainsa94dadce0ef2
diff --git a/Cargo.lock b/Cargo.lockindex 11f59b9..250aa35 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -41,6 +41,15 @@ version = "0.2.21"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"+[[package]]+name = "android_system_properties"+version = "0.1.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"+dependencies = [+ "libc",+]+[[package]]name = "anyhow"version = "1.0.104"@@ -377,6 +386,19 @@ dependencies = ["rand_core 0.10.1",]+[[package]]+name = "chrono"+version = "0.4.45"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"+dependencies = [+ "iana-time-zone",+ "js-sys",+ "num-traits",+ "wasm-bindgen",+ "windows-link",+]+[[package]]name = "clipboard-win"version = "5.4.1"@@ -1285,6 +1307,30 @@ dependencies = ["windows-registry",]+[[package]]+name = "iana-time-zone"+version = "0.1.65"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"+dependencies = [+ "android_system_properties",+ "core-foundation-sys",+ "iana-time-zone-haiku",+ "js-sys",+ "log",+ "wasm-bindgen",+ "windows-core",+]++[[package]]+name = "iana-time-zone-haiku"+version = "0.1.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"+dependencies = [+ "cc",+]+[[package]]name = "icu_collections"version = "2.1.1"@@ -1800,6 +1846,7 @@ version = "0.1.4"dependencies = ["arboard","base64",+ "chrono","crossterm","dirs","hmac",@@ -3000,9 +3047,9 @@ dependencies = [[[package]]name = "rustls-pki-types"-version = "1.15.0"+version = "1.15.1"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "764899a24af3980067ee14bc143654f297b22eaebfe3c7b6b211920a5a59b046"+checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96"dependencies = ["web-time","zeroize",diff --git a/Cargo.toml b/Cargo.tomlindex f4fa810..4c38827 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -15,6 +15,7 @@ rust-version = "1.85.0"[dependencies]arboard = "3.6.1"base64 = "0.22.1"+chrono = "0.4.45"crossterm = "0.29.0"dirs = "6.0.0"hmac = "0.13.0"diff --git a/src/tui/app.rs b/src/tui/app.rsindex 562444a..fd59681 100644--- a/src/tui/app.rs+++ b/src/tui/app.rs@@ -776,19 +776,54 @@ impl App {}).map(|s| s.to_string());- let is_duplicate = self.state.search_results.iter().any(|r| {+ let season =+ item.get("season").and_then(|s| s.as_u64()).unwrap_or(0) as usize;++ if let Some(existing) =+ self.state.search_results.iter_mut().find(|r| r.id == id)+ {+ if season > existing.season {+ existing.season = season;+ existing.title = clean_title;+ existing.stype = stype;+ existing.release_year = release_year;+ existing.cover_url = cover_url;+ }+ continue;+ }++ let raw_lower = raw_title.to_lowercase();+ let is_dub = raw_lower.contains("[hindi]")+ || raw_lower.contains("[tamil]")+ || raw_lower.contains("[telugu]")+ || raw_lower.contains("[english]");++ if is_dub+ && self+ .state+ .search_results+ .iter()+ .any(|r| r.title == clean_title && r.stype == stype)+ {+ continue;+ }++ if self.state.search_results.iter().any(|r| {r.title == clean_title&& r.release_year == release_year&& r.stype == stype- });+ }) {+ continue;+ }- if !id.is_empty() && !is_duplicate {+ if !id.is_empty() {self.state.search_results.push(SearchResult {id,title: clean_title,stype,release_year,cover_url,+ season,});count += 1;}@@ -949,6 +984,43 @@ impl App {.and_then(|u| u.as_str()).map(|s| s.to_string());+ let season = item.get("season").and_then(|s| s.as_u64()).unwrap_or(0) as usize;++ if let Some(existing) =+ self.state.search_results.iter_mut().find(|r| r.id == id)+ {+ if season > existing.season {+ existing.season = season;+ existing.title = clean_title;+ existing.stype = stype;+ existing.release_year = release_year;+ existing.cover_url = cover_url;+ }+ continue;+ }++ let raw_lower = raw_title.to_lowercase();+ let is_dub = raw_lower.contains("[hindi]")+ || raw_lower.contains("[tamil]")+ || raw_lower.contains("[telugu]")+ || raw_lower.contains("[english]");++ if is_dub+ && self+ .state+ .search_results+ .iter()+ .any(|r| r.title == clean_title && r.stype == stype)+ {+ continue;+ }++ if self.state.search_results.iter().any(|r| {+ r.title == clean_title && r.release_year == release_year && r.stype == stype+ }) {+ continue;+ }+if !id.is_empty() {self.state.search_results.push(SearchResult {id,@@ -956,6 +1028,7 @@ impl App {stype,release_year,cover_url,+ season,});count += 1;}@@ -2395,7 +2468,7 @@ impl App {let mut all_items = Vec::new();for h in handles {- if let Ok((res, page, items, pager)) = h.await {+ if let Ok((_res, _page, items, _pager)) = h.await {all_items.extend(items);}}@@ -2426,21 +2499,33 @@ impl App {if let Some(subject_id) = &self.state.active_subject_id {let id = subject_id.clone();if let Some(pool) = self.state.stream_pool.get_mut(&id) {+ let mut actual_resolutions = std::collections::HashSet::new();+for item in raw_list.clone() {- let se = item+ if let Some(r) = item.get("resolution").and_then(|r| r.as_u64()) {+ actual_resolutions.insert(r as u32);+ }++ let mut se = item.get("se").and_then(|v| {v.as_i64().or_else(|| v.as_str().and_then(|s| s.parse().ok()))}).unwrap_or(0) as usize;- let ep = item+ let mut ep = item.get("ep").and_then(|v| {v.as_i64().or_else(|| v.as_str().and_then(|s| s.parse().ok()))}).unwrap_or(0) as usize;++ if target_se == 0 && target_ep == 0 {+ se = 0;+ ep = 0;+ }+let entry = pool.episode_index.entry((se, ep)).or_insert_with(Vec::new);let link = item.get("resourceLink")@@ -2453,6 +2538,13 @@ impl App {}}+ if !actual_resolutions.is_empty() {+ let mut res_vec: Vec<u32> = actual_resolutions.into_iter().collect();+ res_vec.sort_unstable_by(|a, b| b.cmp(a));++ pool.available_resolutions = res_vec;+ }+if let Some(target_streams) =pool.episode_index.get(&(target_se, target_ep)){@@ -2482,7 +2574,7 @@ impl App {self.state.status_message = format!("Resolved {} direct stream sources.", count);self.state.status_timer = 150;}- Action::EpisodeStreamsFailed(season, episode, err) => {+ Action::EpisodeStreamsFailed(_season, _episode, err) => {self.state.is_loading = false;self.state.status_message = format!("Error: {}", err);self.state.status_timer = 150;@@ -2673,7 +2765,6 @@ impl App {if let Some(prog) = self.state.download_progress {use ratatui::layout::{Constraint, Direction, Layout};- use ratatui::style::{Color, Modifier, Style};use ratatui::widgets::{Block, Borders, Gauge};let chunks = Layout::default()@@ -2692,11 +2783,7 @@ impl App {.borders(Borders::ALL).title(format!(" Download: {} [X] Cancel ", status)),)- .gauge_style(- Style::default()- .fg(Color::Cyan)- .add_modifier(Modifier::BOLD),- )+ .gauge_style(self.theme.accent).ratio((prog / 100.0).clamp(0.0, 1.0));frame.render_widget(gauge, chunks[1]);}diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rsindex f85bd39..140dc73 100644--- a/src/tui/screens/home.rs+++ b/src/tui/screens/home.rs@@ -5,76 +5,134 @@ use crate::tui::{use ratatui::{Frame,layout::{Alignment, Constraint, Direction, Layout, Rect},- widgets::{Block, Cell, Paragraph, Row, Table},+ widgets::{Block, Borders, Cell, Paragraph, Row, Table},};pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme) {let show_cursor = (state.tick_count % 16) < 8;+ let search_prefix = if state.basic_terminal { "> " } else { "❯ " };+let search_content =if !state.status_message.is_empty() && state.input_mode == InputMode::Normal {- format!("> {}", state.status_message)+ format!("{}{}", search_prefix, state.status_message)} else if state.search_query.is_empty() {+ use chrono::Timelike;+ let hour = chrono::Local::now().hour();+ let greeting_time = if hour >= 5 && hour < 12 {+ "Good morning"+ } else if hour >= 12 && hour < 17 {+ "Good afternoon"+ } else if hour >= 17 && hour < 21 {+ "Good evening"+ } else {+ "Working late"+ };+ let punct = if greeting_time == "Working late" {+ "?"+ } else {+ ""+ };+ let greeting = format!("{}, {}{}", greeting_time, state.username, punct);+let prompts = [- "Search for a movie...",- "Search for a TV series...",- "Search by genre...",+ "What are you in the mood to watch?",+ "Try 'Oppenheimer', 'Titanic', or 'Interstellar'...",+ "Discover your next binge-worthy masterpiece...",+ "Search for blockbuster movies, hit shows, or anime...",+ "Feeling nostalgic? Search timeless classics...",+ "Explore trending titles for your movie night...",];let type_speed = 3;let del_speed = 1;- let pause1 = 60;+ let pause1 = 90;let pause2 = 15;+ let greeting_cycle =+ greeting.len() * type_speed + pause1 + greeting.len() * del_speed + pause2;+let mut total_ticks = 0;for p in prompts.iter() {total_ticks += p.len() * type_speed + pause1 + p.len() * del_speed + pause2;}- let mut t = (state.tick_count as usize) % total_ticks;++ let tick_u = state.tick_count as usize;let mut animated_text = String::new();- for p in prompts.iter() {- let t_type = p.len() * type_speed;- let t_del = p.len() * del_speed;- let cycle = t_type + pause1 + t_del + pause2;-- if t < cycle {- let display_len = if t < t_type {- t / type_speed- } else if t < t_type + pause1 {- p.len()- } else if t < t_type + pause1 + t_del {- p.len().saturating_sub((t - (t_type + pause1)) / del_speed)- } else {- 0- };- animated_text = p[0..display_len].to_string();- break;++ if tick_u < greeting_cycle {+ let t = tick_u;+ let t_type = greeting.len() * type_speed;+ let t_del = greeting.len() * del_speed;++ let display_len = if t < t_type {+ t / type_speed+ } else if t < t_type + pause1 {+ greeting.len()+ } else if t < t_type + pause1 + t_del {+ greeting+ .len()+ .saturating_sub((t - (t_type + pause1)) / del_speed)} else {- t -= cycle;+ 0+ };+ animated_text = greeting[0..display_len.min(greeting.len())].to_string();+ } else {+ let mut t = (tick_u - greeting_cycle) % total_ticks;+ for p in prompts.iter() {+ let t_type = p.len() * type_speed;+ let t_del = p.len() * del_speed;+ let cycle = t_type + pause1 + t_del + pause2;++ if t < cycle {+ let display_len = if t < t_type {+ t / type_speed+ } else if t < t_type + pause1 {+ p.len()+ } else if t < t_type + pause1 + t_del {+ p.len().saturating_sub((t - (t_type + pause1)) / del_speed)+ } else {+ 0+ };+ animated_text = p[0..display_len.min(p.len())].to_string();+ break;+ } else {+ t -= cycle;+ }}}if state.input_mode == InputMode::Editing {if show_cursor {- format!("> {}█", animated_text)+ format!(+ "{}{}{}█",+ search_prefix,+ animated_text,+ if animated_text.is_empty() { "" } else { "" }+ )} else {- format!("> {} ", animated_text)+ format!(+ "{}{}{} ",+ search_prefix,+ animated_text,+ if animated_text.is_empty() { "" } else { "" }+ )}} else {if show_cursor {- format!("> {}|", animated_text)+ format!("{}{}|", search_prefix, animated_text)} else {- format!("> {} ", animated_text)+ format!("{}{}", search_prefix, animated_text)}}} else {if state.input_mode == InputMode::Editing {if show_cursor {- format!("> {}█", state.search_query)+ format!("{} {}█", search_prefix, state.search_query)} else {- format!("> {} ", state.search_query)+ format!("{} {} ", search_prefix, state.search_query)}} else {- format!("> {}", state.search_query)+ format!("{} {}", search_prefix, state.search_query)}};@@ -97,6 +155,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)} else {4};+let logo_text = if is_narrow {"█▀▄▀█ █▀█ █ █ █ █▀▀ █▀▄ █▀█ ▀▄▀\n█ ▀ █ █▄█ ▀▄▀ █ ██▄ █▄▀ █▄█ █ █"} else if is_wide {@@ -119,8 +178,9 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)Constraint::Percentage(15),Constraint::Length(logo_height),Constraint::Length(1),- Constraint::Percentage(15),- Constraint::Length(1),+ Constraint::Length(2),+ Constraint::Length(3),+ Constraint::Length(3),Constraint::Min(0),Constraint::Length(1),Constraint::Length(1),@@ -153,24 +213,47 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)]).split(vertical_chunks[2]);- let logo_style = if state.tick_count == 1 {- ratatui::style::Style::default().fg(ratatui::style::Color::Rgb(49, 50, 68))- } else if state.tick_count == 2 {- ratatui::style::Style::default().fg(ratatui::style::Color::Rgb(108, 112, 134))- } else {+ let logo_style = if state.basic_terminal || state.tick_count >= 8 {theme.title- };+ } else {+ let t = state.tick_count as f32 / 8.0;- let title_art = Paragraph::new(logo_text)- .alignment(Alignment::Left)- .style(logo_style);+ let r = (49.0 + (203.0 - 49.0) * t) as u8;+ let g = (50.0 + (166.0 - 50.0) * t) as u8;+ let b = (68.0 + (247.0 - 68.0) * t) as u8;+ ratatui::style::Style::default().fg(ratatui::style::Color::Rgb(r, g, b))+ };- frame.render_widget(title_art, horizontal_chunks[1]);+ if is_wide && !state.basic_terminal && state.tick_count < 15 {+ let rows: Vec<&str> = logo_text.split('\n').collect();+ for (i, row) in rows.iter().enumerate() {+ let row_tick_start = 1 + i as u64;+ if state.tick_count >= row_tick_start {+ let row_t = ((state.tick_count - row_tick_start) as f32 / 7.0).clamp(0.0, 1.0);+ let r = (49.0 + (203.0 - 49.0) * row_t) as u8;+ let g = (50.0 + (166.0 - 50.0) * row_t) as u8;+ let b = (68.0 + (247.0 - 68.0) * row_t) as u8;+ let row_style =+ ratatui::style::Style::default().fg(ratatui::style::Color::Rgb(r, g, b));++ let row_area = Rect {+ x: horizontal_chunks[1].x,+ y: horizontal_chunks[1].y + i as u16,+ width: horizontal_chunks[1].width,+ height: 1,+ };+ frame.render_widget(Paragraph::new(*row).style(row_style), row_area);+ }+ }+ } else {+ let title_art = Paragraph::new(logo_text)+ .alignment(Alignment::Left)+ .style(logo_style);+ frame.render_widget(title_art, horizontal_chunks[1]);+ }- let version_style = if state.tick_count == 1 {- ratatui::style::Style::default().fg(ratatui::style::Color::Rgb(49, 50, 68))- } else if state.tick_count == 2 {- ratatui::style::Style::default().fg(ratatui::style::Color::Rgb(108, 112, 134))+ let version_style = if state.tick_count < 6 {+ ratatui::style::Style::default().fg(theme.base)} else {theme.text_dim};@@ -187,7 +270,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)Constraint::Percentage(50),Constraint::Percentage(25),])- .split(vertical_chunks[4]);+ .split(vertical_chunks[5]);search_bar_area = search_chunks[1];@@ -195,15 +278,24 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme).alignment(Alignment::Center).style(match state.input_mode {InputMode::Editing => theme.title,- InputMode::Normal => theme.text,+ InputMode::Normal => theme.text_dim,});frame.render_widget(search_bar, search_bar_area);- let legend = Paragraph::new("Type to Search ↑↓ Browse ? Help")- .alignment(Alignment::Center)- .style(theme.text_dim);- frame.render_widget(legend, vertical_chunks[6]);+ let legend_line = ratatui::text::Line::from(vec![+ ratatui::text::Span::styled(" [Type] ", theme.shortcut),+ ratatui::text::Span::styled("Search ", theme.text_dim),+ ratatui::text::Span::styled("[↑↓] ", theme.shortcut),+ ratatui::text::Span::styled("Browse ", theme.text_dim),+ ratatui::text::Span::styled("[?] ", theme.shortcut),+ ratatui::text::Span::styled("Help ", theme.text_dim),+ ratatui::text::Span::styled("[Esc] ", theme.shortcut),+ ratatui::text::Span::styled("Quit", theme.text_dim),+ ]);++ let legend = Paragraph::new(legend_line).alignment(Alignment::Center);+ frame.render_widget(legend, vertical_chunks[7]);if let Some(version_str) = &state.update_available {let update_text = Paragraph::new(format!(@@ -212,23 +304,39 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme))).alignment(Alignment::Center).style(theme.highlight);- frame.render_widget(update_text, vertical_chunks[7]);+ frame.render_widget(update_text, vertical_chunks[8]);}}} else {let chunks = Layout::default().direction(Direction::Vertical)- .constraints([Constraint::Length(1), Constraint::Min(0)])+ .constraints([Constraint::Length(3), Constraint::Min(0)]).split(area);search_bar_area = chunks[0];+ let border_style = if state.input_mode == InputMode::Editing {+ theme.border_focus+ } else {+ theme.border+ };+let search_bar = Paragraph::new(search_content.clone()).style(match state.input_mode {InputMode::Editing => theme.title,InputMode::Normal => theme.text,})- .block(ratatui::widgets::Block::default().padding(ratatui::widgets::Padding::left(1)));+ .block(+ Block::default()+ .borders(Borders::ALL)+ .border_style(border_style)+ .border_type(if state.basic_terminal {+ ratatui::widgets::BorderType::Plain+ } else {+ ratatui::widgets::BorderType::Rounded+ })+ .padding(ratatui::widgets::Padding::left(1)),+ );frame.render_widget(search_bar, search_bar_area);let list_block = Block::default();@@ -254,9 +362,24 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)]).split(inner_area);- let p = Paragraph::new(format!("{} Searching...", spinner))- .alignment(Alignment::Center)- .style(theme.text_dim);+ let spinner_color = if state.basic_terminal {+ theme.accent+ } else {+ let is_sky = (state.tick_count % 16) < 8;+ if is_sky { theme.accent } else { theme.teal }+ };++ let search_query = if state.search_query.is_empty() {+ "recent...".to_string()+ } else {+ format!("\"{}\"...", state.search_query)+ };++ let p = Paragraph::new(ratatui::text::Line::from(vec![+ ratatui::text::Span::styled(format!("{} Searching for ", spinner), spinner_color),+ ratatui::text::Span::styled(search_query, theme.title),+ ]))+ .alignment(Alignment::Center);frame.render_widget(p, v_chunks[1]);} else if !state.search_results.is_empty() {let selected_idx = state.search_list_state.selected();diff --git a/src/tui/state.rs b/src/tui/state.rsindex d68d645..2f58958 100644--- a/src/tui/state.rs+++ b/src/tui/state.rs@@ -35,6 +35,7 @@ pub struct SearchResult {pub stype: i64,pub release_year: String,pub cover_url: Option<String>,+ pub season: usize,}#[derive(Debug, Default)]@@ -121,6 +122,7 @@ pub struct AppState {pub pending_play_link: Option<String>,pub pending_open_with: bool,pub basic_terminal: bool,+ pub username: String,}impl Default for AppState {@@ -249,6 +251,9 @@ impl Default for AppState {subtitle_list_state: ListState::default(),pending_play_link: None,pending_open_with: false,+ username: std::env::var("USER")+ .or_else(|_| std::env::var("USERNAME"))+ .unwrap_or_else(|_| "Friend".to_string()),}}}diff --git a/src/tui/theme.rs b/src/tui/theme.rsindex b711387..6b06af0 100644--- a/src/tui/theme.rs+++ b/src/tui/theme.rs@@ -16,6 +16,11 @@ pub struct Theme {pub rating: Style,pub accent: Style,pub muted: Style,+ pub teal: Style,+ pub lavender: Style,+ pub sapphire: Style,+ pub subtext1: Style,+ pub base: Color,}impl Default for Theme {@@ -43,6 +48,11 @@ impl Default for Theme {.fg(Color::Rgb(137, 220, 235)).add_modifier(Modifier::BOLD),muted: Style::default().fg(Color::Rgb(88, 91, 112)),+ teal: Style::default().fg(Color::Rgb(148, 226, 213)),+ lavender: Style::default().fg(Color::Rgb(180, 190, 254)),+ sapphire: Style::default().fg(Color::Rgb(116, 199, 236)),+ subtext1: Style::default().fg(Color::Rgb(186, 194, 222)),+ base: Color::Rgb(30, 30, 46),}}}@@ -76,7 +86,7 @@ impl Theme {Self {border: Style::default().fg(Color::DarkGray),border_focus: Style::default().fg(Color::Blue),- text: Style::default().fg(Color::Reset),+ text: Style::default().fg(Color::White),text_dim: Style::default().fg(Color::Gray),title: Style::default().fg(Color::Magenta)@@ -96,6 +106,11 @@ impl Theme {.fg(Color::Cyan).add_modifier(Modifier::BOLD),muted: Style::default().fg(Color::DarkGray),+ teal: Style::default().fg(Color::Cyan),+ lavender: Style::default().fg(Color::Blue),+ sapphire: Style::default().fg(Color::Cyan),+ subtext1: Style::default().fg(Color::White),+ base: Color::Black,}}}