Skip to content

Commit

Permalink
fixes for clitic#21
Browse files Browse the repository at this point in the history
  • Loading branch information
clitic committed Sep 14, 2023
1 parent 556ab12 commit 6e835ab
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ members = [
"vsd",
"vsd-mp4",
]
resolver = "2"
5 changes: 5 additions & 0 deletions vsd/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vsd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion vsd/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)]
Expand Down
36 changes: 23 additions & 13 deletions vsd/src/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!(
Expand All @@ -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(),
Expand Down Expand Up @@ -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::<Vec<_>>();
let video_streams_count = video_temp_files.len();
let audio_streams_count = temp_files
Expand All @@ -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()
Expand All @@ -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()]);
Expand Down Expand Up @@ -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()]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion vsd/src/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();

self
Expand Down

0 comments on commit 6e835ab

Please sign in to comment.