From 35cd6a440f12145d4a0045cc56309a20f12c7155 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 13 Nov 2025 17:21:50 +0000 Subject: [PATCH] use video url as preview if duration <=2min --- src/api.rs | 12 ++++++++++++ src/videos.rs | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/api.rs b/src/api.rs index 5e10a38..564413b 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1287,6 +1287,18 @@ async fn videos_post( .await; }); //### + + for video in videos.items.iter_mut() { + if video.duration <= 120 { + let mut preview_url = video.url.clone(); + if let Some(x) = &video.formats { + // preview is a String here, so use it directly + preview_url = x[0].url.clone(); + } + video.preview = Some(preview_url); + } + } + Ok(web::HttpResponse::Ok().json(&videos)) } diff --git a/src/videos.rs b/src/videos.rs index 79f0f20..5983241 100644 --- a/src/videos.rs +++ b/src/videos.rs @@ -183,7 +183,7 @@ impl VideoItem { #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] pub struct VideoFormat { - url: String, + pub url: String, quality: String, format: String, #[serde(skip_serializing_if = "Option::is_none")]