mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-21 09:31:19 +02:00
style: fmt & clippy processed
This commit is contained in:
@@ -1,23 +1,25 @@
|
||||
use crate::ScootalooError;
|
||||
use crate::config::TwitterConfig;
|
||||
use crate::util::cache_media;
|
||||
use crate::ScootalooError;
|
||||
|
||||
use std::error::Error;
|
||||
use egg_mode::{
|
||||
Token,
|
||||
KeyPair,
|
||||
entities::{MediaEntity, MediaType},
|
||||
tweet::{user_timeline, Tweet},
|
||||
user::UserID,
|
||||
tweet::{
|
||||
Tweet,
|
||||
user_timeline,
|
||||
},
|
||||
KeyPair, Token,
|
||||
};
|
||||
use std::error::Error;
|
||||
|
||||
/// Gets Twitter oauth2 token
|
||||
pub fn get_oauth2_token(config: &TwitterConfig) -> Token {
|
||||
let con_token = KeyPair::new(config.consumer_key.to_owned(),config.consumer_secret.to_owned());
|
||||
let access_token = KeyPair::new(config.access_key.to_owned(), config.access_secret.to_owned());
|
||||
let con_token = KeyPair::new(
|
||||
config.consumer_key.to_owned(),
|
||||
config.consumer_secret.to_owned(),
|
||||
);
|
||||
let access_token = KeyPair::new(
|
||||
config.access_key.to_owned(),
|
||||
config.access_secret.to_owned(),
|
||||
);
|
||||
|
||||
Token::Access {
|
||||
consumer: con_token,
|
||||
@@ -26,12 +28,21 @@ pub fn get_oauth2_token(config: &TwitterConfig) -> Token {
|
||||
}
|
||||
|
||||
/// Gets Twitter user timeline
|
||||
pub async fn get_user_timeline(config: &TwitterConfig, token: Token, lid: Option<u64>) -> Result<Vec<Tweet>, Box<dyn Error>> {
|
||||
pub async fn get_user_timeline(
|
||||
config: &TwitterConfig,
|
||||
token: Token,
|
||||
lid: Option<u64>,
|
||||
) -> Result<Vec<Tweet>, Box<dyn Error>> {
|
||||
// fix the page size to 200 as it is the maximum Twitter authorizes
|
||||
let (_, feed) = user_timeline(UserID::from(config.username.to_owned()), true, false, &token)
|
||||
.with_page_size(200)
|
||||
.older(lid)
|
||||
.await?;
|
||||
let (_, feed) = user_timeline(
|
||||
UserID::from(config.username.to_owned()),
|
||||
true,
|
||||
false,
|
||||
&token,
|
||||
)
|
||||
.with_page_size(200)
|
||||
.older(lid)
|
||||
.await?;
|
||||
|
||||
Ok(feed.to_vec())
|
||||
}
|
||||
@@ -41,22 +52,27 @@ pub async fn get_tweet_media(m: &MediaEntity, t: &str) -> Result<String, Box<dyn
|
||||
match m.media_type {
|
||||
MediaType::Photo => {
|
||||
return cache_media(&m.media_url_https, t).await;
|
||||
},
|
||||
_ => {
|
||||
match &m.video_info {
|
||||
Some(v) => {
|
||||
for variant in &v.variants {
|
||||
if variant.content_type == "video/mp4" {
|
||||
return cache_media(&variant.url, t).await;
|
||||
}
|
||||
}
|
||||
_ => match &m.video_info {
|
||||
Some(v) => {
|
||||
for variant in &v.variants {
|
||||
if variant.content_type == "video/mp4" {
|
||||
return cache_media(&variant.url, t).await;
|
||||
}
|
||||
return Err(ScootalooError::new(&format!("Media Type for {} is video but no mp4 file URL is available", &m.url)).into());
|
||||
},
|
||||
None => {
|
||||
return Err(ScootalooError::new(&format!("Media Type for {} is video but does not contain any video_info", &m.url)).into());
|
||||
},
|
||||
}
|
||||
return Err(ScootalooError::new(&format!(
|
||||
"Media Type for {} is video but no mp4 file URL is available",
|
||||
&m.url
|
||||
))
|
||||
.into());
|
||||
}
|
||||
None => {
|
||||
return Err(ScootalooError::new(&format!(
|
||||
"Media Type for {} is video but does not contain any video_info",
|
||||
&m.url
|
||||
))
|
||||
.into());
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user