cargo fmt
This commit is contained in:
parent
b5198194cf
commit
3113a50169
|
@ -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<String, VarError> {
|
|||
}
|
||||
|
||||
fn parse_var<E: Debug, T: FromStr<Err = E>>(name: &str) -> Result<T, VarError> {
|
||||
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"),
|
||||
|
|
39
src/main.rs
39
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,23 +56,26 @@ 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(
|
||||
match session
|
||||
.create_post(
|
||||
&conf.cohost_page,
|
||||
&mut eggbug::Post {
|
||||
content_warnings: vec![descriptor],
|
||||
|
@ -82,10 +85,12 @@ async fn main() {
|
|||
adult_content: false,
|
||||
headline: String::new(),
|
||||
markdown: String::new(),
|
||||
}
|
||||
).await {
|
||||
},
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(id) => info!("Created post {}", id),
|
||||
Err(e) => error!("Failed to create post: {}", e)
|
||||
Err(e) => error!("Failed to create post: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue