利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.
Python ai-video-generatorcontent-creationffmpeginstagram-reelsllmpythonshort-videosubtitlestext-to-speechtiktokvideo-automationvideo-workflowworkflow-automationyoutube-shorts
fix(api): accept every local material format the CLI already supports
c020627464191933f8d
diff --git a/app/services/material_upload.py b/app/services/material_upload.pyindex ddafb19f..ce323d36 100644--- a/app/services/material_upload.py+++ b/app/services/material_upload.py@@ -18,8 +18,12 @@ MAX_VIDEO_MATERIAL_UPLOAD_BYTES = 200 * 1024 * 1024MAX_IMAGE_MATERIAL_UPLOAD_BYTES = 20 * 1024 * 1024MATERIAL_VALIDATION_TIMEOUT_SECONDS = 120-SUPPORTED_VIDEO_EXTENSIONS = (".mp4", ".mov", ".avi", ".flv", ".mkv")-SUPPORTED_IMAGE_EXTENSIONS = (".jpg", ".jpeg", ".png")+# Keep these aligned with the local material formats the CLI accepts (cli.py+# derives its list from const.FILE_TYPE_VIDEOS / const.FILE_TYPE_IMAGES) and the+# render pipeline classifies (video.py reads const.FILE_TYPE_IMAGES). Accepting a+# narrower set here rejects uploads the rest of the pipeline already supports.+SUPPORTED_VIDEO_EXTENSIONS = (".mp4", ".mov", ".avi", ".flv", ".mkv", ".webm")+SUPPORTED_IMAGE_EXTENSIONS = (".jpg", ".jpeg", ".png", ".bmp")SUPPORTED_MATERIAL_EXTENSIONS = (*SUPPORTED_VIDEO_EXTENSIONS,*SUPPORTED_IMAGE_EXTENSIONS,@@ -31,6 +35,7 @@ _IMAGE_FORMATS_BY_EXTENSION = {".jpg": frozenset({"JPEG"}),".jpeg": frozenset({"JPEG"}),".png": frozenset({"PNG"}),+ ".bmp": frozenset({"BMP"}),}@@ -113,7 +118,7 @@ def _validate_image(file_path: str, extension: str) -> None:ValueError,) as exc:raise MaterialUploadError(- "uploaded file must contain a valid JPEG or PNG image"+ "uploaded file must contain a valid JPEG, PNG, or BMP image") from excdiff --git a/test/services/test_material_upload.py b/test/services/test_material_upload.pyindex 6c596328..cede5df6 100644--- a/test/services/test_material_upload.py+++ b/test/services/test_material_upload.py@@ -9,6 +9,7 @@ from uuid import UUIDfrom PIL import Image, UnidentifiedImageError+from app.models import constfrom app.services import material_upload@@ -117,7 +118,7 @@ class TestMaterialUploadService(unittest.TestCase):"renamed.png", io.BytesIO(_image_bytes("JPEG")))with self.assertRaisesRegex(- material_upload.MaterialUploadError, "valid JPEG or PNG"+ material_upload.MaterialUploadError, "valid JPEG, PNG, or BMP"):material_upload.save_material_upload("broken.jpg", io.BytesIO(b"not-an-image")@@ -126,6 +127,55 @@ class TestMaterialUploadService(unittest.TestCase):self.assertTrue(stored_name.endswith(".png"))self.assertEqual(len(os.listdir(temp_dir)), 1)+ def test_webm_and_bmp_materials_are_accepted(self):+ with tempfile.TemporaryDirectory() as temp_dir:+ with (+ patch.object(+ material_upload, "uploaded_material_dir", return_value=temp_dir+ ),+ patch.object(material_upload, "_validate_video") as validate_video,+ ):+ video_name = material_upload.save_material_upload(+ "clip.webm", io.BytesIO(b"decodable-video-placeholder")+ )+ image_name = material_upload.save_material_upload(+ "photo.bmp", io.BytesIO(_image_bytes("BMP"))+ )++ # The declared extension still has to match the real image format.+ with self.assertRaisesRegex(+ material_upload.MaterialUploadError, "does not match"+ ):+ material_upload.save_material_upload(+ "renamed.bmp", io.BytesIO(_image_bytes("PNG"))+ )++ self.assertTrue(video_name.endswith(".webm"))+ self.assertTrue(image_name.endswith(".bmp"))+ validate_video.assert_called_once()+ self.assertEqual(len(os.listdir(temp_dir)), 2)++ def test_supported_extensions_cover_cli_accepted_formats(self):+ cli_accepted_formats = {+ *(f".{extension}" for extension in const.FILE_TYPE_VIDEOS),+ *(f".{extension}" for extension in const.FILE_TYPE_IMAGES),+ ".avi",+ ".flv",+ }+ supported = set(material_upload.SUPPORTED_MATERIAL_EXTENSIONS)++ self.assertTrue(+ cli_accepted_formats.issubset(supported),+ "local material upload must accept every format the CLI accepts; "+ f"missing: {sorted(cli_accepted_formats - supported)}",+ )+ # Every accepted image extension needs a declared Pillow format, otherwise+ # image validation raises instead of returning MaterialUploadError.+ self.assertEqual(+ set(material_upload.SUPPORTED_IMAGE_EXTENSIONS),+ set(material_upload._IMAGE_FORMATS_BY_EXTENSION),+ )+def test_renamed_image_is_not_accepted_as_video(self):with tempfile.TemporaryDirectory() as temp_dir:with (