use bleeding-edge eggbug for up-to-date attachment API

This commit is contained in:
xenofem 2023-07-01 19:48:31 -04:00
parent 9c2b726faa
commit 11a315e059
3 changed files with 99 additions and 38 deletions

37
Cargo.lock generated
View file

@ -11,6 +11,12 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
@ -97,6 +103,17 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5"
dependencies = [
"android-tzdata",
"num-traits",
"serde",
]
[[package]] [[package]]
name = "clang-sys" name = "clang-sys"
version = "1.6.1" version = "1.6.1"
@ -201,11 +218,11 @@ checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
[[package]] [[package]]
name = "eggbug" name = "eggbug"
version = "0.1.3" version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/iliana/eggbug-rs.git?branch=main#94fc2f652a842b0fadfff62750562630e887672a"
checksum = "077e6288b1613f96b53e63c78a05d969c13269d93bc3a4b4fa5374480899c2d5"
dependencies = [ dependencies = [
"base64 0.13.1", "base64 0.13.1",
"bytes", "bytes",
"chrono",
"derive_more", "derive_more",
"futures", "futures",
"hmac", "hmac",
@ -600,6 +617,12 @@ dependencies = [
"unicode-normalization", "unicode-normalization",
] ]
[[package]]
name = "imagesize"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "029d73f573d8e8d63e6d5020011d3255b28c3ba85d6cf870a07184ed23de9284"
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.9.3" version = "1.9.3"
@ -796,6 +819,15 @@ dependencies = [
"minimal-lexical", "minimal-lexical",
] ]
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "num_cpus" name = "num_cpus"
version = "1.15.0" version = "1.15.0"
@ -1105,6 +1137,7 @@ dependencies = [
"eggbug", "eggbug",
"env_logger", "env_logger",
"ffmpeg-next", "ffmpeg-next",
"imagesize",
"lazy_static", "lazy_static",
"log", "log",
"rand", "rand",

View file

@ -7,9 +7,10 @@ license = "MIT"
[dependencies] [dependencies]
dotenvy = "0.15.7" dotenvy = "0.15.7"
eggbug = "0.1.3" eggbug = { git = "https://github.com/iliana/eggbug-rs.git", branch = "main" }
env_logger = "0.10" env_logger = "0.10"
ffmpeg-next = "6.0.0" ffmpeg-next = "6.0.0"
imagesize = "0.12.0"
lazy_static = "1.4.0" lazy_static = "1.4.0"
log = "0.4.19" log = "0.4.19"
rand = "0.8" rand = "0.8"

View file

@ -1,3 +1,6 @@
use std::time::Duration;
use lazy_static::lazy_static;
use log::{debug, error, info}; use log::{debug, error, info};
use rand::{distributions::Standard, seq::IteratorRandom, Rng}; use rand::{distributions::Standard, seq::IteratorRandom, Rng};
@ -7,6 +10,10 @@ mod video;
use crate::shows::EpisodeNumber; use crate::shows::EpisodeNumber;
lazy_static! {
static ref RETRY_INTERVAL: Duration = Duration::from_secs(30);
}
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
@ -31,6 +38,7 @@ async fn main() {
Ok(eps) => eps, Ok(eps) => eps,
Err(e) => { Err(e) => {
error!("Failed to get episodes for {}: {}", title, e); error!("Failed to get episodes for {}: {}", title, e);
tokio::time::sleep(*RETRY_INTERVAL).await;
continue; continue;
} }
}; };
@ -63,42 +71,61 @@ 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(file, timestamp, video_info.subtitle_stream_index).await { let img_data =
Err(e) => { match video::take_screencap(file, timestamp, video_info.subtitle_stream_index).await {
error!("Failed to take screencap: {}", e); Ok(data) => data,
} Err(e) => {
Ok(img_data) => { error!("Failed to take screencap: {}", e);
let attachment = eggbug::Attachment::new( tokio::time::sleep(*RETRY_INTERVAL).await;
img_data, continue;
format!("{} @{}.png", descriptor, formatted_timestamp),
String::from("image/png"),
)
.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
{
Ok(id) => info!("Created post {}", id),
Err(e) => error!("Failed to create post: {}", e),
} }
};
let img_size = match imagesize::blob_size(&img_data) {
Ok(size) => size,
Err(e) => {
error!("Failed to get image size: {}", e);
tokio::time::sleep(*RETRY_INTERVAL).await;
continue;
}
};
let attachment = eggbug::Attachment::new(
img_data,
format!("{} @{}.png", descriptor, formatted_timestamp),
String::from("image/png"),
Some(img_size.width as u32),
Some(img_size.height as u32),
)
.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(),
metadata: None,
},
)
.await
{
Ok(id) => info!("Created post {}", id),
Err(e) => {
error!("Failed to create post: {}", e);
tokio::time::sleep(*RETRY_INTERVAL).await;
continue;
} }
} }