From 78f9763b933c41bcb72c06fdde03b7880f6d7904 Mon Sep 17 00:00:00 2001 From: LinlyBoi Date: Thu, 10 Jul 2025 16:53:35 +0300 Subject: [PATCH] feat: add description file arg and metadata getter --- src/lib.rs | 15 +++++++++++++++ src/youtube.rs | 10 ++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5b4f52a..ad23636 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,6 +65,14 @@ pub struct Args { action = clap::ArgAction::SetTrue )] dry_run: bool, + + #[arg( + long = "description-file", + value_name = "DESCRIPTION_FILE", + help = "File random description to assign videos (For fun), not used if video has metadata", + default_value = "~/org/quotes.org" + )] + description_file: String } impl Args { @@ -91,6 +99,13 @@ impl Args { pub fn oauth_config(&self) -> &str { &self.oauth_config } + pub fn metadata(&self) -> Option<&String> { + self.metadata.as_ref() + } + + pub fn description_file(&self) -> &str { + &self.description_file + } } pub fn parse_duration(duration_str: &str) -> Result> { diff --git a/src/youtube.rs b/src/youtube.rs index 77ebca7..39f77f9 100644 --- a/src/youtube.rs +++ b/src/youtube.rs @@ -256,7 +256,8 @@ impl YouTubeUploader { } } -pub fn create_default_metadata(video_files: &[String]) -> Vec { +pub fn create_default_metadata(video_files: &[String], description_file: String) -> Vec { + let expanded_path = expand_tilde(&description_file); video_files .iter() .enumerate() @@ -269,7 +270,7 @@ pub fn create_default_metadata(video_files: &[String]) -> Vec { VideoMetadata { title: format!("{}", filename), - description: get_random_line("/home/linly/org/quotes.org").expect("WHAT DA HAIL"), + description: get_random_line(&expanded_path).unwrap(), tags: vec!["gaming".to_string()], category_id: "20".to_string(), // GAMING privacy_status: "private".to_string(), @@ -278,8 +279,9 @@ pub fn create_default_metadata(video_files: &[String]) -> Vec { }) .collect() } -fn get_random_line>(path: P) -> io::Result { - let file = File::open(path)?; +fn get_random_line(path: &str) -> io::Result { + let expanded_path = expand_tilde(path); + let file = File::open(expanded_path)?; let reader = BufReader::new(file); let lines: Vec = reader.lines().collect::>>()?;