v1.1.0: optional season/part naming, draft mode
This commit is contained in:
parent
22d2686343
commit
18497a8cbd
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
/target
|
/target
|
||||||
/result
|
/result
|
||||||
/shows.yaml
|
/shows*.yaml
|
||||||
|
/.env
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1137,7 +1137,7 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "screencap-bot"
|
name = "screencap-bot"
|
||||||
version = "1.0.0"
|
version = "1.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "screencap-bot"
|
name = "screencap-bot"
|
||||||
version = "1.0.0"
|
version = "1.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["xenofem <xenofem@xeno.science>"]
|
authors = ["xenofem <xenofem@xeno.science>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -24,6 +24,8 @@ directory:
|
||||||
- `SCREENCAP_BOT_COHOST_EMAIL`: the email address the bot should use to log into cohost
|
- `SCREENCAP_BOT_COHOST_EMAIL`: the email address the bot should use to log into cohost
|
||||||
- `SCREENCAP_BOT_COHOST_PASSWORD`: the password the bot should use to log into cohost
|
- `SCREENCAP_BOT_COHOST_PASSWORD`: the password the bot should use to log into cohost
|
||||||
- `SCREENCAP_BOT_COHOST_PAGE`: the cohost page the bot should post from
|
- `SCREENCAP_BOT_COHOST_PAGE`: the cohost page the bot should post from
|
||||||
|
- `SCREENCAP_BOT_COHOST_DRAFT`: whether to create cohost posts as
|
||||||
|
drafts, eg for testing (default: `false`)
|
||||||
- `RUST_LOG`: log levels, for the app as a whole and/or for specific
|
- `RUST_LOG`: log levels, for the app as a whole and/or for specific
|
||||||
submodules/libraries. See
|
submodules/libraries. See
|
||||||
[`env_logger`](https://docs.rs/env_logger/latest/env_logger/)'s
|
[`env_logger`](https://docs.rs/env_logger/latest/env_logger/)'s
|
||||||
|
|
|
@ -13,6 +13,7 @@ pub struct Config {
|
||||||
pub cohost_email: String,
|
pub cohost_email: String,
|
||||||
pub cohost_password: String,
|
pub cohost_password: String,
|
||||||
pub cohost_page: String,
|
pub cohost_page: String,
|
||||||
|
pub cohost_draft: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
const VAR_PREFIX: &str = "SCREENCAP_BOT_";
|
const VAR_PREFIX: &str = "SCREENCAP_BOT_";
|
||||||
|
@ -42,5 +43,6 @@ pub fn load() -> Config {
|
||||||
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"),
|
||||||
|
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 shows;
|
||||||
mod video;
|
mod video;
|
||||||
|
|
||||||
use crate::shows::EpisodeNumber;
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref RETRY_INTERVAL: Duration = Duration::from_secs(30);
|
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 (num, file) = episodes.iter().choose(rng).unwrap();
|
||||||
|
|
||||||
let descriptor = format!(
|
let descriptor = shows::display_show_episode(title, show, *num);
|
||||||
"{}{}",
|
|
||||||
title,
|
|
||||||
match num {
|
|
||||||
EpisodeNumber::Standalone => String::new(),
|
|
||||||
EpisodeNumber::SingleSeason(n) => format!(" episode {}", n),
|
|
||||||
EpisodeNumber::MultiSeason(season, ep) => format!(" season {} episode {}", season, ep),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
info!("Selected: {} - {}", descriptor, file.display());
|
info!("Selected: {} - {}", descriptor, file.display());
|
||||||
|
|
||||||
|
@ -139,7 +129,7 @@ async fn post_random_screencap<R: Rng>(
|
||||||
content_warnings: vec![descriptor],
|
content_warnings: vec![descriptor],
|
||||||
attachments: vec![attachment],
|
attachments: vec![attachment],
|
||||||
tags,
|
tags,
|
||||||
draft: false,
|
draft: conf.cohost_draft,
|
||||||
adult_content: false,
|
adult_content: false,
|
||||||
headline: String::new(),
|
headline: String::new(),
|
||||||
markdown: String::new(),
|
markdown: String::new(),
|
||||||
|
|
|
@ -15,11 +15,13 @@ pub struct Show {
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub tags: Vec<String>,
|
pub tags: Vec<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub parts: HashMap<u32, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Shows = HashMap<String, Show>;
|
pub type Shows = HashMap<String, Show>;
|
||||||
|
|
||||||
#[derive(Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
pub enum EpisodeNumber {
|
pub enum EpisodeNumber {
|
||||||
Standalone,
|
Standalone,
|
||||||
SingleSeason(u32),
|
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")
|
.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 {
|
impl Show {
|
||||||
pub fn episodes(&self) -> anyhow::Result<Episodes> {
|
pub fn episodes(&self) -> anyhow::Result<Episodes> {
|
||||||
let path = &self.path;
|
let path = &self.path;
|
||||||
|
|
Loading…
Reference in a new issue