add cookie jar support and live_from_start flag

main
Nick Zana 2 years ago
parent 986e677ade
commit 6f5e5bf9e5

@ -5,7 +5,10 @@ use youtube_dl::{YoutubeDl, YoutubeDlOutput};
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Config { pub struct Config {
#[serde(rename = "ytdl-path")]
pub youtube_dl_path: Option<PathBuf>, pub youtube_dl_path: Option<PathBuf>,
#[serde(rename = "cookies")]
pub cookie_jar_path: Option<PathBuf>,
pub output: PathBuf, pub output: PathBuf,
pub streams: Vec<Stream>, pub streams: Vec<Stream>,
} }
@ -29,6 +32,9 @@ pub enum Stream {
subpath: Option<PathBuf>, subpath: Option<PathBuf>,
// Overrides Config::output, still respects subpath (becomes relative to new output) // Overrides Config::output, still respects subpath (becomes relative to new output)
output: Option<PathBuf>, output: Option<PathBuf>,
// YouTube only
#[serde(default)]
live_from_start: bool,
}, },
} }
@ -45,9 +51,8 @@ impl Stream {
quality, quality,
subpath, subpath,
output, output,
live_from_start,
} => { } => {
loop {
// TODO: Can this dl struct be reused?
let mut dl = YoutubeDl::new(url); let mut dl = YoutubeDl::new(url);
dl.download(true); dl.download(true);
@ -65,6 +70,15 @@ impl Stream {
} }
dl.output_directory(output_dir.to_string_lossy()); dl.output_directory(output_dir.to_string_lossy());
if let Some(path) = &config.cookie_jar_path {
dl.cookies(path.to_string_lossy());
}
if *live_from_start {
dl.extra_arg("--live-from-start");
}
loop {
match dl.run_async().await { match dl.run_async().await {
Ok(YoutubeDlOutput::SingleVideo(video)) => { Ok(YoutubeDlOutput::SingleVideo(video)) => {
println!("Successfully downloading video `{url:#?}`: {video:#?}"); println!("Successfully downloading video `{url:#?}`: {video:#?}");

Loading…
Cancel
Save