From 6f5e5bf9e53f6586dcff3e0406adfae2f383c0b4 Mon Sep 17 00:00:00 2001 From: Nick Zana Date: Thu, 4 May 2023 21:55:21 -0400 Subject: [PATCH] add cookie jar support and live_from_start flag --- src/config.rs | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/config.rs b/src/config.rs index 6c5925f..6e41145 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,7 +5,10 @@ use youtube_dl::{YoutubeDl, YoutubeDlOutput}; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct Config { + #[serde(rename = "ytdl-path")] pub youtube_dl_path: Option, + #[serde(rename = "cookies")] + pub cookie_jar_path: Option, pub output: PathBuf, pub streams: Vec, } @@ -29,6 +32,9 @@ pub enum Stream { subpath: Option, // Overrides Config::output, still respects subpath (becomes relative to new output) output: Option, + // YouTube only + #[serde(default)] + live_from_start: bool, }, } @@ -45,26 +51,34 @@ impl Stream { quality, subpath, output, + live_from_start, } => { - loop { - // TODO: Can this dl struct be reused? - let mut dl = YoutubeDl::new(url); - dl.download(true); + let mut dl = YoutubeDl::new(url); + dl.download(true); - if let Some(path) = &config.youtube_dl_path { - dl.youtube_dl_path(path); - } + if let Some(path) = &config.youtube_dl_path { + dl.youtube_dl_path(path); + } - if let Some(quality) = quality { - dl.format(quality); - } + if let Some(quality) = quality { + dl.format(quality); + } - let mut output_dir = output.clone().unwrap_or(config.output.clone()); - if let Some(subpath) = subpath { - output_dir = output_dir.join(subpath); - } - dl.output_directory(output_dir.to_string_lossy()); + let mut output_dir = output.clone().unwrap_or(config.output.clone()); + if let Some(subpath) = subpath { + output_dir = output_dir.join(subpath); + } + 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 { Ok(YoutubeDlOutput::SingleVideo(video)) => { println!("Successfully downloading video `{url:#?}`: {video:#?}");