Skip to content

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

feat: enhance TV mode with dynamic configuration wizard, categorized channel grouping, and additional slash commands

Samir Hossainsd397f4bc50ae
diff --git a/src/tui/action.rs b/src/tui/action.rs
index 7a45bcd..26a5d42 100644
--- a/src/tui/action.rs
+++ b/src/tui/action.rs
@@ -11,6 +11,7 @@ pub enum Action {
Resize(u16, u16),
ToggleHelp,
ToggleTvMode,
+ ShowTvWizard,
TvChannelsLoaded(Vec<crate::providers::iptv_org::m3u::Channel>),
Search {
query: String,
diff --git a/src/tui/app.rs b/src/tui/app.rs
index f576dcb..af64cb0 100644
--- a/src/tui/app.rs
+++ b/src/tui/app.rs
@@ -352,14 +352,25 @@ impl App {
};
let greeting = format!("{}, {}{}", greeting_time, self.state.username, punct);
- let prompts = [
- "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 prompts = if self.state.is_tv_mode {
+ vec![
+ "What live channel are you looking for?",
+ "Try 'BBC', 'CNN', or 'ESPN'...",
+ "Discover news, sports, or entertainment...",
+ "Search your selected broadcast areas...",
+ "Feeling bored? Find a live stream...",
+ "Search live broadcast channels...",
+ ]
+ } else {
+ vec![
+ "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 = 90;
@@ -592,9 +603,9 @@ impl App {
if self.state.tv_wizard_step == 1 {
self.state.tv_wizard_step = 0;
self.state.tv_wizard_selected_idx = 0;
+ self.state.tv_wizard_options = vec!["Grouped by category".to_string(), "Grouped by language".to_string(), "Grouped by broadcast area".to_string()];
} else {
self.state.tv_config_popup = false;
- self.state.is_tv_mode = false;
}
}
KeyCode::Up => {
@@ -623,11 +634,19 @@ impl App {
}
KeyCode::Enter => {
if self.state.tv_wizard_step == 0 {
+ let selected_group = self.state.tv_wizard_options[self.state.tv_wizard_selected_idx].clone();
self.state.tv_wizard_step = 1;
self.state.tv_wizard_selected_idx = 0;
- self.state.tv_wizard_options = vec!["us".to_string(), "uk".to_string(), "ca".to_string(), "news".to_string(), "sports".to_string()];
+ if selected_group == "Grouped by category" {
+ self.state.tv_wizard_options = vec!["Animation", "Business", "Classic", "Comedy", "Documentary", "Education", "Entertainment", "Kids", "Movies", "Music", "News", "Sports"].into_iter().map(|s| s.to_string()).collect();
+ } else if selected_group == "Grouped by language" {
+ self.state.tv_wizard_options = vec!["English", "Spanish", "French", "German", "Italian", "Portuguese", "Russian", "Arabic", "Hindi", "Chinese", "Japanese"].into_iter().map(|s| s.to_string()).collect();
+ } else {
+ self.state.tv_wizard_options = vec!["US", "UK", "CA", "AU", "DE", "FR", "IT", "ES", "IN", "BR", "MX"].into_iter().map(|s| s.to_string()).collect();
+ }
} else {
self.state.tv_config_popup = false;
+ self.state.input_mode = crate::tui::state::InputMode::Editing;
self.state.is_loading = true;
self.state.status_message = "Fetching TV channels...".to_string();
@@ -840,16 +859,31 @@ impl App {
}
Action::ToggleTvMode => {
self.state.is_tv_mode = !self.state.is_tv_mode;
+ self.state.tick_count = 0; // Reset animation
if self.state.is_tv_mode {
- self.state.tv_config_popup = true;
+ self.state.tv_config_popup = false;
self.state.search_query.clear();
self.state.search_results.clear();
+ self.state.status_message = "Initializing Moviebox TV Mode...".to_string();
+ self.state.status_timer = 200;
+
+ let sender = self.action_sender.clone();
+ tokio::spawn(async move {
+ tokio::time::sleep(std::time::Duration::from_millis(2500)).await;
+ sender.send(Action::ShowTvWizard).ok();
+ });
} else {
self.state.tv_config_popup = false;
self.state.search_query.clear();
self.state.search_results.clear();
}
}
+ Action::ShowTvWizard => {
+ if self.state.is_tv_mode {
+ self.state.tv_config_popup = true;
+ self.state.input_mode = crate::tui::state::InputMode::Normal;
+ }
+ }
Action::TvChannelsLoaded(channels) => {
self.state.tv_channels = channels;
self.state.is_loading = false;
@@ -982,7 +1016,7 @@ impl App {
}
Action::Suggest(query) => {
if query.starts_with('/') {
- let commands = vec![
+ let mut commands = vec![
"/discover",
"/movies",
"/tvshows",
@@ -990,6 +1024,10 @@ impl App {
"/clear-cache",
"/quit",
];
+ if self.state.is_tv_mode {
+ commands.push("/list");
+ commands.push("/config");
+ }
let mut suggestions = vec![];
for cmd in commands {
if cmd.starts_with(&query) {
@@ -1081,25 +1119,14 @@ impl App {
query,
force_refresh,
} => {
- if self.state.is_tv_mode {
- let q = query.to_lowercase();
- self.state.search_results = self.state.tv_channels.iter()
- .filter(|c| c.name.to_lowercase().contains(&q) || c.group.to_lowercase().contains(&q))
- .map(|c| SearchResult {
- id: c.id.clone(),
- title: c.name.clone(),
- stype: 1,
- release_year: c.group.clone(),
- cover_url: Some(c.logo.clone()),
- season: 1,
- })
- .collect();
- self.state.is_loading = false;
- self.state.search_list_state.select(if self.state.search_results.is_empty() { None } else { Some(0) });
+ let lower_query = query.trim().to_lowercase();
+
+ if lower_query == "/clear-cache" {
+ self.action_sender.send(Action::ClearCache).ok();
+ self.state.search_query.clear();
return None;
}
- let lower_query = query.trim().to_lowercase();
if lower_query == "/github" {
let _ = open::that("https://github.com/mesamirh/MovieBox-Tui");
self.state.search_query.clear();
@@ -1148,9 +1175,27 @@ impl App {
return None;
}
- if lower_query == "/clear-cache" {
- self.action_sender.send(Action::ClearCache).ok();
- self.state.search_query.clear();
+ if self.state.is_tv_mode {
+ if lower_query == "/config" {
+ self.action_sender.send(Action::ShowTvWizard).ok();
+ self.state.search_query.clear();
+ return None;
+ }
+
+ let q = lower_query.clone();
+ self.state.search_results = self.state.tv_channels.iter()
+ .filter(|c| q == "/list" || c.name.to_lowercase().contains(&q) || c.group.to_lowercase().contains(&q))
+ .map(|c| SearchResult {
+ id: c.id.clone(),
+ title: c.name.clone(),
+ stype: 1,
+ release_year: c.group.clone(),
+ cover_url: Some(c.logo.clone()),
+ season: 1,
+ })
+ .collect();
+ self.state.is_loading = false;
+ self.state.search_list_state.select(if self.state.search_results.is_empty() { None } else { Some(0) });
return None;
}
diff --git a/src/tui/screens/help.rs b/src/tui/screens/help.rs
index 7819745..845b996 100644
--- a/src/tui/screens/help.rs
+++ b/src/tui/screens/help.rs
@@ -7,7 +7,7 @@ use ratatui::{
};
pub fn draw(frame: &mut Frame, area: Rect, state: &AppState, theme: &Theme) {
- let help_text = vec![
+ let mut help_text = vec![
Line::from(vec![Span::styled(
" Global",
theme.header.add_modifier(ratatui::style::Modifier::BOLD),
@@ -42,64 +42,97 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &AppState, theme: &Theme) {
Span::styled("Select / Submit", theme.text),
]),
Line::from(vec![]),
- Line::from(vec![Span::styled(
- " Discover & Search",
- theme.header.add_modifier(ratatui::style::Modifier::BOLD),
- )]),
- Line::from(vec![
- Span::styled(" /discover ", theme.header),
- Span::styled("Trending & Featured", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" /movies ", theme.header),
- Span::styled("Discover Movies", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" /shows ", theme.header),
- Span::styled("Discover TV Shows", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" /anime ", theme.header),
- Span::styled("Discover Anime", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" /github ", theme.header),
- Span::styled("Open GitHub Repo", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" /update ", theme.header),
- Span::styled("Check for updates", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" /toggle-update ", theme.header),
- Span::styled("Toggle auto updates", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" /clear-cache ", theme.header),
- Span::styled("Clear app cache", theme.text),
- ]),
- Line::from(vec![]),
Line::from(vec![Span::styled(
" Stream Controls",
theme.header.add_modifier(ratatui::style::Modifier::BOLD),
)]),
Line::from(vec![
Span::styled(" [Enter] ", theme.header),
- Span::styled("Play with default player", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" [o] ", theme.header),
- Span::styled("Open Player Picker", theme.text),
+ Span::styled(if state.is_tv_mode { "Play Channel" } else { "Play with default player" }, theme.text),
]),
+ ];
+
+ if !state.is_tv_mode {
+ help_text.splice(44..44, vec![
+ Line::from(vec![Span::styled(
+ " Discover & Search",
+ theme.header.add_modifier(ratatui::style::Modifier::BOLD),
+ )]),
+ Line::from(vec![
+ Span::styled(" /discover ", theme.header),
+ Span::styled("Trending & Featured", theme.text),
+ ]),
+ Line::from(vec![
+ Span::styled(" /movies ", theme.header),
+ Span::styled("Discover Movies", theme.text),
+ ]),
+ Line::from(vec![
+ Span::styled(" /shows ", theme.header),
+ Span::styled("Discover TV Shows", theme.text),
+ ]),
+ Line::from(vec![
+ Span::styled(" /anime ", theme.header),
+ Span::styled("Discover Anime", theme.text),
+ ]),
+ Line::from(vec![
+ Span::styled(" /github ", theme.header),
+ Span::styled("Open GitHub Repo", theme.text),
+ ]),
+ Line::from(vec![
+ Span::styled(" /update ", theme.header),
+ Span::styled("Check for updates", theme.text),
+ ]),
+ Line::from(vec![
+ Span::styled(" /toggle-update ", theme.header),
+ Span::styled("Toggle auto updates", theme.text),
+ ]),
+ Line::from(vec![
+ Span::styled(" /clear-cache ", theme.header),
+ Span::styled("Clear app cache", theme.text),
+ ]),
+ Line::from(vec![]),
+ ]);
+
+ help_text.extend(vec![
+ Line::from(vec![
+ Span::styled(" [o] ", theme.header),
+ Span::styled("Open Player Picker", theme.text),
+ ]),
+ Line::from(vec![
+ Span::styled(" [d] ", theme.header),
+ Span::styled("Download Video", theme.text),
+ ]),
+ ]);
+ }
+
+ if state.is_tv_mode {
+ help_text.extend(vec![
+ Line::from(vec![Span::styled(
+ " TV Commands",
+ theme.header.add_modifier(ratatui::style::Modifier::BOLD),
+ )]),
+ Line::from(vec![
+ Span::styled(" /list ", theme.header),
+ Span::styled("Show available channels", theme.text),
+ ]),
+ Line::from(vec![
+ Span::styled(" /config ", theme.header),
+ Span::styled("Open TV Config Popup", theme.text),
+ ]),
+ Line::from(vec![
+ Span::styled(" /clear-cache ", theme.header),
+ Span::styled("Clear app cache", theme.text),
+ ]),
+ Line::from(vec![]),
+ ]);
+ }
+
+ help_text.extend(vec![
Line::from(vec![
Span::styled(" [r] ", theme.header),
Span::styled("Refresh Streams/Search", theme.text),
]),
- Line::from(vec![
- Span::styled(" [d] ", theme.header),
- Span::styled("Download Video", theme.text),
- ]),
- ];
+ ]);
let height = help_text.len() as u16 + 2;
let margin_y = area.height.saturating_sub(height) / 2;
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index 5570e74..6dca591 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -65,7 +65,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let is_narrow = area.width < 60 || state.basic_terminal;
let is_wide = area.width >= 100 && !state.basic_terminal;
- let mut logo_height = if is_narrow {
+ let logo_height = if is_narrow {
2
} else if is_wide {
6
@@ -73,39 +73,51 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
4
};
- if state.is_tv_mode {
- logo_height += 1;
- }
-
- let mut logo_text = if is_narrow {
- "█▀▄▀█ █▀█ █ █ █ █▀▀ █▀▄ █▀█ ▀▄▀\n█ ▀ █ █▄█ ▀▄▀ █ ██▄ █▄▀ █▄█ █ █".to_string()
+ let logo_text = if is_narrow {
+ if state.is_tv_mode {
+ "█▀▄▀█ █▀█ █ █ █ █▀▀ █▀▄ █▀█ ▀▄▀\n█ ▀ █ █▄█ ▀▄▀ █ ██▄ █▄▀ █▄█ █ █TV".to_string()
+ } else {
+ "█▀▄▀█ █▀█ █ █ █ █▀▀ █▀▄ █▀█ ▀▄▀\n█ ▀ █ █▄█ ▀▄▀ █ ██▄ █▄▀ █▄█ █ █".to_string()
+ }
} else if is_wide {
- r"███╗ ███╗ ██████╗ ██╗ ██╗ ██╗ ███████╗ ██████╗ ██████╗ ██╗ ██╗
+ if state.is_tv_mode {
+ r"███╗ ███╗ ██████╗ ██╗ ██╗ ██╗ ███████╗ ██████╗ ██████╗ ██╗ ██╗
+████╗ ████║ ██╔═══██╗ ██║ ██║ ██║ ██╔════╝ ██╔══██╗ ██╔═══██╗ ╚██╗██╔╝
+██╔████╔██║ ██║ ██║ ██║ ██║ ██║ █████╗ ██████╔╝ ██║ ██║ ╚███╔╝
+██║╚██╔╝██║ ██║ ██║ ╚██╗ ██╔╝ ██║ ██╔══╝ ██╔══██╗ ██║ ██║ ██╔██╗ TV
+██║ ╚═╝ ██║ ╚██████╔╝ ╚████╔╝ ██║ ███████╗ ██████╔╝ ╚██████╔╝ ██╔╝ ██╗
+╚═╝ ╚═╝ ╚═════╝ ╚═══╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝".to_string()
+ } else {
+ r"███╗ ███╗ ██████╗ ██╗ ██╗ ██╗ ███████╗ ██████╗ ██████╗ ██╗ ██╗
████╗ ████║ ██╔═══██╗ ██║ ██║ ██║ ██╔════╝ ██╔══██╗ ██╔═══██╗ ╚██╗██╔╝
██╔████╔██║ ██║ ██║ ██║ ██║ ██║ █████╗ ██████╔╝ ██║ ██║ ╚███╔╝
██║╚██╔╝██║ ██║ ██║ ╚██╗ ██╔╝ ██║ ██╔══╝ ██╔══██╗ ██║ ██║ ██╔██╗
██║ ╚═╝ ██║ ╚██████╔╝ ╚████╔╝ ██║ ███████╗ ██████╔╝ ╚██████╔╝ ██╔╝ ██╗
╚═╝ ╚═╝ ╚═════╝ ╚═══╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝".to_string()
+ }
} else {
- r" __ __ ___ __ __ ___ ___ ___ ___ __ __
+ if state.is_tv_mode {
+ r" __ __ ___ __ __ ___ ___ ___ ___ __ __
+ | \/ |/ _ \ \ \ / /|_ _|| __|| _ ) / _ \ \ \/ /
+ | |\/| | (_) | \ V / | | | _| | _ \| (_) | > < TV
+ |_| |_|\___/ \_/ |___||___||___/ \___/ /_/\_\ ".to_string()
+ } else {
+ r" __ __ ___ __ __ ___ ___ ___ ___ __ __
| \/ |/ _ \ \ \ / /|_ _|| __|| _ ) / _ \ \ \/ /
| |\/| | (_) | \ V / | | | _| | _ \| (_) | > <
|_| |_|\___/ \_/ |___||___||___/ \___/ /_/\_\ ".to_string()
+ }
};
let logo_width: u16 = if is_narrow {
- 31
+ if state.is_tv_mode { 33 } else { 31 }
} else if is_wide {
- 73
+ if state.is_tv_mode { 75 } else { 73 }
} else {
- 55
+ if state.is_tv_mode { 57 } else { 55 }
};
- if state.is_tv_mode {
- let padding = logo_width.saturating_sub(11) / 2;
- let pad_str = " ".repeat(padding as usize);
- logo_text.push_str(&format!("\n{}[ TV MODE ]", pad_str));
- }
+
let vertical_chunks = Layout::default()
.direction(Direction::Vertical)
@@ -200,11 +212,13 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
InputMode::Normal => theme.text_dim,
});
- frame.render_widget(search_bar, search_bar_area);
+ if !state.tv_config_popup {
+ frame.render_widget(search_bar, search_bar_area);
+ }
let legend_line = ratatui::text::Line::from(vec![
- ratatui::text::Span::styled(" [Ctrl+T] ", theme.shortcut),
- ratatui::text::Span::styled("TV Mode ", theme.text_dim),
+ ratatui::text::Span::styled("[Ctrl+T] ", theme.shortcut),
+ ratatui::text::Span::styled(if state.is_tv_mode { "TV Mode " } else { "Streaming Mode " }, theme.text_dim),
ratatui::text::Span::styled("[Type] ", theme.shortcut),
ratatui::text::Span::styled("Search ", theme.text_dim),
ratatui::text::Span::styled("[↑↓] ", theme.shortcut),
@@ -645,41 +659,44 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let content_height = state.tv_wizard_options.len() as u16;
let popup_height = (content_height + 4).clamp(6, area.height.saturating_sub(4).max(6));
+ let y_pos = (area.height.saturating_sub(popup_height) / 2 + 5).min(area.height.saturating_sub(popup_height));
let popup_area = ratatui::layout::Rect {
x: area.width.saturating_sub(60) / 2,
- y: area.height.saturating_sub(popup_height) / 2,
+ y: y_pos,
width: 60,
height: popup_height,
};
let popup_block = ratatui::widgets::Block::default()
.title(if state.tv_wizard_step == 0 { " TV Setup: Select Grouping " } else { " TV Setup: Select Items " })
+ .title_alignment(ratatui::layout::Alignment::Center)
.borders(ratatui::widgets::Borders::ALL)
+ .border_type(ratatui::widgets::BorderType::Rounded)
.border_style(theme.border_focus)
- .style(ratatui::style::Style::default().bg(theme.base));
+ .style(ratatui::style::Style::default());
let inner_area = popup_block.inner(popup_area);
- frame.render_widget(ratatui::widgets::Clear, popup_area);
frame.render_widget(popup_block, popup_area);
- let items: Vec<ratatui::widgets::ListItem> = state.tv_wizard_options.iter().enumerate().map(|(i, opt)| {
- let is_selected = i == state.tv_wizard_selected_idx;
+ let items: Vec<ratatui::widgets::ListItem> = state.tv_wizard_options.iter().map(|opt| {
let is_checked = state.tv_wizard_selections.contains(opt);
- let prefix = if is_selected { "> " } else { " " };
let checkbox = if state.tv_wizard_step == 1 {
if is_checked { "[x] " } else { "[ ] " }
} else {
""
};
- let style = if is_selected { theme.highlight } else { theme.text };
let line = ratatui::text::Line::from(vec![
- ratatui::text::Span::styled(format!("{}{}{}", prefix, checkbox, opt), style)
+ ratatui::text::Span::styled(format!("{}{}", checkbox, opt), theme.text)
]);
ratatui::widgets::ListItem::new(line)
}).collect();
- let list = ratatui::widgets::List::new(items);
+ let list = ratatui::widgets::List::new(items)
+ .highlight_style(
+ theme.highlight.add_modifier(ratatui::style::Modifier::BOLD)
+ )
+ .highlight_symbol(if state.basic_terminal { "> " } else { "▌ " });
let mut list_area = inner_area;
list_area.height = list_area.height.saturating_sub(1);