use bleeding-edge eggbug for up-to-date attachment API
This commit is contained in:
parent
9c2b726faa
commit
11a315e059
3 changed files with 99 additions and 38 deletions
97
src/main.rs
97
src/main.rs
|
@ -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,42 +71,61 @@ async fn main() {
|
|||
let formatted_timestamp = format_timestamp(timestamp, Some(video_info.duration_secs));
|
||||
info!("Taking screencap at {}", formatted_timestamp);
|
||||
|
||||
match video::take_screencap(file, timestamp, video_info.subtitle_stream_index).await {
|
||||
Err(e) => {
|
||||
error!("Failed to take screencap: {}", e);
|
||||
}
|
||||
Ok(img_data) => {
|
||||
let attachment = eggbug::Attachment::new(
|
||||
img_data,
|
||||
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_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;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue