diff --git a/src/main.rs b/src/main.rs index 4e63da3..5411628 100644 --- a/src/main.rs +++ b/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);