From a8e97f411a1e769e52d8cbde11f0a4ca1535f7ef Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Sun, 12 Jan 2025 23:56:50 +0100 Subject: [PATCH] feat: prefer maxresdefault.jpg thumbnail if available --- downloader/src/lib.rs | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/downloader/src/lib.rs b/downloader/src/lib.rs index 6107235..9efccc7 100644 --- a/downloader/src/lib.rs +++ b/downloader/src/lib.rs @@ -1020,14 +1020,37 @@ impl DownloadQuery { }; if let Some(thumbnail) = thumbnail { - let resp = self - .dl - .i - .http - .get(thumbnail.url) - .send() - .await? - .error_for_status()?; + // Attempt to get the higher resolution, uncropped maxresdefault.jpg thumbnail if available + let mut resp = None; + if thumbnail.height != thumbnail.width { + if let Ok(x) = self + .dl + .i + .http + .get(format!( + "https://i.ytimg.com/vi/{}/maxresdefault.jpg", + track.id + )) + .send() + .await? + .error_for_status() + { + resp = Some(x); + } + } + + let resp = match resp { + Some(resp) => resp, + None => self + .dl + .i + .http + .get(thumbnail.url) + .send() + .await? + .error_for_status()?, + }; + let img_type = resp .headers() .get(header::CONTENT_TYPE)