feat: add video/gif medias

This commit is contained in:
VC
2023-11-09 18:40:28 +01:00
parent 6fca84c3be
commit eba13ba095
5 changed files with 411 additions and 17 deletions

View File

@@ -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 cant 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));