finish making default downloader use spawn_pipe
This commit is contained in:
parent
48f8d93516
commit
d229e184dc
3 changed files with 15 additions and 40 deletions
31
Cargo.lock
generated
31
Cargo.lock
generated
|
|
@ -489,12 +489,6 @@ version = "1.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6"
|
checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "fixedbitset"
|
|
||||||
version = "0.4.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flume"
|
name = "flume"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
|
|
@ -1101,7 +1095,6 @@ dependencies = [
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-appender",
|
"tracing-appender",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"tree_magic_mini",
|
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -1344,16 +1337,6 @@ version = "2.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "petgraph"
|
|
||||||
version = "0.6.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9"
|
|
||||||
dependencies = [
|
|
||||||
"fixedbitset",
|
|
||||||
"indexmap 2.2.3",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pin-project"
|
name = "pin-project"
|
||||||
version = "1.1.3"
|
version = "1.1.3"
|
||||||
|
|
@ -2560,20 +2543,6 @@ dependencies = [
|
||||||
"tracing-log",
|
"tracing-log",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tree_magic_mini"
|
|
||||||
version = "3.1.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "77ee137597cdb361b55a4746983e4ac1b35ab6024396a419944ad473bb915265"
|
|
||||||
dependencies = [
|
|
||||||
"fnv",
|
|
||||||
"home",
|
|
||||||
"memchr",
|
|
||||||
"nom",
|
|
||||||
"once_cell",
|
|
||||||
"petgraph",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "triomphe"
|
name = "triomphe"
|
||||||
version = "0.1.11"
|
version = "0.1.11"
|
||||||
|
|
|
||||||
|
|
@ -20,4 +20,3 @@ tracing = { version = "0.1.40", features = ["async-await"] }
|
||||||
tracing-appender = "0.2.3"
|
tracing-appender = "0.2.3"
|
||||||
tracing-subscriber = "0.3.18"
|
tracing-subscriber = "0.3.18"
|
||||||
rust-i18n = "3.0.1"
|
rust-i18n = "3.0.1"
|
||||||
tree_magic_mini = "3.1.4"
|
|
||||||
|
|
|
||||||
23
src/dl.rs
23
src/dl.rs
|
|
@ -1,8 +1,8 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use tracing::{event, Level};
|
use tracing::{event, Level};
|
||||||
|
|
||||||
use crate::security::sanitize::{extract_url, parse_url};
|
|
||||||
use crate::dl::ffmpeg::FFMpeg;
|
use crate::dl::ffmpeg::FFMpeg;
|
||||||
|
use crate::security::sanitize::{extract_url, parse_url};
|
||||||
|
|
||||||
use self::spawn::SpawnError;
|
use self::spawn::SpawnError;
|
||||||
use self::tmpfile::{TmpFile, TmpFileError};
|
use self::tmpfile::{TmpFile, TmpFileError};
|
||||||
|
|
@ -118,7 +118,8 @@ impl Downloader {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn tiktok_download(url: &str, info: &YtDlpInfo) -> Result<TmpFile, DownloadError> {
|
async fn tiktok_download(url: &str, info: &YtDlpInfo) -> Result<TmpFile, DownloadError> {
|
||||||
let original = info.formats
|
let original = info
|
||||||
|
.formats
|
||||||
.iter()
|
.iter()
|
||||||
.find(|f| f.format_id == "0")
|
.find(|f| f.format_id == "0")
|
||||||
.ok_or(DownloadError::NoFormatFound)?;
|
.ok_or(DownloadError::NoFormatFound)?;
|
||||||
|
|
@ -130,7 +131,7 @@ impl Downloader {
|
||||||
match self {
|
match self {
|
||||||
Downloader::Default => Self::default_download(url, info).await,
|
Downloader::Default => Self::default_download(url, info).await,
|
||||||
Downloader::YouTube => Self::youtube_download(url, info).await,
|
Downloader::YouTube => Self::youtube_download(url, info).await,
|
||||||
Downloader::TikTok => Self::tiktok_download(url, info).await
|
Downloader::TikTok => Self::tiktok_download(url, info).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +141,7 @@ impl fmt::Display for Downloader {
|
||||||
match self {
|
match self {
|
||||||
Downloader::Default => write!(f, "Default"),
|
Downloader::Default => write!(f, "Default"),
|
||||||
Downloader::YouTube => write!(f, "YouTube"),
|
Downloader::YouTube => write!(f, "YouTube"),
|
||||||
Downloader::TikTok => write!(f, "TikTok")
|
Downloader::TikTok => write!(f, "TikTok"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -149,19 +150,25 @@ pub async fn download(url: &str) -> Result<TmpFile, DownloadError> {
|
||||||
let url = parse_url(extract_url(url).ok_or(DownloadError::NotAnURL)?)
|
let url = parse_url(extract_url(url).ok_or(DownloadError::NotAnURL)?)
|
||||||
.ok_or(DownloadError::NotAnURL)?;
|
.ok_or(DownloadError::NotAnURL)?;
|
||||||
let host_url = url.host_str().ok_or(DownloadError::NotAnURL)?;
|
let host_url = url.host_str().ok_or(DownloadError::NotAnURL)?;
|
||||||
|
|
||||||
let downloader = &DOWNLOADERS
|
let downloader = &DOWNLOADERS
|
||||||
.iter()
|
.iter()
|
||||||
.find(|f| f.0 == host_url)
|
.find(|f| f.0 == host_url)
|
||||||
.unwrap_or(&DEFAULT_DOWNLOADER).1;
|
.unwrap_or(&DEFAULT_DOWNLOADER)
|
||||||
|
.1;
|
||||||
event!(Level::INFO, "using {} downloader for {}", downloader, url);
|
event!(Level::INFO, "using {} downloader for {}", downloader, url);
|
||||||
|
|
||||||
let info = YtDlp::load_info(url.as_str()).await?;
|
let info = YtDlp::load_info(url.as_str()).await?;
|
||||||
let output = match downloader.download(url.as_str(), &info).await {
|
let output = match downloader.download(url.as_str(), &info).await {
|
||||||
Ok(output) => output,
|
Ok(output) => output,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
event!(Level::ERROR, "downloader {} failed: {}. falling back to default downloader", downloader, e);
|
event!(
|
||||||
|
Level::ERROR,
|
||||||
|
"downloader {} failed: {}. falling back to default downloader",
|
||||||
|
downloader,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
|
||||||
DEFAULT_DOWNLOADER.1.download(url.as_str(), &info).await?
|
DEFAULT_DOWNLOADER.1.download(url.as_str(), &info).await?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue