Skip to content

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

feat(player): size player window to the terminal

Samir Hossains0ad1791d37ab
diff --git a/src/tui/app.rs b/src/tui/app.rs
index 84f0e5d..187f3b5 100644
--- a/src/tui/app.rs
+++ b/src/tui/app.rs
@@ -224,6 +224,21 @@ impl App {
let client = self.client.http_client().clone();
let sender = self.action_sender.clone();
+ let cell_size = self
+ .state
+ .image_picker
+ .as_ref()
+ .map(|picker| picker.font_size());
+ let window = crossterm::terminal::size().ok().map(|(cols, rows)| {
+ let (cell_width, cell_height) = cell_size
+ .filter(|size| size.width > 0 && size.height > 0)
+ .map(|size| (size.width as u32, size.height as u32))
+ .unwrap_or((8, 16));
+ (
+ (cols as u32 * cell_width).clamp(320, 1920),
+ (rows as u32 * cell_height).clamp(180, 1080),
+ )
+ });
tokio::spawn(async move {
let mut local_subtitle = subtitle.clone();
let mut temporary_subtitle = None;
@@ -270,8 +285,13 @@ impl App {
}
}
- let mut command =
- crate::tui::player::command(kind, &link, local_subtitle.as_deref(), &headers);
+ let mut command = crate::tui::player::command(
+ kind,
+ &link,
+ local_subtitle.as_deref(),
+ &headers,
+ window,
+ );
command.stdin(std::process::Stdio::null());
command.stdout(std::process::Stdio::null());
command.stderr(std::process::Stdio::piped());
diff --git a/src/tui/player.rs b/src/tui/player.rs
index c92e629..88f0f6c 100644
--- a/src/tui/player.rs
+++ b/src/tui/player.rs
@@ -47,11 +47,12 @@ pub fn command(
url: &str,
subtitle: Option<&str>,
headers: &[(String, String)],
+ window: Option<(u32, u32)>,
) -> Command {
match kind {
- PlayerKind::Mpv => mpv_command(url, subtitle, headers, false),
- PlayerKind::Iina => iina_command(url, subtitle, headers),
- PlayerKind::Vlc => vlc_command(url, subtitle, headers),
+ PlayerKind::Mpv => mpv_command(url, subtitle, headers, false, window),
+ PlayerKind::Iina => iina_command(url, subtitle, headers, window),
+ PlayerKind::Vlc => vlc_command(url, subtitle, headers, window),
PlayerKind::AndroidIntent => android_intent_command(url),
}
}
@@ -95,6 +96,7 @@ fn mpv_command(
subtitle: Option<&str>,
headers: &[(String, String)],
iina: bool,
+ window: Option<(u32, u32)>,
) -> Command {
let fallback = if cfg!(target_os = "windows") {
"mpv.exe"
@@ -112,9 +114,10 @@ fn mpv_command(
};
let prefix = if iina { "--mpv-" } else { "--" };
- command
- .arg(format!("{prefix}autofit=960x540"))
- .arg(format!("{prefix}geometry=50%:50%"));
+ if let Some((width, height)) = window {
+ command.arg(format!("{prefix}autofit={width}x{height}"));
+ }
+ command.arg(format!("{prefix}geometry=50%:50%"));
if !iina {
command.arg("--idle=no").arg("--keep-open=no");
@@ -148,7 +151,12 @@ fn mpv_command(
}
#[cfg(target_os = "macos")]
-fn iina_command(url: &str, subtitle: Option<&str>, headers: &[(String, String)]) -> Command {
+fn iina_command(
+ url: &str,
+ subtitle: Option<&str>,
+ headers: &[(String, String)],
+ window: Option<(u32, u32)>,
+) -> Command {
let configured = configured_executable("MOVIEBOX_IINA_PATH");
let cli_global = std::path::Path::new("/Applications/IINA.app/Contents/MacOS/iina-cli");
let cli_local = dirs::home_dir()
@@ -173,7 +181,7 @@ fn iina_command(url: &str, subtitle: Option<&str>, headers: &[(String, String)])
Command::new("iina")
};
- let mpv = mpv_command(url, subtitle, headers, true);
+ let mpv = mpv_command(url, subtitle, headers, true, window);
for arg in mpv.get_args() {
command.arg(arg);
}
@@ -181,11 +189,21 @@ fn iina_command(url: &str, subtitle: Option<&str>, headers: &[(String, String)])
}
#[cfg(not(target_os = "macos"))]
-fn iina_command(url: &str, subtitle: Option<&str>, headers: &[(String, String)]) -> Command {
- mpv_command(url, subtitle, headers, false)
+fn iina_command(
+ url: &str,
+ subtitle: Option<&str>,
+ headers: &[(String, String)],
+ window: Option<(u32, u32)>,
+) -> Command {
+ mpv_command(url, subtitle, headers, false, window)
}
-fn vlc_command(url: &str, subtitle: Option<&str>, headers: &[(String, String)]) -> Command {
+fn vlc_command(
+ url: &str,
+ subtitle: Option<&str>,
+ headers: &[(String, String)],
+ window: Option<(u32, u32)>,
+) -> Command {
let fallback = if cfg!(target_os = "windows") {
"vlc.exe"
} else {
@@ -200,10 +218,12 @@ fn vlc_command(url: &str, subtitle: Option<&str>, headers: &[(String, String)])
} else {
Command::new(&executable)
};
- command
- .arg("--width=960")
- .arg("--height=540")
- .arg("--play-and-exit");
+ if let Some((width, height)) = window {
+ command
+ .arg(format!("--width={width}"))
+ .arg(format!("--height={height}"));
+ }
+ command.arg("--play-and-exit");
for (name, value) in headers {
if name.eq_ignore_ascii_case("referer") {