Enable stdout output

This commit is contained in:
ByteDream 2023-03-23 13:39:05 +01:00
parent a7adb7191e
commit ba1c0aaaa4
4 changed files with 20 additions and 8 deletions

View file

@ -108,6 +108,7 @@ impl Execute for Archive {
.to_string_lossy() .to_string_lossy()
!= "mkv" != "mkv"
&& !is_special_file(PathBuf::from(&self.output)) && !is_special_file(PathBuf::from(&self.output))
&& self.output != "-"
{ {
bail!("File extension is not '.mkv'. Currently only matroska / '.mkv' files are supported") bail!("File extension is not '.mkv'. Currently only matroska / '.mkv' files are supported")
} }

View file

@ -333,9 +333,15 @@ impl Filter for DownloadFilter {
.total_cmp(&b.format.sequence_number) .total_cmp(&b.format.sequence_number)
}); });
for data in input { for data in input {
let mut downloader = DownloadBuilder::new() let mut download_builder =
.default_subtitle(self.download.subtitle.clone()) DownloadBuilder::new().default_subtitle(self.download.subtitle.clone());
.build(); // set the output format to mpegts / mpeg transport stream if the output file is stdout.
// mp4 isn't used here as the output file must be readable which isn't possible when
// writing to stdout
if self.download.output == "-" {
download_builder = download_builder.output_format(Some("mpegts".to_string()))
}
let mut downloader = download_builder.build();
downloader.add_format(DownloadFormat { downloader.add_format(DownloadFormat {
video: (data.video, data.format.audio.clone()), video: (data.video, data.format.audio.clone()),
audios: vec![(data.audio, data.format.audio.clone())], audios: vec![(data.audio, data.format.audio.clone())],

View file

@ -317,7 +317,12 @@ impl Downloader {
let progress_handler = progress!("Generating output file"); let progress_handler = progress!("Generating output file");
let ffmpeg = Command::new("ffmpeg") let ffmpeg = Command::new("ffmpeg")
.stdout(Stdio::null()) // pass ffmpeg stdout to real stdout only if output file is stdout
.stdout(if dst.to_str().unwrap() == "-" {
Stdio::inherit()
} else {
Stdio::null()
})
.stderr(Stdio::piped()) .stderr(Stdio::piped())
.args(command_args) .args(command_args)
.output()?; .output()?;

View file

@ -223,12 +223,12 @@ impl Format {
pub fn visual_output(&self, dst: &Path) { pub fn visual_output(&self, dst: &Path) {
info!( info!(
"Downloading {} to '{}'", "Downloading {} to {}",
self.title, self.title,
if is_special_file(&dst) { if is_special_file(&dst) || dst.to_str().unwrap() == "-" {
dst.to_str().unwrap() dst.to_string_lossy().to_string()
} else { } else {
dst.file_name().unwrap().to_str().unwrap() format!("'{}'", dst.to_str().unwrap())
} }
); );
tab_info!( tab_info!(