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()
!= "mkv"
&& !is_special_file(PathBuf::from(&self.output))
&& self.output != "-"
{
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)
});
for data in input {
let mut downloader = DownloadBuilder::new()
.default_subtitle(self.download.subtitle.clone())
.build();
let mut download_builder =
DownloadBuilder::new().default_subtitle(self.download.subtitle.clone());
// 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 {
video: (data.video, 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 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())
.args(command_args)
.output()?;

View file

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