From 67104801bfcf1d80d4d09f148d9294dc7fb34331 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sun, 4 Sep 2022 12:54:07 +0200 Subject: [PATCH] Use mpb attached picture also for icons and collapsed folder --- crates/collection/src/audio_folder.rs | 6 ++++++ src/services/icon/mod.rs | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/crates/collection/src/audio_folder.rs b/crates/collection/src/audio_folder.rs index 3ff54957..5c938c1a 100644 --- a/crates/collection/src/audio_folder.rs +++ b/crates/collection/src/audio_folder.rs @@ -301,6 +301,12 @@ impl FolderLister { files = f.files; tags = f.tags; is_file = true; + if cover.is_none() { + cover = f.cover; + } + if description.is_none() { + description = f.description; + } // TODO: Should this be also collapsed? //is_collapsed = true; } diff --git a/src/services/icon/mod.rs b/src/services/icon/mod.rs index d3a7e39f..5971873a 100644 --- a/src/services/icon/mod.rs +++ b/src/services/icon/mod.rs @@ -1,4 +1,5 @@ use anyhow::Result; +use collection::{audio_meta::is_audio, extract_cover}; use headers::{ContentLength, ContentType}; use hyper::{Body, Response}; use image::io::Reader as ImageReader; @@ -16,7 +17,7 @@ use super::subs::add_cache_headers; pub mod cache; -pub fn icon_response(path: impl AsRef) -> Result> { +pub fn icon_response(path: impl AsRef + std::fmt::Debug) -> Result> { let cache_enabled = !get_config().icons.cache_disabled; let data = match if cache_enabled { cached_icon(&path) @@ -48,9 +49,17 @@ pub fn icon_response(path: impl AsRef) -> Result> { builder.body(data.into()).map_err(anyhow::Error::from) } -pub fn scale_cover(path: impl AsRef) -> Result> { +pub fn scale_cover(path: impl AsRef + std::fmt::Debug) -> Result> { use image::imageops::FilterType; - let img = ImageReader::open(&path)?.with_guessed_format()?.decode()?; + let img = if is_audio(&path) { + let data = extract_cover(&path) + .ok_or_else(|| anyhow::Error::msg("Cover is missing, but is expected"))?; + ImageReader::new(Cursor::new(data)) + .with_guessed_format()? + .decode()? + } else { + ImageReader::open(&path)?.with_guessed_format()?.decode()? + }; let sz = get_config().icons.size; let scaled = img.resize( sz,