Main: Support downloading thumbnails from events instead of the actual media
This commit is contained in:
parent
ef7fc3c6a9
commit
0a319d82b9
1 changed files with 30 additions and 3 deletions
33
src/main.rs
33
src/main.rs
|
@ -247,6 +247,10 @@ struct Arguments {
|
|||
element_export_path: Option<PathBuf>,
|
||||
|
||||
mxc_url: Option<String>,
|
||||
|
||||
/// When used with an event, download the thumbnail instead of the actual media.
|
||||
#[clap(long, env)]
|
||||
thumbnail: bool,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
@ -256,7 +260,8 @@ async fn main() -> Result<()> {
|
|||
let Arguments {
|
||||
server,
|
||||
mxc_url,
|
||||
element_export_path
|
||||
element_export_path,
|
||||
thumbnail,
|
||||
} = Arguments::parse();
|
||||
|
||||
if let Some(element_export_path) = element_export_path {
|
||||
|
@ -351,8 +356,30 @@ async fn main() -> Result<()> {
|
|||
if let Err(error) = match event.content.msgtype {
|
||||
MessageType::Audio(content) => process_media(content.source, Some(content.body), &server).await,
|
||||
MessageType::File(content) => process_media(content.source, Some(content.body), &server).await,
|
||||
MessageType::Image(content) => process_media(content.source, Some(content.body), &server).await,
|
||||
MessageType::Video(content) => process_media(content.source, Some(content.body), &server).await,
|
||||
MessageType::Image(content) => {
|
||||
let source = if thumbnail {
|
||||
content.info
|
||||
.ok_or(anyhow::Error::msg("Requested thumbnail but image doesn't have info"))?
|
||||
.thumbnail_source
|
||||
.ok_or(anyhow::Error::msg("Requested thumbnail image info doesn't contain one"))?
|
||||
} else {
|
||||
content.source
|
||||
};
|
||||
|
||||
process_media(source, Some(content.body), &server).await
|
||||
},
|
||||
MessageType::Video(content) => {
|
||||
let source = if thumbnail {
|
||||
content.info
|
||||
.ok_or(anyhow::Error::msg("Requested thumbnail but video doesn't have info"))?
|
||||
.thumbnail_source
|
||||
.ok_or(anyhow::Error::msg("Requested thumbnail video info doesn't contain one"))?
|
||||
} else {
|
||||
content.source
|
||||
};
|
||||
|
||||
process_media(source, Some(content.body), &server).await
|
||||
},
|
||||
_ => {
|
||||
error!("Event content is not known to contain media, exiting");
|
||||
exit(1);
|
||||
|
|
Loading…
Add table
Reference in a new issue