v1.1.0: optional season/part naming, draft mode
This commit is contained in:
parent
22d2686343
commit
18497a8cbd
7 changed files with 28 additions and 16 deletions
|
@ -13,6 +13,7 @@ pub struct Config {
|
|||
pub cohost_email: String,
|
||||
pub cohost_password: String,
|
||||
pub cohost_page: String,
|
||||
pub cohost_draft: bool,
|
||||
}
|
||||
|
||||
const VAR_PREFIX: &str = "SCREENCAP_BOT_";
|
||||
|
@ -42,5 +43,6 @@ pub fn load() -> Config {
|
|||
cohost_email: expect_var("COHOST_EMAIL"),
|
||||
cohost_password: expect_var("COHOST_PASSWORD"),
|
||||
cohost_page: expect_var("COHOST_PAGE"),
|
||||
cohost_draft: parse_var("COHOST_DRAFT").unwrap_or(false),
|
||||
}
|
||||
}
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -11,8 +11,6 @@ mod config;
|
|||
mod shows;
|
||||
mod video;
|
||||
|
||||
use crate::shows::EpisodeNumber;
|
||||
|
||||
lazy_static! {
|
||||
static ref RETRY_INTERVAL: Duration = Duration::from_secs(30);
|
||||
}
|
||||
|
@ -79,15 +77,7 @@ async fn post_random_screencap<R: Rng>(
|
|||
})?;
|
||||
let (num, file) = episodes.iter().choose(rng).unwrap();
|
||||
|
||||
let descriptor = format!(
|
||||
"{}{}",
|
||||
title,
|
||||
match num {
|
||||
EpisodeNumber::Standalone => String::new(),
|
||||
EpisodeNumber::SingleSeason(n) => format!(" episode {}", n),
|
||||
EpisodeNumber::MultiSeason(season, ep) => format!(" season {} episode {}", season, ep),
|
||||
}
|
||||
);
|
||||
let descriptor = shows::display_show_episode(title, show, *num);
|
||||
|
||||
info!("Selected: {} - {}", descriptor, file.display());
|
||||
|
||||
|
@ -139,7 +129,7 @@ async fn post_random_screencap<R: Rng>(
|
|||
content_warnings: vec![descriptor],
|
||||
attachments: vec![attachment],
|
||||
tags,
|
||||
draft: false,
|
||||
draft: conf.cohost_draft,
|
||||
adult_content: false,
|
||||
headline: String::new(),
|
||||
markdown: String::new(),
|
||||
|
|
|
@ -15,11 +15,13 @@ pub struct Show {
|
|||
pub path: PathBuf,
|
||||
#[serde(default)]
|
||||
pub tags: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub parts: HashMap<u32, String>,
|
||||
}
|
||||
|
||||
pub type Shows = HashMap<String, Show>;
|
||||
|
||||
#[derive(Debug, Eq, Hash, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum EpisodeNumber {
|
||||
Standalone,
|
||||
SingleSeason(u32),
|
||||
|
@ -33,6 +35,21 @@ pub fn load<P: AsRef<Path>>(shows_file: P) -> anyhow::Result<Shows> {
|
|||
.context("Failed to parse YAML from shows file")
|
||||
}
|
||||
|
||||
pub fn display_show_episode(title: &str, show: &Show, episode: EpisodeNumber) -> String {
|
||||
match episode {
|
||||
EpisodeNumber::Standalone => title.to_string(),
|
||||
EpisodeNumber::SingleSeason(n) => format!("{} episode {}", title, n),
|
||||
EpisodeNumber::MultiSeason(season, ep) => format!(
|
||||
"{} {} episode {}",
|
||||
title,
|
||||
show.parts
|
||||
.get(&season)
|
||||
.unwrap_or(&format!("season {}", season)),
|
||||
ep
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
impl Show {
|
||||
pub fn episodes(&self) -> anyhow::Result<Episodes> {
|
||||
let path = &self.path;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue