Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix(material): require Pixabay rendition height to fill output

Rudy Celekli7042bb9d93ec
diff --git a/app/services/material.py b/app/services/material.py
index eeaec3c5..d18a7c36 100644
--- a/app/services/material.py
+++ b/app/services/material.py
@@ -546,7 +546,7 @@ def search_videos_pixabay(
orientation_matches = aspect == VideoAspect.square or (
_matches_video_aspect(w, h, aspect)
)
- if orientation_matches and w >= video_width:
+ if orientation_matches and w >= video_width and h >= video_height:
item = MaterialInfo()
item.provider = "pixabay"
item.url = video_url
diff --git a/test/services/test_pixabay_rendition_height.py b/test/services/test_pixabay_rendition_height.py
new file mode 100644
index 00000000..ac40ca89
--- /dev/null
+++ b/test/services/test_pixabay_rendition_height.py
@@ -0,0 +1,23 @@
+from types import SimpleNamespace
+from unittest.mock import patch
+
+import pytest
+
+from app.services import material
+
+
[email protected]("aspect,width,short_height,height", [
+ (material.VideoAspect.portrait, 1080, 1200, 1920),
+ (material.VideoAspect.landscape, 1920, 800, 1080),
+])
+def test_pixabay_skips_rendition_that_cannot_fill_output_height(aspect, width, short_height, height):
+ response = SimpleNamespace(status_code=200, headers={}, json=lambda: {"hits": [{
+ "duration": 8,
+ "videos": {
+ "small": {"width": width, "height": short_height, "url": "https://example.com/short.mp4"},
+ "large": {"width": width, "height": height, "url": "https://example.com/full.mp4"},
+ },
+ }]})
+ with patch.object(material, "get_api_key", return_value="fixture-key"), patch.object(material.requests, "get", return_value=response):
+ results = material.search_videos_pixabay("nature", 1, aspect)
+ assert [item.url for item in results] == ["https://example.com/full.mp4"]