mirror of
https://framagit.org/veretcle/oolatoocs.git
synced 2025-07-20 20:41:17 +02:00
feat: add video/gif medias
This commit is contained in:
47
src/lib.rs
47
src/lib.rs
@@ -1,3 +1,6 @@
|
||||
mod error;
|
||||
pub use error::OolatoocsError;
|
||||
|
||||
mod config;
|
||||
pub use config::{parse_toml, Config};
|
||||
|
||||
@@ -15,8 +18,9 @@ use utils::strip_everything;
|
||||
|
||||
mod twitter;
|
||||
#[allow(unused_imports)]
|
||||
use twitter::{post_tweet, upload_media};
|
||||
use twitter::{post_tweet, upload_chunk_media, upload_simple_media};
|
||||
|
||||
use megalodon::entities::attachment::AttachmentType;
|
||||
use rusqlite::Connection;
|
||||
|
||||
#[tokio::main]
|
||||
@@ -36,9 +40,46 @@ pub async fn run(config: &Config) {
|
||||
let Ok(tweet_content) = strip_everything(&toot.content, &toot.tags) else {
|
||||
continue; // skip in case we can’t strip something
|
||||
};
|
||||
let mut medias: Vec<u64> = vec![];
|
||||
|
||||
// if we wanted to cut toot in half, now would be the right time to do so
|
||||
// treating medias (nothing for now)
|
||||
let tweet_id = post_tweet(&config.twitter, &tweet_content, &[])
|
||||
|
||||
for media in toot.media_attachments {
|
||||
let id = match media.r#type {
|
||||
AttachmentType::Image => {
|
||||
let Ok(id) =
|
||||
upload_simple_media(&config.twitter, &media.url, &media.description).await
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
id
|
||||
}
|
||||
AttachmentType::Gifv => {
|
||||
let Ok(id) = upload_chunk_media(&config.twitter, &media.url, "tweet_gif").await
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
id
|
||||
}
|
||||
AttachmentType::Video => {
|
||||
let Ok(id) =
|
||||
upload_chunk_media(&config.twitter, &media.url, "tweet_video").await
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
id
|
||||
}
|
||||
_ => {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
medias.push(id);
|
||||
}
|
||||
|
||||
println!("{:?}", medias);
|
||||
|
||||
let tweet_id = post_tweet(&config.twitter, &tweet_content, &medias)
|
||||
.await
|
||||
.unwrap_or_else(|e| panic!("Cannot Tweet {}: {}", toot.id, e));
|
||||
|
||||
|
Reference in New Issue
Block a user