From 6e835ab01898c61cd683a3c4048c0f90a4a63d6a Mon Sep 17 00:00:00 2001 From: clitic Date: Thu, 14 Sep 2023 12:33:15 +0530 Subject: [PATCH] fixes for #21 --- Cargo.toml | 1 + vsd/CHANGELOG.md | 5 +++++ vsd/Cargo.toml | 2 +- vsd/src/commands/mod.rs | 2 +- vsd/src/downloader.rs | 36 +++++++++++++++++++++++------------- vsd/src/playlist.rs | 2 +- 6 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 746d30c..6382db2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,4 @@ members = [ "vsd", "vsd-mp4", ] +resolver = "2" diff --git a/vsd/CHANGELOG.md b/vsd/CHANGELOG.md index ef3b977..dfd0353 100644 --- a/vsd/CHANGELOG.md +++ b/vsd/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- `save` + - Handle `--output` flag correctly. ([#21](https://github.com/clitic/vsd/issues/21)) + ## [0.3.0] - 2023-08-18 ### Added diff --git a/vsd/Cargo.toml b/vsd/Cargo.toml index 82a4219..ce0e06a 100644 --- a/vsd/Cargo.toml +++ b/vsd/Cargo.toml @@ -9,7 +9,7 @@ keywords = ["m3u8"] license = "MIT OR Apache-2.0" name = "vsd" repository = "https://github.com/clitic/vsd/tree/main/vsd" -version = "0.3.0" +version = "0.3.1" readme = "README.md" [dependencies] diff --git a/vsd/src/commands/mod.rs b/vsd/src/commands/mod.rs index 02fdf30..ee4fcda 100644 --- a/vsd/src/commands/mod.rs +++ b/vsd/src/commands/mod.rs @@ -23,8 +23,8 @@ use clap::{ColorChoice, Parser, Subcommand}; "\n\nEnabled features:", "\n browser : ", cfg!(feature = "browser"), "\n native-tls : ", cfg!(feature = "native-tls"), - "\n rustls-tls-webpki-roots : ", cfg!(feature = "rustls-tls-webpki-roots"), "\n rustls-tls-native-roots : ", cfg!(feature = "rustls-tls-native-roots"), + "\n rustls-tls-webpki-roots : ", cfg!(feature = "rustls-tls-webpki-roots"), ), version, )] diff --git a/vsd/src/downloader.rs b/vsd/src/downloader.rs index bc63b18..7fbfbf9 100644 --- a/vsd/src/downloader.rs +++ b/vsd/src/downloader.rs @@ -432,6 +432,7 @@ pub(crate) fn download( } let mut temp_files = vec![]; + let one_stream = (video_audio_streams.len() == 1) && subtitle_streams.is_empty(); // ----------------------------------------------------------------------------------------- // Download Subtitle Streams @@ -699,6 +700,7 @@ pub(crate) fn download( // ----------------------------------------------------------------------------------------- let pool = threadpool::ThreadPool::new(threads as usize); + let mut should_mux = !no_decrypt; for stream in video_audio_streams { pb.lock().unwrap().write(format!( @@ -718,10 +720,18 @@ pub(crate) fn download( continue; } - let temp_file = stream + let mut temp_file = stream .file_path(&directory, &stream.extension()) .to_string_lossy() .to_string(); + + if let Some(output) = &output { + if one_stream && output.ends_with(&format!(".{}", stream.extension())) { + temp_file = output.to_owned(); + should_mux = false; + } + } + temp_files.push(Stream { file_path: temp_file.clone(), language: stream.language.clone(), @@ -897,7 +907,7 @@ pub(crate) fn download( let video_temp_files = temp_files .iter() - .filter(|x| x.media_type == MediaType::Video) + .filter(|x| (x.media_type == MediaType::Video) || (x.media_type == MediaType::Undefined)) .collect::>(); let video_streams_count = video_temp_files.len(); let audio_streams_count = temp_files @@ -909,13 +919,15 @@ pub(crate) fn download( .filter(|x| x.media_type == MediaType::Subtitles) .count(); - if !no_decrypt + if should_mux && (video_streams_count == 1 || audio_streams_count == 1 || subtitle_streams_count == 1) { if let Some(output) = &output { let all_temp_files = temp_files .iter() - .filter(|x| x.media_type == MediaType::Video) + .filter(|x| { + (x.media_type == MediaType::Video) || (x.media_type == MediaType::Undefined) + }) .chain( temp_files .iter() @@ -934,16 +946,14 @@ pub(crate) fn download( args.extend_from_slice(&["-i".to_owned(), temp_file.file_path.clone()]); } - if args.len() == 2 && (video_streams_count == 1 || audio_streams_count == 1) { + if (video_streams_count == 1) + || (audio_streams_count == 1) + || (subtitle_streams_count == 1) + { + // TODO - Re-consider this copy args.extend_from_slice(&["-c".to_owned(), "copy".to_owned()]); - } else if args.len() > 2 { + } else { args.extend_from_slice(&["-c".to_owned(), "copy".to_owned()]); - // args.extend_from_slice(&[ - // "-c:v".to_owned(), - // "copy".to_owned(), - // "-c:a".to_owned(), - // "copy".to_owned(), - // ]); if subtitle_streams_count > 0 && output.ends_with(".mp4") { args.extend_from_slice(&["-c:s".to_owned(), "mov_text".to_owned()]); @@ -982,7 +992,7 @@ pub(crate) fn download( } } - if subtitle_streams_count > 1 { + if subtitle_streams_count > 0 { args.extend_from_slice(&["-disposition:s:0".to_owned(), "default".to_owned()]); } } diff --git a/vsd/src/playlist.rs b/vsd/src/playlist.rs index c508d39..8b6a43f 100644 --- a/vsd/src/playlist.rs +++ b/vsd/src/playlist.rs @@ -100,7 +100,7 @@ impl MasterPlaylist { .map(|x| x.0) .chain(audio_streams.into_iter().map(|x| x.0)) .chain(subtitle_streams.into_iter().map(|x| x.0)) - .chain(undefined_streams.into_iter()) + .chain(undefined_streams) .collect::>(); self