feat: add description file arg and metadata getter
This commit is contained in:
15
src/lib.rs
15
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<Duration, Box<dyn std::error::Error>> {
|
||||
|
||||
@@ -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>>>()?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user