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

View file

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

View file

@ -1,3 +1,6 @@
use std::time::Duration;
use lazy_static::lazy_static;
use log::{debug, error, info};
use rand::{distributions::Standard, seq::IteratorRandom, Rng};
@ -7,6 +10,10 @@ mod video;
use crate::shows::EpisodeNumber;
lazy_static! {
static ref RETRY_INTERVAL: Duration = Duration::from_secs(30);
}
#[tokio::main]
async fn main() {
dotenvy::dotenv().ok();
@ -31,6 +38,7 @@ async fn main() {
Ok(eps) => eps,
Err(e) => {
error!("Failed to get episodes for {}: {}", title, e);
tokio::time::sleep(*RETRY_INTERVAL).await;
continue;
}
};
@ -63,15 +71,31 @@ async fn main() {
let formatted_timestamp = format_timestamp(timestamp, Some(video_info.duration_secs));
info!("Taking screencap at {}", formatted_timestamp);
let img_data =
match video::take_screencap(file, timestamp, video_info.subtitle_stream_index).await {
Ok(data) => data,
Err(e) => {
error!("Failed to take screencap: {}", e);
tokio::time::sleep(*RETRY_INTERVAL).await;
continue;
}
Ok(img_data) => {
};
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 {}",
@ -92,13 +116,16 @@ async fn main() {
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),
}
Err(e) => {
error!("Failed to create post: {}", e);
tokio::time::sleep(*RETRY_INTERVAL).await;
continue;
}
}