diff --git a/src/config.rs b/src/config.rs index 9f06828..54ab8da 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,4 +1,10 @@ -use std::{env::{self, VarError}, path::PathBuf, str::FromStr, fmt::Debug, time::Duration}; +use std::{ + env::{self, VarError}, + fmt::Debug, + path::PathBuf, + str::FromStr, + time::Duration, +}; pub struct Config { pub shows_file: PathBuf, @@ -16,7 +22,10 @@ fn get_var(name: &str) -> Result { } fn parse_var>(name: &str) -> Result { - get_var(name).map(|s| s.parse().expect(&format!("Failed to parse {}{}", VAR_PREFIX, name))) + get_var(name).map(|s| { + s.parse() + .expect(&format!("Failed to parse {}{}", VAR_PREFIX, name)) + }) } fn expect_var(name: &str) -> String { @@ -26,8 +35,10 @@ fn expect_var(name: &str) -> String { pub fn load() -> Config { Config { shows_file: parse_var("SHOWS_FILE").unwrap_or(PathBuf::from("./shows.yaml")), - global_tags: get_var("GLOBAL_TAGS").map(|s| s.split(",").map(String::from).collect()).unwrap_or_default(), - post_interval: Duration::from_secs(parse_var("POST_INTERVAL").unwrap_or(6*3600)), + global_tags: get_var("GLOBAL_TAGS") + .map(|s| s.split(",").map(String::from).collect()) + .unwrap_or_default(), + post_interval: Duration::from_secs(parse_var("POST_INTERVAL").unwrap_or(6 * 3600)), cohost_email: expect_var("COHOST_EMAIL"), cohost_password: expect_var("COHOST_PASSWORD"), cohost_page: expect_var("COHOST_PAGE"), diff --git a/src/main.rs b/src/main.rs index 890099d..83c4ba8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,13 +21,12 @@ async fn main() { let shows = shows::load(conf.shows_file); info!("Logging into cohost as {}", conf.cohost_email); - let session = eggbug::Session::login(&conf.cohost_email, &conf.cohost_password).await.expect("Failed to login to cohost"); + let session = eggbug::Session::login(&conf.cohost_email, &conf.cohost_password) + .await + .expect("Failed to login to cohost"); loop { - let (title, show) = shows - .iter() - .choose(&mut rng) - .expect("No shows found!"); + let (title, show) = shows.iter().choose(&mut rng).expect("No shows found!"); let (num, file) = show.episodes.iter().choose(&mut rng).unwrap(); let descriptor = format!( @@ -36,7 +35,8 @@ async fn main() { match num { EpisodeNumber::Standalone => String::new(), EpisodeNumber::SingleSeason(n) => format!(" episode {}", n), - EpisodeNumber::MultiSeason(season, ep) => format!(" season {} episode {}", season, ep), + EpisodeNumber::MultiSeason(season, ep) => + format!(" season {} episode {}", season, ep), } ); @@ -56,36 +56,41 @@ async fn main() { let formatted_timestamp = format_timestamp(timestamp, Some(video_info.duration_secs)); info!("Taking screencap at {}", formatted_timestamp); - match video::take_screencap( - file, - timestamp, - video_info.subtitle_stream_index, - ).await { - Err(e) => { error!("Failed to take screencap: {}", e); } + match video::take_screencap(file, timestamp, video_info.subtitle_stream_index).await { + Err(e) => { + error!("Failed to take screencap: {}", e); + } Ok(img_data) => { let attachment = eggbug::Attachment::new( img_data, format!("{} @{}.png", descriptor, formatted_timestamp), String::from("image/png"), - ).with_alt_text(format!("Screencap of {} at {}", descriptor, formatted_timestamp)); + ) + .with_alt_text(format!( + "Screencap of {} at {}", + descriptor, formatted_timestamp + )); let mut tags = show.tags.clone(); tags.extend_from_slice(&conf.global_tags); - match session.create_post( - &conf.cohost_page, - &mut eggbug::Post { - content_warnings: vec![descriptor], - attachments: vec![attachment], - tags, - draft: false, - adult_content: false, - headline: String::new(), - markdown: String::new(), - } - ).await { + match session + .create_post( + &conf.cohost_page, + &mut eggbug::Post { + content_warnings: vec![descriptor], + attachments: vec![attachment], + tags, + draft: false, + adult_content: false, + headline: String::new(), + markdown: String::new(), + }, + ) + .await + { Ok(id) => info!("Created post {}", id), - Err(e) => error!("Failed to create post: {}", e) + Err(e) => error!("Failed to create post: {}", e), } } } diff --git a/src/video.rs b/src/video.rs index 1330334..5b320dd 100644 --- a/src/video.rs +++ b/src/video.rs @@ -106,6 +106,6 @@ pub async fn take_screencap>( "ffmpeg command failed", )); } - + fs::read(&dest_path).await }