feat: add description file arg and metadata getter

This commit is contained in:
LinlyBoi
2025-07-10 16:53:35 +03:00
parent 61678f5455
commit 78f9763b93
2 changed files with 21 additions and 4 deletions

View File

@@ -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<Duration, Box<dyn std::error::Error>> {

View File

@@ -256,7 +256,8 @@ impl YouTubeUploader {
}
}
pub fn create_default_metadata(video_files: &[String]) -> Vec<VideoMetadata> {
pub fn create_default_metadata(video_files: &[String], description_file: String) -> Vec<VideoMetadata> {
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> {
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<VideoMetadata> {
})
.collect()
}
fn get_random_line<P: AsRef<Path>>(path: P) -> io::Result<String> {
let file = File::open(path)?;
fn get_random_line(path: &str) -> io::Result<String> {
let expanded_path = expand_tilde(path);
let file = File::open(expanded_path)?;
let reader = BufReader::new(file);
let lines: Vec<String> = reader.lines().collect::<io::Result<Vec<String>>>()?;