Skip to content

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

fix: resolve cross-platform player and cache bugs

Samir Hossainse686d1bc41fe
diff --git a/src/cache.rs b/src/cache.rs
index 9382121..cc3ae61 100644
--- a/src/cache.rs
+++ b/src/cache.rs
@@ -3,6 +3,7 @@ use std::fs;
use std::path::PathBuf;
const CACHE_EXPIRY_SECS: u64 = 24 * 60 * 60;
+const STREAM_CACHE_EXPIRY_SECS: u64 = 2 * 60 * 60;
fn read_json_cache(path: &PathBuf, expiry_secs: u64) -> Option<serde_json::Value> {
if path.exists() {
@@ -114,7 +115,7 @@ pub fn get_stream_cache(
) -> Option<serde_json::Value> {
read_json_cache(
&get_cache_path(subject_id, season, episode),
- CACHE_EXPIRY_SECS,
+ STREAM_CACHE_EXPIRY_SECS,
)
}
@@ -125,7 +126,7 @@ pub fn get_provider_stream_cache(
episode: usize,
) -> Option<serde_json::Value> {
let path = get_provider_stream_path(provider, subject_id, season, episode);
- let value = read_json_cache(&path, CACHE_EXPIRY_SECS)?;
+ let value = read_json_cache(&path, STREAM_CACHE_EXPIRY_SECS)?;
if stream_payload_has_results(&value) {
Some(value)
} else {
diff --git a/src/history.rs b/src/history.rs
index 05becd2..3e32ea2 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -3,9 +3,24 @@ use std::collections::HashSet;
use std::fs;
use std::path::PathBuf;
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct WatchHistoryItem {
+ pub provider: String,
+ pub subject_id: String,
+ pub title: String,
+ pub cover_url: Option<String>,
+ pub stype: i64,
+ pub release_year: String,
+ pub season: usize,
+ pub episode: usize,
+ pub timestamp: u64,
+}
+
#[derive(Default, Serialize, Deserialize)]
pub struct HistoryManager {
watched: HashSet<String>,
+ #[serde(default)]
+ pub recent: Vec<WatchHistoryItem>,
}
impl HistoryManager {
@@ -44,15 +59,20 @@ impl HistoryManager {
format!("{provider}::{subject_id}::{season}::{episode}")
}
- pub fn mark_watched(
- &mut self,
- provider: &str,
- subject_id: &str,
- season: usize,
- episode: usize,
- ) {
- let key = Self::key(provider, subject_id, season, episode);
+ pub fn mark_watched(&mut self, item: WatchHistoryItem) {
+ let key = Self::key(&item.provider, &item.subject_id, item.season, item.episode);
self.watched.insert(key);
+
+ self.recent
+ .retain(|i| !(i.provider == item.provider && i.subject_id == item.subject_id));
+
+ self.recent.push(item);
+
+ if self.recent.len() > 100 {
+ let excess = self.recent.len() - 100;
+ self.recent.drain(0..excess);
+ }
+
self.save();
}
diff --git a/src/providers/bdix/circleftp/client.rs b/src/providers/bdix/circleftp/client.rs
index 4cf82ad..06f00ec 100644
--- a/src/providers/bdix/circleftp/client.rs
+++ b/src/providers/bdix/circleftp/client.rs
@@ -336,5 +336,5 @@ fn build_client() -> reqwest::Client {
reqwest::Client::builder()
.timeout(Duration::from_secs(5))
.build()
- .unwrap()
+ .unwrap_or_else(|_| reqwest::Client::new())
}
diff --git a/src/providers/bdix/circleftp/parser.rs b/src/providers/bdix/circleftp/parser.rs
index e626f44..a0aca64 100644
--- a/src/providers/bdix/circleftp/parser.rs
+++ b/src/providers/bdix/circleftp/parser.rs
@@ -57,7 +57,6 @@ pub fn search_to_moviebox_json(response: &CircleFtpSearchResponse) -> Vec<Catalo
}
});
- // Try to construct poster URL if an image is provided
let poster_url = post
.image
.as_ref()
diff --git a/src/providers/bdix/dhakaflix/client.rs b/src/providers/bdix/dhakaflix/client.rs
index b353fee..d15e705 100644
--- a/src/providers/bdix/dhakaflix/client.rs
+++ b/src/providers/bdix/dhakaflix/client.rs
@@ -69,7 +69,7 @@ impl DhakaFlixClient {
.timeout(Duration::from_secs(5))
.user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
.build()
- .unwrap(),
+ .unwrap_or_else(|_| reqwest::Client::new()),
}
}
diff --git a/src/tui/action.rs b/src/tui/action.rs
index b5ca86c..ad77f8f 100644
--- a/src/tui/action.rs
+++ b/src/tui/action.rs
@@ -112,4 +112,5 @@ pub enum Action {
crate::tui::state::PlayerKind,
crate::providers::models::PlaybackSource,
),
+ PlayerCrashed(Option<i32>, String),
}
diff --git a/src/tui/app.rs b/src/tui/app.rs
index 3d5ba32..8f7797c 100644
--- a/src/tui/app.rs
+++ b/src/tui/app.rs
@@ -165,9 +165,56 @@ impl App {
let season = self.state.selected_season;
let episode = self.state.selected_episode;
let provider = self.state.active_provider.cache_key();
+
+ let mut title = "Unknown".to_string();
+ let mut cover_url = None;
+ let mut stype = 1;
+ let mut release_year = "Unknown".to_string();
+
+ if let Some(details) = &self.state.selected_details {
+ if let Some(t) = details.get("title").and_then(|t| t.as_str()) {
+ title = t.to_string();
+ }
+ cover_url = details
+ .get("poster")
+ .or_else(|| details.get("cover"))
+ .or_else(|| details.get("pic"))
+ .and_then(|c| c.as_str().or_else(|| c.get("url").and_then(|u| u.as_str())))
+ .map(|s| s.to_string());
+ stype = details
+ .get("stype")
+ .or_else(|| details.get("subjectType"))
+ .and_then(|s| s.as_i64())
+ .unwrap_or(1);
+ if let Some(y) = details
+ .get("year")
+ .or_else(|| details.get("releaseYear"))
+ .and_then(|y| y.as_str())
+ {
+ release_year = y.to_string();
+ } else if let Some(y) = details.get("year").and_then(|y| y.as_i64()) {
+ release_year = y.to_string();
+ }
+ }
+
+ let timestamp = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap_or_default()
+ .as_secs();
+
self.state
.history
- .mark_watched(provider, subject_id, season, episode);
+ .mark_watched(crate::history::WatchHistoryItem {
+ provider: provider.to_string(),
+ subject_id: subject_id.clone(),
+ title,
+ cover_url,
+ stype,
+ release_year,
+ season,
+ episode,
+ timestamp,
+ });
self.state.dirty = true;
}
@@ -204,7 +251,7 @@ impl App {
crate::tui::player::command(kind, &link, local_subtitle.as_deref(), &headers);
command.stdin(std::process::Stdio::null());
command.stdout(std::process::Stdio::null());
- command.stderr(std::process::Stdio::null());
+ command.stderr(std::process::Stdio::piped());
#[cfg(unix)]
{
@@ -219,21 +266,41 @@ impl App {
match command.spawn() {
Ok(mut child) => {
- if let Some(path) = temporary_subtitle {
- tokio::task::spawn_blocking(move || {
- let _ = child.wait();
+ let start_time = std::time::Instant::now();
+ let stderr_stream = child.stderr.take();
+
+ tokio::task::spawn_blocking(move || {
+ let mut error_output = String::new();
+ if let Some(mut stderr) = stderr_stream {
+ use std::io::Read;
+ let _ = stderr.read_to_string(&mut error_output);
+ }
+
+ let result = child.wait();
+
+ if let Ok(status) = result {
+ if !status.success() && start_time.elapsed().as_secs() < 3 {
+ let clean_error = error_output.trim().to_string();
+ sender
+ .send(Action::PlayerCrashed(status.code(), clean_error))
+ .ok();
+ }
+ }
+
+ if let Some(path) = temporary_subtitle {
let _ = std::fs::remove_file(path);
- });
- }
+ }
+ });
}
Err(error) => {
if let Some(path) = temporary_subtitle {
let _ = tokio::fs::remove_file(path).await;
}
sender
- .send(Action::SetStatus(format!(
- "Error: failed to launch media player: {error}"
- )))
+ .send(Action::PlayerCrashed(
+ None,
+ format!("Failed to spawn player executable: {error}"),
+ ))
.ok();
}
}
@@ -1692,6 +1759,7 @@ impl App {
commands.extend(vec![
"/discover",
"/home",
+ "/history",
"/movies",
"/shows",
"/tvshows",
@@ -1799,6 +1867,100 @@ impl App {
} => {
let lower_query = query.trim().to_lowercase();
+ if lower_query == "/history" {
+ self.state.input_mode = InputMode::Normal;
+ self.state.is_loading = false;
+ self.state.is_homepage_mode = false;
+ self.state.active_screen = Screen::Home;
+ self.state.search_results.clear();
+ self.state.search_posters.clear();
+ self.state.search_poster_protocols.clear();
+
+ let mut recent = self.state.history.recent.clone();
+ if recent.is_empty() {
+ self.state.notify(
+ crate::tui::overlay::NotificationKind::Info,
+ "History",
+ "No watch history found.",
+ );
+ } else {
+ recent.sort_by_key(|b| std::cmp::Reverse(b.timestamp));
+
+ for item in recent {
+ let mut provider = self.state.active_provider;
+ let cache_key_lower = item.provider.to_lowercase();
+ if cache_key_lower == "moviebox" {
+ provider = crate::providers::models::ProviderKind::MovieBox;
+ } else if cache_key_lower == "fourkhdhub" {
+ provider = crate::providers::models::ProviderKind::FourKHdHub;
+ } else if cache_key_lower == "bdixcircleftp" {
+ provider = crate::providers::models::ProviderKind::BdixCircleFtp;
+ } else if cache_key_lower == "bdixdhakaflix" {
+ provider = crate::providers::models::ProviderKind::BdixDhakaFlix;
+ }
+ self.state.search_results.push(SearchResult {
+ id: item.subject_id.clone(),
+ title: item.title.clone(),
+ stype: item.stype,
+ release_year: item.release_year.clone(),
+ cover_url: item.cover_url.clone(),
+ season: item.season,
+ episode: item.episode,
+ provider,
+ });
+ }
+
+ self.state.search_list_state.select(Some(0));
+
+ let results_to_fetch = self
+ .state
+ .search_results
+ .iter()
+ .take(15)
+ .map(|r| (r.id.clone(), r.stype, r.cover_url.clone()))
+ .collect::<Vec<_>>();
+
+ let sender = self.action_sender.clone();
+ let req_client = self.client.http_client().clone();
+ tokio::spawn(async move {
+ let sem = std::sync::Arc::new(tokio::sync::Semaphore::new(4));
+ for (id, _stype, cover_url) in results_to_fetch {
+ if let Some(url) = cover_url {
+ let permit = sem.clone().acquire_owned().await.ok();
+ let tx = sender.clone();
+ let client = req_client.clone();
+ tokio::spawn(async move {
+ let _permit = permit;
+ if let Ok(resp) = client
+ .get(&url)
+ .header("User-Agent", "MovieBox-Tui/1.0")
+ .send()
+ .await
+ {
+ if let Ok(bytes) = resp.bytes().await {
+ let bytes_clone = bytes.clone();
+ if let Ok(Ok(img)) =
+ tokio::task::spawn_blocking(move || {
+ image::load_from_memory(&bytes_clone)
+ })
+ .await
+ {
+ tx.send(Action::SearchPosterLoaded(
+ id,
+ Some(std::sync::Arc::new(img)),
+ ))
+ .ok();
+ }
+ }
+ }
+ });
+ }
+ }
+ });
+ }
+ return None;
+ }
+
if lower_query == "/clear-cache" {
self.action_sender.send(Action::ClearCache).ok();
self.state.search_query.clear();
@@ -1926,6 +2088,7 @@ impl App {
release_year: c.group.clone(),
cover_url: Some(c.logo.clone()),
season: 1,
+ episode: 1,
provider: ProviderKind::MovieBox,
})
.collect();
@@ -2295,6 +2458,7 @@ impl App {
release_year,
cover_url,
season,
+ episode: 1,
provider: context.provider,
});
}
@@ -2522,6 +2686,7 @@ impl App {
release_year,
cover_url,
season,
+ episode: 1,
provider: ProviderKind::MovieBox,
});
count += 1;
@@ -3411,9 +3576,12 @@ impl App {
.selected_details
.as_ref()
.and_then(|d| d.get("id"))
- .and_then(|i| i.as_str())
- .unwrap_or("")
- .to_string();
+ .and_then(|i| {
+ i.as_str()
+ .map(|s| s.to_string())
+ .or_else(|| i.as_i64().map(|n| n.to_string()))
+ })
+ .unwrap_or_default();
let resource_id = self.get_selected_resource_id();
if let Some(rid) = resource_id {
@@ -3436,16 +3604,26 @@ impl App {
.ok();
return;
}
- if let Ok(res) = client.get_ext_captions(&subject_id, &rid).await {
- crate::cache::set_captions_cache(&subject_id, &rid, &res);
- sender
- .send(Action::ShowSubtitlePopup(link_clone, res, open_with))
- .ok();
- } else {
- if open_with {
- sender.send(Action::ShowPlayerPicker(link_clone, None)).ok();
- } else {
- sender.send(Action::LaunchMpv(link_clone, None)).ok();
+ let result = tokio::time::timeout(
+ std::time::Duration::from_secs(15),
+ client.get_ext_captions(&subject_id, &rid),
+ )
+ .await;
+ match result {
+ Ok(Ok(res)) => {
+ crate::cache::set_captions_cache(&subject_id, &rid, &res);
+ sender
+ .send(Action::ShowSubtitlePopup(link_clone, res, open_with))
+ .ok();
+ }
+ _ => {
+ if open_with {
+ sender
+ .send(Action::ShowPlayerPicker(link_clone, None))
+ .ok();
+ } else {
+ sender.send(Action::LaunchMpv(link_clone, None)).ok();
+ }
}
}
});
@@ -3811,6 +3989,7 @@ impl App {
let action_tx = self.action_sender.clone();
let id_clone = id.clone();
let provider = context.provider;
+ let http_client = self.client.http_client().clone();
tokio::spawn(async move {
if let Ok(Some(bytes)) = tokio::task::spawn_blocking({
let id_clone = id_clone.clone();
@@ -3835,7 +4014,10 @@ impl App {
return;
}
}
- let client = reqwest::Client::new();
+ let client = reqwest::Client::builder()
+ .timeout(std::time::Duration::from_secs(5))
+ .build()
+ .unwrap_or(http_client);
if let Ok(resp) = client
.get(&url_clone)
.header("User-Agent", "MovieBox-Tui/1.0")
@@ -3915,8 +4097,39 @@ impl App {
self.state.available_episode_numbers.push(ep_numbers);
}
- self.state.season_list_state.select(Some(0));
- self.state.episode_list_state.select(Some(0));
+ let mut default_season = 1;
+ let mut default_episode = 1;
+ if let Some(res) = self.state.search_results.iter().find(|r| r.id == id) {
+ if res.season > 0 {
+ default_season = res.season;
+ }
+ if res.episode > 0 {
+ default_episode = res.episode;
+ }
+ }
+
+ let season_idx = self
+ .state
+ .available_seasons
+ .iter()
+ .position(|s| {
+ s.get("se")
+ .and_then(|v| v.as_i64())
+ .map(|v| v as usize == default_season)
+ .unwrap_or(false)
+ })
+ .unwrap_or(0);
+
+ self.state.season_list_state.select(Some(season_idx));
+
+ let ep_idx = self
+ .state
+ .available_episode_numbers
+ .get(season_idx)
+ .and_then(|eps| eps.iter().position(|&e| e == default_episode))
+ .unwrap_or(0);
+
+ self.state.episode_list_state.select(Some(ep_idx));
if let Some(dubs) = payload.get("dubs").and_then(|d| d.as_array()) {
let mut current_idx = 0;
@@ -3936,8 +4149,8 @@ impl App {
}
if !self.state.language_chosen {
- self.state.selected_season = 1;
- self.state.selected_episode = 1;
+ self.state.selected_season = default_season;
+ self.state.selected_episode = default_episode;
}
let has_multiple_dubs = payload
@@ -4473,13 +4686,44 @@ impl App {
}
let entry = pool.episode_index.entry((se, ep)).or_insert_with(Vec::new);
+ let rid = item.get("resourceId").and_then(|r| r.as_str());
let link = item
.get("resourceLink")
.and_then(|l| l.as_str())
.unwrap_or("");
- if !entry.iter().any(|i| {
- i.get("resourceLink").and_then(|l| l.as_str()).unwrap_or("") == link
- }) {
+
+ let mut exists = false;
+ for i in entry.iter_mut() {
+ let i_rid = i.get("resourceId").and_then(|r| r.as_str());
+ if rid.is_some() && i_rid == rid {
+ if let Some(obj) = i.as_object_mut() {
+ obj.insert(
+ "resourceLink".to_string(),
+ serde_json::Value::String(link.to_string()),
+ );
+ }
+ exists = true;
+ break;
+ }
+
+ let i_link =
+ i.get("resourceLink").and_then(|l| l.as_str()).unwrap_or("");
+ let base_link = link.split('?').next().unwrap_or(link);
+ let i_base_link = i_link.split('?').next().unwrap_or(i_link);
+
+ if base_link == i_base_link && !base_link.is_empty() {
+ if let Some(obj) = i.as_object_mut() {
+ obj.insert(
+ "resourceLink".to_string(),
+ serde_json::Value::String(link.to_string()),
+ );
+ }
+ exists = true;
+ break;
+ }
+ }
+
+ if !exists {
entry.push(item);
}
}
@@ -4705,6 +4949,7 @@ impl App {
self.state.subtitle_popup = false;
}
Action::ShowPlayerPicker(link, subtitle) => {
+ self.state.is_resolving_playback = false;
if self.state.available_players.is_empty() {
self.state.notify(
NotificationKind::Error,
@@ -4723,6 +4968,7 @@ impl App {
self.state.subtitle_popup = false;
}
Action::LaunchPlayer(kind, link, sub) => {
+ self.state.is_resolving_playback = false;
self.state.player_picker_popup = false;
self.launch_player(kind, link, sub, Vec::new());
}
@@ -4736,6 +4982,27 @@ impl App {
}
self.launch_player(kind, source.url, source.subtitle, source.headers);
}
+ Action::PlayerCrashed(code, error_msg) => {
+ let code_str = code
+ .map(|c| c.to_string())
+ .unwrap_or_else(|| "unknown".into());
+
+ let display_err = if error_msg.is_empty() {
+ "No error output provided by player.".to_string()
+ } else {
+ error_msg.lines().last().unwrap_or(&error_msg).to_string()
+ };
+
+ self.state.status_message =
+ format!("Player crashed (code {code_str}): {display_err}");
+ self.state.status_timer = 300;
+
+ self.state.notify(
+ NotificationKind::Error,
+ "Player Error",
+ format!("Crash code: {code_str}\n{display_err}"),
+ );
+ }
Action::CheckForUpdates => {
let update_sender = self.action_sender.clone();
tokio::spawn(async move {
diff --git a/src/tui/player.rs b/src/tui/player.rs
index 7cf84f7..43e350d 100644
--- a/src/tui/player.rs
+++ b/src/tui/player.rs
@@ -18,11 +18,14 @@ pub fn detect() -> Vec<PlayerKind> {
if mpv_executable().is_some() {
players.push(PlayerKind::Mpv);
}
+
if vlc_executable().is_some() {
players.push(PlayerKind::Vlc);
}
- if cfg!(target_os = "android") || std::path::Path::new("/system/bin/am").exists() {
+ let is_android = cfg!(target_os = "android") || std::path::Path::new("/system/bin/am").exists();
+
+ if is_android {
players.push(PlayerKind::AndroidIntent);
}
@@ -97,11 +100,11 @@ fn mpv_command(
let executable = mpv_executable().unwrap_or_else(|| fallback.into());
let mut command = if executable.starts_with("flatpak run ") {
let mut parts = executable.split(' ');
- let mut cmd = Command::new(parts.next().unwrap());
+ let mut cmd = Command::new(parts.next().unwrap_or("flatpak"));
cmd.args(parts);
cmd
} else {
- Command::new(executable)
+ Command::new(&executable)
};
let prefix = if iina { "--mpv-" } else { "--" };
@@ -110,6 +113,10 @@ fn mpv_command(
.arg(format!("{prefix}autofit-larger=640x360"))
.arg(format!("{prefix}geometry=50%:50%"));
+ if !iina {
+ command.arg("--idle=no").arg("--keep-open=no");
+ }
+
if !headers.is_empty() {
let fields = headers
.iter()
@@ -119,10 +126,16 @@ fn mpv_command(
command.arg(format!("{prefix}http-header-fields={fields}"));
}
if let Some(subtitle) = subtitle {
+ let sub_arg = if executable.starts_with("flatpak run ") {
+ format!("@@ {} @@", subtitle)
+ } else {
+ subtitle.to_string()
+ };
+
if iina {
- command.arg(format!("--mpv-sub-files={subtitle}"));
+ command.arg(format!("--mpv-sub-files={sub_arg}"));
} else {
- command.arg(format!("--sub-file={subtitle}"));
+ command.arg(format!("--sub-file={sub_arg}"));
}
}
@@ -139,25 +152,33 @@ fn iina_command(url: &str, subtitle: Option<&str>, headers: &[(String, String)])
.map(|h| h.join("Applications/IINA.app/Contents/MacOS/iina-cli"))
.unwrap_or_default();
+ let mut is_open = false;
let mut command = if let Some(executable) = configured {
Command::new(executable)
} else if cli_global.exists() {
let mut c = Command::new(cli_global);
- c.arg("--keep-running");
+ c.arg("--keep-running").arg("--no-stdin");
c
} else if cli_local.exists() {
let mut c = Command::new(cli_local);
- c.arg("--keep-running");
+ c.arg("--keep-running").arg("--no-stdin");
c
} else if iina_app_exists() {
+ is_open = true;
let mut c = Command::new("open");
- c.arg("-W").arg("-a").arg("IINA").arg("--args");
+ c.arg("-W").arg("-a").arg("IINA").arg(url).arg("--args");
c
} else {
Command::new("iina")
};
+
let mpv = mpv_command(url, subtitle, headers, true);
- command.args(mpv.get_args());
+ for arg in mpv.get_args() {
+ if is_open && arg == std::ffi::OsStr::new(url) {
+ continue;
+ }
+ command.arg(arg);
+ }
command
}
@@ -175,13 +196,16 @@ fn vlc_command(url: &str, subtitle: Option<&str>, headers: &[(String, String)])
let executable = vlc_executable().unwrap_or_else(|| fallback.into());
let mut command = if executable.starts_with("flatpak run ") {
let mut parts = executable.split(' ');
- let mut cmd = Command::new(parts.next().unwrap());
+ let mut cmd = Command::new(parts.next().unwrap_or("flatpak"));
cmd.args(parts);
cmd
} else {
- Command::new(executable)
+ Command::new(&executable)
};
- command.arg("--width=960").arg("--height=540").arg(url);
+ command
+ .arg("--width=960")
+ .arg("--height=540")
+ .arg("--play-and-exit");
for (name, value) in headers {
if name.eq_ignore_ascii_case("referer") {
@@ -191,9 +215,15 @@ fn vlc_command(url: &str, subtitle: Option<&str>, headers: &[(String, String)])
}
}
if let Some(subtitle) = subtitle {
- command.arg(format!("--sub-file={subtitle}"));
+ let sub_arg = if executable.starts_with("flatpak run ") {
+ format!("@@ {} @@", subtitle)
+ } else {
+ subtitle.to_string()
+ };
+ command.arg(format!("--sub-file={sub_arg}"));
}
+ command.arg(url);
command
}
@@ -206,7 +236,7 @@ fn mpv_executable() -> Option<String> {
} else {
"mpv"
};
- #[allow(unused_mut)]
+ #[cfg_attr(not(any(target_os = "macos", windows)), allow(unused_mut))]
let mut paths = vec![MPV_WINDOWS.to_string(), MPV_MACOS.to_string()];
#[cfg(target_os = "macos")]
if let Some(home) = dirs::home_dir() {
@@ -233,7 +263,7 @@ fn vlc_executable() -> Option<String> {
"vlc"
};
- #[allow(unused_mut)]
+ #[cfg_attr(not(any(target_os = "macos", windows)), allow(unused_mut))]
let mut paths = vec![
VLC_WINDOWS.to_string(),
VLC_WINDOWS_X86.to_string(),
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index efe80cf..228f3ec 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -739,16 +739,35 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let max_title_width = text_area.width.saturating_sub(4) as usize;
let display_title = crate::tui::text::truncate_width(&res.title, max_title_width);
- let type_tag = if state.is_tv_mode || res.stype == 3 {
- "TV Channel"
+ let mut type_tag = if state.is_tv_mode || res.stype == 3 {
+ "TV Channel".to_string()
} else if res.stype == 1 {
- "Movie"
+ "Movie".to_string()
} else if res.stype == 2 {
- "Series"
+ "Series".to_string()
} else {
- "Unknown"
+ "".to_string()
};
+ let is_history = state.search_query.trim().to_lowercase() == "/history";
+ if is_history {
+ let mut extra = vec![];
+ if res.season > 0 {
+ extra.push(format!("S{:02}E{:02}", res.season, res.episode));
+ }
+ extra.push(res.provider.to_string());
+
+ if !extra.is_empty() {
+ if type_tag.is_empty() {
+ type_tag = extra.join(" • ");
+ } else {
+ type_tag = format!("{} • {}", type_tag, extra.join(" • "));
+ }
+ }
+ } else if type_tag.is_empty() {
+ type_tag = "Unknown".to_string();
+ }
+
let title_line = ratatui::text::Line::from(vec![
ratatui::text::Span::raw(" "),
ratatui::text::Span::styled(display_title, title_style),
@@ -759,11 +778,20 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let mut info_spans = vec![];
+ macro_rules! push_year {
+ () => {
+ if res.release_year != "Unknown" && !res.release_year.is_empty() {
+ info_spans
+ .push(ratatui::text::Span::styled(&res.release_year, theme.text));
+ info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
+ }
+ };
+ }
+
if is_selected {
if state.preview_loading || state.is_loading {
- info_spans.push(ratatui::text::Span::styled(&res.release_year, theme.text));
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
- info_spans.push(ratatui::text::Span::styled(type_tag, theme.text));
+ push_year!();
+ info_spans.push(ratatui::text::Span::styled(&type_tag, theme.text));
info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
info_spans.push(ratatui::text::Span::styled("Loading...", theme.text_dim));
} else if let Some(meta) = &state.search_preview {
@@ -777,8 +805,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
info_spans.push(ratatui::text::Span::styled(r, theme.text));
info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
}
- info_spans.push(ratatui::text::Span::styled(&res.release_year, theme.text));
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
+ push_year!();
let mut g_names = vec![];
if let Some(genres) = meta.get("genres").and_then(|g| g.as_array()) {
@@ -796,16 +823,14 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.push(ratatui::text::Span::styled(g_names.join(" • "), theme.text));
info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
}
- info_spans.push(ratatui::text::Span::styled(type_tag, theme.text));
+ info_spans.push(ratatui::text::Span::styled(&type_tag, theme.text));
} else {
- info_spans.push(ratatui::text::Span::styled(&res.release_year, theme.text));
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
- info_spans.push(ratatui::text::Span::styled(type_tag, theme.text));
+ push_year!();
+ info_spans.push(ratatui::text::Span::styled(&type_tag, theme.text));
}
} else {
- info_spans.push(ratatui::text::Span::styled(&res.release_year, theme.text));
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
- info_spans.push(ratatui::text::Span::styled(type_tag, theme.text));
+ push_year!();
+ info_spans.push(ratatui::text::Span::styled(&type_tag, theme.text));
}
if text_layout[2].height > 0 && !info_spans.is_empty() {
diff --git a/src/tui/state.rs b/src/tui/state.rs
index 064be27..60fd953 100644
--- a/src/tui/state.rs
+++ b/src/tui/state.rs
@@ -39,6 +39,7 @@ pub struct SearchResult {
pub release_year: String,
pub cover_url: Option<String>,
pub season: usize,
+ pub episode: usize,
pub provider: crate::providers::models::ProviderKind,
}