feat: use megalodon instead of elefren

This commit is contained in:
VC
2022-11-29 18:20:13 +01:00
parent 19f75a9e76
commit 7f42c9d01a
5 changed files with 92 additions and 68 deletions

View File

@@ -1,22 +1,16 @@
use crate::{twitter::get_tweet_media, ScootalooError};
use std::{borrow::Cow, error::Error};
use egg_mode::tweet::Tweet;
use elefren::prelude::*;
use futures::{stream, stream::StreamExt};
use log::{error, info, warn};
use megalodon::{mastodon::Mastodon, megalodon::Megalodon};
use reqwest::Url;
use std::error::Error;
use tokio::{
fs::{create_dir_all, remove_file, File},
io::copy,
};
use futures::{stream, stream::StreamExt};
/// Generate associative table between media ids and tweet extended entities
pub async fn generate_media_ids(
tweet: &Tweet,
@@ -46,8 +40,10 @@ pub async fn generate_media_ids(
let local_tweet_media_path = get_tweet_media(&media, &cache_path).await?;
// upload media to Mastodon
let mastodon_media =
mastodon.media(Cow::from(local_tweet_media_path.to_owned()))?;
let mastodon_media = mastodon
.upload_media(local_tweet_media_path.to_owned(), None)
.await?
.json();
// at this point, we can safely erase the original file
// it doesnt matter if we cant remove, cache_media fn is idempotent
remove_file(&local_tweet_media_path).await.ok();