From 3954de092e18dac900d2ad142484141ead0c1737 Mon Sep 17 00:00:00 2001 From: hl-valdemar Date: Fri, 9 Oct 2026 21:15:42 +0200 Subject: [PATCH] feat: default to IINA for piped playback --- src/main.rs | 12 ++++++------ src/youtube.rs | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3892908..a0ceb26 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,13 @@ //! A Ratatui YouTube browser backed by yt-dlp and FFmpeg, with no API key. //! -//! Run `cargo run -- --player mpv --player-arg=--volume=50 "rust programming"`. +//! Run `cargo run -- "rust programming"`; macOS defaults to IINA, other platforms to mpv. //! Without a CLI query, start in insert mode; otherwise search and start in normal mode. //! Insert: Enter submits a changed query and returns to normal; Esc returns without searching. //! Normal: j/k selects, Enter streams, and i returns to insert mode to edit the query. //! Normal-mode d opens the full description; Up/Down scrolls lines and PgUp/PgDn scrolls pages. //! The centered popup uses up to 70% width and 60% height, capped at 96 by 20 cells. //! Esc closes the popup; j/k loads the selected video's description and i returns to editing. -//! The player must read media from standard input when passed `-`. +//! IINA receives `--stdin`; other players must read standard input when passed `-`. //! Audio and video are streamed through a pipe, never saved to a video file. //! See `--help` for controls; replacing playback or quitting cancels its processes. @@ -30,14 +30,14 @@ use youtube::{Job, Playback, Video}; #[command( version, about = "Search YouTube and stream videos to your chosen player", - after_help = "Requires yt-dlp, FFmpeg, and a player on PATH.\nThe player receives audio/video on standard input, with '-' as its last argument.\nWithout a CLI query, start in INSERT; a CLI query is searched automatically in NORMAL.\nINSERT: type to edit; Enter submits if changed and returns to NORMAL; Esc returns without submitting.\nNORMAL: j/k or arrows select; Enter streams; i edits the query; d toggles description; q quits.\nOpening the description fetches full video metadata, preserving paragraphs and caching it for these results.\nThe centered description window uses up to 70% width and 60% height, capped at 96 by 20 cells.\nWhile it is open, Up/Down scroll lines and PgUp/PgDn scroll pages; j/k still selects videos.\nEsc closes the description; i closes it to edit the query. Scrolling stays within the text.\nCtrl-U clears in INSERT; Ctrl-C quits in either mode.\nSelecting another video replaces playback. Quitting stops playback.\nExample: tubular --player mpv --player-arg=--volume=50 \"rust programming\"" + after_help = "Requires yt-dlp, FFmpeg, and a player on PATH.\nDefaults to IINA on macOS and mpv elsewhere; --player overrides the default.\nIINA receives '--stdin'; other players receive '-' to read audio/video from standard input.\nWithout a CLI query, start in INSERT; a CLI query is searched automatically in NORMAL.\nINSERT: type to edit; Enter submits if changed and returns to NORMAL; Esc returns without submitting.\nNORMAL: j/k or arrows select; Enter streams; i edits the query; d toggles description; q quits.\nOpening the description fetches full video metadata, preserving paragraphs and caching it for these results.\nThe centered description window uses up to 70% width and 60% height, capped at 96 by 20 cells.\nWhile it is open, Up/Down scroll lines and PgUp/PgDn scroll pages; j/k still selects videos.\nEsc closes the description; i closes it to edit the query. Scrolling stays within the text.\nCtrl-U clears in INSERT; Ctrl-C quits in either mode.\nSelecting another video replaces playback. Quitting stops playback.\nExample: tubular --player mpv --player-arg=--volume=50 \"rust programming\"" )] struct Options { - /// Player executable (must support '-' for media on standard input). - #[arg(long, default_value = "mpv")] + /// Player executable (IINA or a player supporting '-' for standard input). + #[arg(long, default_value = if cfg!(target_os = "macos") { "iina" } else { "mpv" })] player: OsString, - /// Argument passed to the player before '-'; repeat for multiple arguments. + /// Argument passed to the player before its standard-input flag; repeat as needed. #[arg(long, allow_hyphen_values = true)] player_arg: Vec, diff --git a/src/youtube.rs b/src/youtube.rs index 439e877..378002b 100644 --- a/src/youtube.rs +++ b/src/youtube.rs @@ -230,7 +230,10 @@ impl Playback { let stream = extractor.stdout.take().expect("stdout is piped"); let player = match isolated_command(player) .args(args) - .arg("-") + .arg(match std::path::Path::new(player).file_name() { + Some(name) if name == "iina" || name == "iina-cli" => "--stdin", + _ => "-", + }) .stdin(Stdio::from(stream)) .stdout(Stdio::null()) .stderr(Stdio::piped())