From 9226015fcc1eb3cdec784a56fd91044c6539c25b Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Sun, 14 Aug 2022 18:07:00 -0400 Subject: [PATCH] Download full images with proper extensions --- src/main.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2001739..13f6ef6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,8 @@ use parse::{CreateArgs, Command, DownloadArgs}; use ::protobuf::Message; use sanitise_file_name::sanitise_with_options; +use crate::protobuf::image::Format; + fn trim_url<'a>(base_url: &str, url: &'a str) -> Option<&'a str> { if url.starts_with(base_url) { let shortened = url @@ -199,7 +201,14 @@ fn download(server: &str, args: DownloadArgs) { .unwrap_or(Cow::Borrowed("Unnamed-Album".as_ref()))); fs::create_dir_all(&dest_dir).expect("Failed to create destination directory"); for (indx, image) in index.images.into_iter().enumerate() { - let path = dest_dir.join(format!("{indx:03}.webp")); + let extension = image.format.enum_value().map(|f| match f { + Format::PNG => "png", + Format::WEBP => "webp", + Format::AVIF => "avif", + Format::JPG => "jpg", + Format::GIF => "gif", + }).unwrap_or(".unk"); + let path = dest_dir.join(format!("{indx:03}.{extension}")); let mut dest_file = OpenOptions::new() .write(true) .truncate(true) @@ -209,7 +218,7 @@ fn download(server: &str, args: DownloadArgs) { let key = image.key.try_into().expect("Invalid key size"); let encrypted_thumbnail = upload::get_data( &download_agent, - &format!("{}/{}.bin", server, image.thumb_url), + &format!("{}/{}.bin", server, image.full_url), 7680_000, &mut download_buffer ).expect("Failed to retrieve image data");