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 struct Config {
|
||||||
pub shows_file: PathBuf,
|
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> {
|
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 {
|
fn expect_var(name: &str) -> String {
|
||||||
|
@ -26,8 +35,10 @@ fn expect_var(name: &str) -> String {
|
||||||
pub fn load() -> Config {
|
pub fn load() -> Config {
|
||||||
Config {
|
Config {
|
||||||
shows_file: parse_var("SHOWS_FILE").unwrap_or(PathBuf::from("./shows.yaml")),
|
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(),
|
global_tags: get_var("GLOBAL_TAGS")
|
||||||
post_interval: Duration::from_secs(parse_var("POST_INTERVAL").unwrap_or(6*3600)),
|
.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_email: expect_var("COHOST_EMAIL"),
|
||||||
cohost_password: expect_var("COHOST_PASSWORD"),
|
cohost_password: expect_var("COHOST_PASSWORD"),
|
||||||
cohost_page: expect_var("COHOST_PAGE"),
|
cohost_page: expect_var("COHOST_PAGE"),
|
||||||
|
|
57
src/main.rs
57
src/main.rs
|
@ -21,13 +21,12 @@ async fn main() {
|
||||||
let shows = shows::load(conf.shows_file);
|
let shows = shows::load(conf.shows_file);
|
||||||
|
|
||||||
info!("Logging into cohost as {}", conf.cohost_email);
|
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 {
|
loop {
|
||||||
let (title, show) = shows
|
let (title, show) = shows.iter().choose(&mut rng).expect("No shows found!");
|
||||||
.iter()
|
|
||||||
.choose(&mut rng)
|
|
||||||
.expect("No shows found!");
|
|
||||||
let (num, file) = show.episodes.iter().choose(&mut rng).unwrap();
|
let (num, file) = show.episodes.iter().choose(&mut rng).unwrap();
|
||||||
|
|
||||||
let descriptor = format!(
|
let descriptor = format!(
|
||||||
|
@ -36,7 +35,8 @@ async fn main() {
|
||||||
match num {
|
match num {
|
||||||
EpisodeNumber::Standalone => String::new(),
|
EpisodeNumber::Standalone => String::new(),
|
||||||
EpisodeNumber::SingleSeason(n) => format!(" episode {}", n),
|
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));
|
let formatted_timestamp = format_timestamp(timestamp, Some(video_info.duration_secs));
|
||||||
info!("Taking screencap at {}", formatted_timestamp);
|
info!("Taking screencap at {}", formatted_timestamp);
|
||||||
|
|
||||||
match video::take_screencap(
|
match video::take_screencap(file, timestamp, video_info.subtitle_stream_index).await {
|
||||||
file,
|
Err(e) => {
|
||||||
timestamp,
|
error!("Failed to take screencap: {}", e);
|
||||||
video_info.subtitle_stream_index,
|
}
|
||||||
).await {
|
|
||||||
Err(e) => { error!("Failed to take screencap: {}", e); }
|
|
||||||
Ok(img_data) => {
|
Ok(img_data) => {
|
||||||
let attachment = eggbug::Attachment::new(
|
let attachment = eggbug::Attachment::new(
|
||||||
img_data,
|
img_data,
|
||||||
format!("{} @{}.png", descriptor, formatted_timestamp),
|
format!("{} @{}.png", descriptor, formatted_timestamp),
|
||||||
String::from("image/png"),
|
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();
|
let mut tags = show.tags.clone();
|
||||||
tags.extend_from_slice(&conf.global_tags);
|
tags.extend_from_slice(&conf.global_tags);
|
||||||
|
|
||||||
match session.create_post(
|
match session
|
||||||
&conf.cohost_page,
|
.create_post(
|
||||||
&mut eggbug::Post {
|
&conf.cohost_page,
|
||||||
content_warnings: vec![descriptor],
|
&mut eggbug::Post {
|
||||||
attachments: vec![attachment],
|
content_warnings: vec![descriptor],
|
||||||
tags,
|
attachments: vec![attachment],
|
||||||
draft: false,
|
tags,
|
||||||
adult_content: false,
|
draft: false,
|
||||||
headline: String::new(),
|
adult_content: false,
|
||||||
markdown: String::new(),
|
headline: String::new(),
|
||||||
}
|
markdown: String::new(),
|
||||||
).await {
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(id) => info!("Created post {}", id),
|
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