parent
d9c45bb2e0
commit
235017ba29
4 changed files with 34 additions and 9 deletions
|
@ -30,6 +30,7 @@ rustls-tls-native-roots = [
|
|||
|
||||
[dependencies]
|
||||
rustypipe = { path = "..", default-features = false }
|
||||
rustypipe-postprocessor = { path = "../postprocessor" }
|
||||
once_cell = "1.12.0"
|
||||
regex = "1.6.0"
|
||||
thiserror = "1.0.36"
|
||||
|
|
|
@ -14,7 +14,7 @@ use rand::Rng;
|
|||
use regex::Regex;
|
||||
use reqwest::{header, Client};
|
||||
use rustypipe::{
|
||||
model::{traits::FileFormat, AudioCodec, VideoCodec, VideoPlayer},
|
||||
model::{traits::FileFormat, AudioCodec, AudioFormat, VideoCodec, VideoPlayer},
|
||||
param::StreamFilter,
|
||||
};
|
||||
use tokio::{
|
||||
|
@ -346,13 +346,34 @@ pub async fn download_video(
|
|||
// Downloading combined video/audio stream (no conversion)
|
||||
(Some(video), None) => {
|
||||
pb.set_message(format!("Downloading {title}"));
|
||||
download_single_file(
|
||||
&video.url,
|
||||
download_dir.join(output_fname).with_extension(&format),
|
||||
http,
|
||||
pb.clone(),
|
||||
)
|
||||
.await?;
|
||||
download_single_file(&video.url, output_path, http, pb.clone()).await?;
|
||||
}
|
||||
// Downloading audio only
|
||||
(None, Some(audio)) => {
|
||||
pb.set_message(format!("Downloading {title}"));
|
||||
|
||||
let (dl_path, postprocessor) = match (audio.format, audio.codec) {
|
||||
(AudioFormat::M4a, AudioCodec::Mp4a) => (output_path.clone(), None),
|
||||
(AudioFormat::Webm, AudioCodec::Opus) => (
|
||||
download_dir.join(format!(
|
||||
"{}.audio{}",
|
||||
output_fname,
|
||||
audio.format.extension()
|
||||
)),
|
||||
Some(AudioFormat::Webm),
|
||||
),
|
||||
_ => (output_path.clone(), None),
|
||||
};
|
||||
|
||||
download_single_file(&audio.url, &dl_path, http, pb.clone()).await?;
|
||||
|
||||
if let Some(postprocessor) = postprocessor {
|
||||
pb.set_message(format!("Converting {title}"));
|
||||
if postprocessor == AudioFormat::Webm {
|
||||
rustypipe_postprocessor::ogg_from_webm::process(&dl_path, &output_path)?;
|
||||
}
|
||||
fs::remove_file(&dl_path).await?;
|
||||
}
|
||||
}
|
||||
// Downloading split video/audio streams (requires conversion with ffmpeg)
|
||||
_ => {
|
||||
|
|
|
@ -20,6 +20,8 @@ pub enum DownloadError {
|
|||
Input(Cow<'static, str>),
|
||||
#[error("error: {0}")]
|
||||
Other(Cow<'static, str>),
|
||||
#[error("Postprocessing error: {0}")]
|
||||
Postprocessing(#[from] rustypipe_postprocessor::PostprocessingError),
|
||||
}
|
||||
|
||||
/// Split an URL into its base string and parameter map
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
pub mod ogg_from_webm;
|
||||
|
||||
mod crc;
|
||||
mod ogg;
|
||||
mod ogg_from_webm;
|
||||
mod webm;
|
||||
|
||||
/// Error from the postprocessor
|
||||
|
|
Loading…
Add table
Reference in a new issue