Skip to content

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

feat: add Coverr video material source

shawn(shoujche)ee16d99f0ccc
diff --git a/README-en.md b/README-en.md
index a930df69..77fbec61 100644
--- a/README-en.md
+++ b/README-en.md
@@ -50,6 +50,7 @@ materials, video subtitles, and video background music before synthesizing a hig
supports `subtitle outlining`
- [x] Supports **background music**, either random or specified music files, with adjustable `background music volume`
- [x] Video material sources are **high-definition** and **royalty-free**, and you can also use your own **local materials**
+- [x] Supports multiple stock video providers: **Pexels**, **Pixabay**, and **Coverr** (free CC0 HD/4K, mostly 16:9 landscape; register at [coverr.co/developers](https://coverr.co/developers?ctx=header_navigation), Demo tier 50 requests/hour)
- [x] Supports integration with various models such as **OpenAI**, **AIHubMix**, **Moonshot**, **Azure**, **gpt4free**, **one-api**, **Qwen**, **Google Gemini**, **Ollama**, **DeepSeek**, **MiniMax**, **ERNIE**, **Pollinations**, **ModelScope** and more
## Video Demos 📺
diff --git a/README.md b/README.md
index a71963b9..968b2e30 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,7 @@
- [x] 支持 **字幕生成**,可以调整 `字体`、`位置`、`颜色`、`大小`,同时支持`字幕描边`设置
- [x] 支持 **背景音乐**,随机或者指定音乐文件,可设置`背景音乐音量`
- [x] 视频素材来源 **高清**,而且 **无版权**,也可以使用自己的 **本地素材**
+- [x] 支持多种素材源:**Pexels**、**Pixabay**、**Coverr**(免费 CC0 高清/4K 素材库,以 16:9 横屏为主;在 [coverr.co/developers](https://coverr.co/developers?ctx=header_navigation) 注册即可,Demo 套餐 50 次/小时)
- [x] 支持 **OpenAI**、**AIHubMix**、**Moonshot**、**Azure**、**gpt4free**、**one-api**、**通义千问**、**Google Gemini**、**Ollama**、**DeepSeek**、**MiniMax**、 **文心一言**, **Pollinations**、**ModelScope** 等多种模型接入
## 视频演示 📺
diff --git a/app/services/material.py b/app/services/material.py
index 754f68b7..37fc0aea 100644
--- a/app/services/material.py
+++ b/app/services/material.py
@@ -16,6 +16,12 @@ from app.utils import utils
_api_key_counter = 0
_api_key_lock = threading.Lock()
+# Coverr provider 的 url 编码 scheme:
+# item.url = f"{COVERR_URL_PREFIX}{video_id}|{mp4_url}"
+# 下载时拆开拿到 video_id 用于合规性 ping。
+# 复用 url 字段是为了避免改动 MaterialInfo schema(会影响 API 反序列化)。
+COVERR_URL_PREFIX = "coverr://"
+
def _get_tls_verify() -> bool:
# 默认开启 TLS 证书校验,防止素材搜索和下载过程被中间人篡改。
@@ -165,6 +171,106 @@ def search_videos_pixabay(
return []
+def search_videos_coverr(
+ search_term: str,
+ minimum_duration: int,
+ video_aspect: VideoAspect = VideoAspect.portrait,
+) -> List[MaterialInfo]:
+ """
+ Coverr (https://coverr.co) - free CC0 HD/4K stock videos.
+
+ Coverr API notes (based on official docs at api.coverr.co/docs/):
+ - 鉴权: Authorization: Bearer <api_key>
+ - 搜索端点: GET /videos?query=...,响应结构 {"hits": [...], ...}
+ - 加 ?urls=true 在搜索响应里直接返回 mp4 直链
+ - URL 是 signed JWT(绑定 API key,无过期时间)
+ - Coverr 库以 16:9 横屏为主,9:16 portrait 占比极低(约 1%)
+ 因此本函数不做 aspect_ratio 过滤,由下游 video.py 的
+ resize + letterbox 逻辑统一处理
+ - duration 字段同时存在 number 和 string 两种形态,本函数都接受
+
+ 返回的 MaterialInfo.url 为 f"{COVERR_URL_PREFIX}{video_id}|{mp4_url}" 格式,
+ 供 download_videos 拆出 video_id 完成合规性 ping。
+ """
+ api_key = get_api_key("coverr_api_keys")
+ headers = {"Authorization": f"Bearer {api_key}"}
+ params = {
+ "query": search_term,
+ "page_size": 20,
+ "urls": "true",
+ "sort": "popular",
+ }
+ query_url = f"https://api.coverr.co/videos?{urlencode(params)}"
+ logger.info(f"searching videos: {query_url}, with proxies: {config.proxy}")
+
+ try:
+ r = requests.get(
+ query_url,
+ headers=headers,
+ proxies=config.proxy,
+ verify=_get_tls_verify(),
+ timeout=(30, 60),
+ )
+ response = r.json()
+ video_items: List[MaterialInfo] = []
+
+ if not isinstance(response, dict) or "hits" not in response:
+ logger.error(f"search videos failed: {response}")
+ return video_items
+
+ for v in response["hits"]:
+ # duration 在不同响应里可能是 number(11.625) 或 string("10.500000")
+ try:
+ duration = int(float(v.get("duration") or 0))
+ except (TypeError, ValueError):
+ continue
+ if duration < minimum_duration:
+ continue
+
+ video_id = v.get("id")
+ mp4_url = (v.get("urls") or {}).get("mp4")
+ if not video_id or not mp4_url:
+ continue
+
+ item = MaterialInfo()
+ item.provider = "coverr"
+ item.url = f"{COVERR_URL_PREFIX}{video_id}|{mp4_url}"
+ item.duration = duration
+ video_items.append(item)
+ return video_items
+ except Exception as e:
+ logger.error(f"search videos failed: {str(e)}")
+
+ return []
+
+
+def _ping_coverr_download(video_id: str, api_key: str) -> None:
+ """
+ Coverr 合规性要求:用户实际下载视频后必须 ping 一次
+ PATCH /videos/<id>/stats/downloads,否则 Coverr 会审查并可能吊销 API key。
+ 详见 https://api.coverr.co/docs/videos/#download-a-video
+
+ 此 ping 失败不应阻断下载流程 —— 视频已经在用户硬盘上,
+ 只是 Coverr 端的统计落不到。记 warning 即可。
+ """
+ url = f"https://api.coverr.co/videos/{video_id}/stats/downloads"
+ headers = {"Authorization": f"Bearer {api_key}"}
+ try:
+ r = requests.patch(
+ url,
+ headers=headers,
+ proxies=config.proxy,
+ verify=_get_tls_verify(),
+ timeout=(10, 10),
+ )
+ if r.status_code != 204:
+ logger.warning(
+ f"coverr download ping returned status {r.status_code} for id={video_id}"
+ )
+ except Exception as e:
+ logger.warning(f"coverr download ping failed for id={video_id}: {str(e)}")
+
+
def save_video(video_url: str, save_dir: str = "") -> str:
if not save_dir:
save_dir = utils.storage_dir("cache_videos")
@@ -240,6 +346,8 @@ def download_videos(
search_videos = search_videos_pexels
if source == "pixabay":
search_videos = search_videos_pixabay
+ elif source == "coverr":
+ search_videos = search_videos_coverr
for search_term in search_terms:
video_items = search_videos(
@@ -273,12 +381,31 @@ def download_videos(
total_duration = 0.0
for item in valid_video_items:
try:
- logger.info(f"downloading video: {item.url}")
+ coverr_video_id = None
+ download_url = item.url
+ if item.provider == "coverr":
+ if not item.url.startswith(COVERR_URL_PREFIX):
+ logger.error(
+ f"coverr item missing scheme prefix, skipping: {item.url}"
+ )
+ continue
+ payload = item.url[len(COVERR_URL_PREFIX):]
+ coverr_video_id, sep, download_url = payload.partition("|")
+ if not sep or not coverr_video_id or not download_url:
+ logger.error(f"malformed coverr url, skipping: {item.url}")
+ continue
+
+ logger.info(f"downloading video: {download_url}")
saved_video_path = save_video(
- video_url=item.url, save_dir=material_directory
+ video_url=download_url, save_dir=material_directory
)
if saved_video_path:
logger.info(f"video saved: {saved_video_path}")
+ if coverr_video_id:
+ _ping_coverr_download(
+ video_id=coverr_video_id,
+ api_key=get_api_key("coverr_api_keys"),
+ )
video_paths.append(saved_video_path)
seconds = min(max_clip_duration, item.duration)
total_duration += seconds
diff --git a/config.example.toml b/config.example.toml
index 63b96566..ae25b41c 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -29,6 +29,18 @@ pexels_api_keys = []
# 特别注意格式,Key 用英文双引号括起来,多个Key用逗号隔开
pixabay_api_keys = []
+# Coverr API Key
+# Register at https://coverr.co/developers?ctx=header_navigation to get your API key instantly.
+# Free tier (Demo) is limited to 50 requests/hour — sufficient for a few
+# video tasks per hour. Upgrade to Pro/Ultimate subscription for 2000/hour.
+# Coverr provides free CC0 HD/4K stock videos, mostly 16:9 landscape; if
+# you generate 9:16 short-form videos, prefer Pexels/Pixabay as primary
+# and use Coverr to widen the catalog for landscape/cinematic content.
+# You can use multiple keys to avoid rate limits.
+# For example: coverr_api_keys = ["123adsf4567adf89","abd1321cd13efgfdfhi"]
+# 特别注意格式,Key 用英文双引号括起来,多个Key用逗号隔开
+coverr_api_keys = []
+
# 支持的提供商 (Supported providers):
# openai
# aihubmix (OpenAI-compatible AI model gateway)
diff --git a/test/services/test_material.py b/test/services/test_material.py
index 608a820f..313ad9a8 100644
--- a/test/services/test_material.py
+++ b/test/services/test_material.py
@@ -6,6 +6,8 @@ from pathlib import Path
from types import SimpleNamespace
from unittest.mock import patch
+import requests
+
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from app.config import config
@@ -128,5 +130,375 @@ class TestMaterialTlsVerification(unittest.TestCase):
self.assertEqual(result, [])
+class TestCoverrProvider(unittest.TestCase):
+ """
+ Coverr 视频素材源(spec: 2026-06-09-coverr-video-provider-design.md)。
+ 全部用 unittest.mock 替换 requests,确保 CI 不依赖真实网络和真实 API key。
+ """
+
+ def setUp(self):
+ self.original_app_config = dict(config.app)
+ self.original_proxy_config = dict(config.proxy)
+
+ def tearDown(self):
+ config.app.clear()
+ config.app.update(self.original_app_config)
+ config.proxy.clear()
+ config.proxy.update(self.original_proxy_config)
+
+ # ---------------- Tests for search_videos_coverr ----------------
+
+ def test_search_coverr_parses_hits_and_encodes_url(self):
+ """
+ search_videos_coverr 应把每个 hit 转成 MaterialInfo,并把
+ (id, mp4_url) 编码进 url 字段供下载时拆解。
+ 同时验证 Authorization header 使用 Bearer scheme。
+ """
+ config.app["coverr_api_keys"] = ["coverr-key"]
+ config.app.pop("tls_verify", None)
+ config.proxy.clear()
+
+ fake_response = SimpleNamespace(
+ json=lambda: {
+ "page": 0,
+ "pages": 50,
+ "page_size": 20,
+ "total": 1,
+ "hits": [
+ {
+ "id": "S1YbPl1NfI",
+ "duration": 11.625,
+ "aspect_ratio": "16:9",
+ "urls": {
+ "mp4": "https://storage.coverr.co/videos/abc?token=xyz",
+ "mp4_preview": "https://storage.coverr.co/videos/abc/preview?token=xyz",
+ "mp4_download": "https://storage.coverr.co/videos/abc/download?token=xyz",
+ },
+ }
+ ],
+ }
+ )
+
+ with patch(
+ "app.services.material.requests.get", return_value=fake_response
+ ) as get:
+ results = material.search_videos_coverr("nature", minimum_duration=5)
+
+ self.assertEqual(len(results), 1)
+ item = results[0]
+ self.assertEqual(item.provider, "coverr")
+ self.assertEqual(item.duration, 11)
+ self.assertTrue(item.url.startswith("coverr://"))
+ self.assertIn("S1YbPl1NfI", item.url)
+ self.assertIn(
+ "https://storage.coverr.co/videos/abc?token=xyz", item.url
+ )
+ # Bearer auth + TLS verify on by default
+ self.assertEqual(
+ get.call_args.kwargs["headers"]["Authorization"], "Bearer coverr-key"
+ )
+ self.assertTrue(get.call_args.kwargs["verify"])
+
+ def test_search_coverr_uses_tls_verification_by_default(self):
+ """与 pexels/pixabay 一致:未显式配置时 TLS 校验默认开启。"""
+ config.app["coverr_api_keys"] = ["coverr-key"]
+ config.app.pop("tls_verify", None)
+ config.proxy.clear()
+
+ fake_response = SimpleNamespace(json=lambda: {"hits": []})
+
+ with patch(
+ "app.services.material.requests.get", return_value=fake_response
+ ) as get:
+ material.search_videos_coverr("nature", minimum_duration=1)
+
+ self.assertTrue(get.call_args.kwargs["verify"])
+
+ def test_search_coverr_allows_explicit_tls_disable_for_proxy(self):
+ """企业自签证书代理场景必须能显式关闭 TLS 校验。"""
+ config.app["coverr_api_keys"] = ["coverr-key"]
+ config.app["tls_verify"] = False
+ config.proxy.clear()
+
+ fake_response = SimpleNamespace(json=lambda: {"hits": []})
+
+ with patch(
+ "app.services.material.requests.get", return_value=fake_response
+ ) as get:
+ material.search_videos_coverr("nature", minimum_duration=1)
+
+ self.assertFalse(get.call_args.kwargs["verify"])
+
+ def test_search_coverr_filters_by_min_duration_and_accepts_string(self):
+ """
+ Coverr duration 字段在不同响应里可能是 number 或 string,
+ 两种格式都要接受;低于 minimum_duration 的应被过滤。
+ """
+ config.app["coverr_api_keys"] = ["coverr-key"]
+ config.app.pop("tls_verify", None)
+ config.proxy.clear()
+
+ fake_response = SimpleNamespace(
+ json=lambda: {
+ "hits": [
+ {
+ "id": "shortvid",
+ "duration": 3, # below minimum
+ "urls": {"mp4": "https://example.com/a.mp4"},
+ },
+ {
+ "id": "stringdur",
+ "duration": "10.500000", # string accepted
+ "urls": {"mp4": "https://example.com/b.mp4"},
+ },
+ ]
+ }
+ )
+
+ with patch(
+ "app.services.material.requests.get", return_value=fake_response
+ ):
+ results = material.search_videos_coverr("x", minimum_duration=5)
+
+ self.assertEqual(len(results), 1)
+ self.assertEqual(results[0].duration, 10)
+ self.assertIn("stringdur", results[0].url)
+
+ def test_search_coverr_skips_invalid_items(self):
+ """缺 id 或缺 urls.mp4 的条目应被跳过,不应抛异常。"""
+ config.app["coverr_api_keys"] = ["coverr-key"]
+ config.app.pop("tls_verify", None)
+ config.proxy.clear()
+
+ fake_response = SimpleNamespace(
+ json=lambda: {
+ "hits": [
+ { # missing urls.mp4
+ "id": "no-mp4",
+ "duration": 10,
+ "urls": {"mp4_preview": "https://example.com/preview.mp4"},
+ },
+ { # missing id
+ "duration": 10,
+ "urls": {"mp4": "https://example.com/x.mp4"},
+ },
+ { # valid baseline
+ "id": "good",
+ "duration": 10,
+ "urls": {"mp4": "https://example.com/good.mp4"},
+ },
+ ]
+ }
+ )
+
+ with patch(
+ "app.services.material.requests.get", return_value=fake_response
+ ):
+ results = material.search_videos_coverr("x", minimum_duration=1)
+
+ self.assertEqual(len(results), 1)
+ self.assertIn("good", results[0].url)
+
+ def test_search_coverr_returns_empty_on_failure(self):
+ """
+ 响应结构异常 / 网络异常时,函数必须返回 [] 而不是抛异常,
+ 与 pexels/pixabay 行为保持一致。
+ """
+ config.app["coverr_api_keys"] = ["coverr-key"]
+ config.app.pop("tls_verify", None)
+ config.proxy.clear()
+
+ # Subtest A: malformed response (no "hits" key)
+ with self.subTest("malformed response"):
+ fake_response = SimpleNamespace(
+ json=lambda: {"error": "rate limited"}
+ )
+ with patch(
+ "app.services.material.requests.get", return_value=fake_response
+ ):
+ results = material.search_videos_coverr("x", minimum_duration=1)
+ self.assertEqual(results, [])
+
+ # Subtest B: network exception bubbles up from requests.get
+ with self.subTest("network exception"):
+ with patch(
+ "app.services.material.requests.get",
+ side_effect=requests.ConnectionError("boom"),
+ ):
+ results = material.search_videos_coverr("x", minimum_duration=1)
+ self.assertEqual(results, [])
+
+ # ---------------- Tests for _ping_coverr_download ----------------
+
+ def test_ping_coverr_download_sends_patch_with_bearer_auth(self):
+ """
+ 合规性 ping 必须使用 PATCH + Bearer auth,落到正确的 stats endpoint。
+ """
+ config.proxy.clear()
+ config.app.pop("tls_verify", None)
+
+ fake_response = SimpleNamespace(status_code=204)
+ with patch(
+ "app.services.material.requests.patch", return_value=fake_response
+ ) as patch_call:
+ material._ping_coverr_download("vid-abc", "coverr-key")
+
+ call = patch_call.call_args
+ # URL 必须是 stats/downloads endpoint
+ self.assertIn("/videos/vid-abc/stats/downloads", call.args[0])
+ # Bearer auth
+ self.assertEqual(
+ call.kwargs["headers"]["Authorization"], "Bearer coverr-key"
+ )
+
+ def test_ping_coverr_download_swallows_failures(self):
+ """
+ ping 失败不能阻断下载流程 —— 视频已经在硬盘上,
+ 失败只能记 warning,绝不能 raise。
+ """
+ config.proxy.clear()
+ config.app.pop("tls_verify", None)
+
+ # Subtest A: HTTP non-204 status -> warning, no raise
+ with self.subTest("non-204 status"):
+ fake_response = SimpleNamespace(status_code=500)
+ with patch(
+ "app.services.material.requests.patch",
+ return_value=fake_response,
+ ):
+ # 不应抛任何异常
+ material._ping_coverr_download("vid-x", "coverr-key")
+
+ # Subtest B: network exception -> swallowed
+ with self.subTest("network exception"):
+ with patch(
+ "app.services.material.requests.patch",
+ side_effect=requests.ConnectionError("boom"),
+ ):
+ material._ping_coverr_download("vid-y", "coverr-key")
+
+ # ---------------- Tests for download_videos coverr branch ----------------
+
+ def test_download_videos_decodes_coverr_url_and_pings(self):
+ """
+ download_videos 在 source="coverr" 时:
+ 1. dispatch 到 search_videos_coverr
+ 2. 把 item.url 的 coverr://<id>|<mp4_url> 拆开,只把 mp4_url 传给 save_video
+ 3. 下载成功后才 ping,且 ping 携带正确的 video_id
+ """
+ config.app["coverr_api_keys"] = ["coverr-key"]
+ config.app.pop("tls_verify", None)
+ config.app.pop("material_directory", None)
+ config.proxy.clear()
+
+ fake_item = material.MaterialInfo()
+ fake_item.provider = "coverr"
+ fake_item.url = (
+ f"{material.COVERR_URL_PREFIX}vid-XYZ|"
+ "https://storage.coverr.co/videos/abc?token=xyz"
+ )
+ fake_item.duration = 10
+
+ with patch(
+ "app.services.material.search_videos_coverr",
+ return_value=[fake_item],
+ ) as search, patch(
+ "app.services.material.save_video",
+ return_value="/tmp/coverr-saved.mp4",
+ ) as save, patch(
+ "app.services.material._ping_coverr_download"
+ ) as ping:
+ result = material.download_videos(
+ task_id="t-coverr",
+ search_terms=["nature"],
+ source="coverr",
+ audio_duration=5,
+ max_clip_duration=5,
+ )
+
+ # 1. dispatch
+ self.assertEqual(search.call_count, 1)
+
+ # 2. save_video 收到的是 mp4 直链,不带 coverr:// 前缀也不带 |id 段
+ save_url = save.call_args.kwargs.get("video_url") or save.call_args.args[0]
+ self.assertEqual(
+ save_url, "https://storage.coverr.co/videos/abc?token=xyz"
+ )
+ self.assertNotIn("coverr://", save_url)
+ self.assertNotIn("|", save_url)
+
+ # 3. 下载成功后 ping,且 video_id 正确
+ self.assertEqual(ping.call_count, 1)
+ ping_kwargs = ping.call_args.kwargs
+ self.assertEqual(ping_kwargs.get("video_id"), "vid-XYZ")
+ self.assertEqual(ping_kwargs.get("api_key"), "coverr-key")
+
+ # 4. 整体返回值正确
+ self.assertEqual(result, ["/tmp/coverr-saved.mp4"])
+
+ def test_download_videos_skips_ping_on_failure_or_malformed_url(self):
+ """
+ 合规性保护:
+ - save_video 返回 "" (下载失败) → 不能 ping
+ - item.url 缺 | 分隔符 → 跳过该 item,不能 ping 也不能下载
+ """
+ config.app["coverr_api_keys"] = ["coverr-key"]
+ config.app.pop("tls_verify", None)
+ config.app.pop("material_directory", None)
+ config.proxy.clear()
+
+ # Subtest A: save_video failed
+ with self.subTest("save_video fails -> no ping"):
+ fake_item = material.MaterialInfo()
+ fake_item.provider = "coverr"
+ fake_item.url = (
+ f"{material.COVERR_URL_PREFIX}vid-A|https://example.com/a.mp4"
+ )
+ fake_item.duration = 10
+
+ with patch(
+ "app.services.material.search_videos_coverr",
+ return_value=[fake_item],
+ ), patch(
+ "app.services.material.save_video", return_value=""
+ ), patch(
+ "app.services.material._ping_coverr_download"
+ ) as ping:
+ material.download_videos(
+ task_id="t-fail",
+ search_terms=["x"],
+ source="coverr",
+ audio_duration=5,
+ max_clip_duration=5,
+ )
+ self.assertEqual(ping.call_count, 0)
+
+ # Subtest B: malformed url (missing |)
+ with self.subTest("malformed url -> skip item entirely"):
+ fake_item = material.MaterialInfo()
+ fake_item.provider = "coverr"
+ fake_item.url = f"{material.COVERR_URL_PREFIX}only-an-id" # no |
+ fake_item.duration = 10
+
+ with patch(
+ "app.services.material.search_videos_coverr",
+ return_value=[fake_item],
+ ), patch(
+ "app.services.material.save_video", return_value="/tmp/x.mp4"
+ ) as save, patch(
+ "app.services.material._ping_coverr_download"
+ ) as ping:
+ result = material.download_videos(
+ task_id="t-bad",
+ search_terms=["x"],
+ source="coverr",
+ audio_duration=5,
+ max_clip_duration=5,
+ )
+ self.assertEqual(save.call_count, 0)
+ self.assertEqual(ping.call_count, 0)
+ self.assertEqual(result, [])
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/webui/Main.py b/webui/Main.py
index 76af5fbd..215a3a03 100644
--- a/webui/Main.py
+++ b/webui/Main.py
@@ -655,6 +655,12 @@ if not config.app.get("hide_config", False):
)
save_keys_to_config("pixabay_api_keys", pixabay_api_key)
+ coverr_api_key = get_keys_from_config("coverr_api_keys")
+ coverr_api_key = st.text_input(
+ tr("Coverr API Key"), value=coverr_api_key, type="password"
+ )
+ save_keys_to_config("coverr_api_keys", coverr_api_key)
+
llm_provider = config.app.get("llm_provider", "").lower()
panel = st.columns(3)
left_panel = panel[0]
@@ -772,6 +778,7 @@ with middle_panel:
video_sources = [
(tr("Pexels"), "pexels"),
(tr("Pixabay"), "pixabay"),
+ (tr("Coverr"), "coverr"),
(tr("Local file"), "local"),
(tr("TikTok"), "douyin"),
(tr("Bilibili"), "bilibili"),
@@ -838,6 +845,13 @@ with middle_panel:
(tr("Portrait"), VideoAspect.portrait.value),
(tr("Landscape"), VideoAspect.landscape.value),
]
+ # Coverr 库 99% 是 16:9 横屏,默认竖屏会让画面被大量黑边包围。
+ # 用 source-specific widget key 让每个 source 各自记忆 aspect 选择:
+ # - 首次切到 coverr → 默认 Landscape(index=1)
+ # - 其他 source 沿用 Portrait(index=0)
+ # - 用户在某 source 下手动改过 aspect,session_state 会记住,
+ # 下次回到同一 source 时尊重用户选择,不会再被强制覆盖。
+ default_aspect_index = 1 if params.video_source == "coverr" else 0
selected_index = st.selectbox(
tr("Video Ratio"),
options=range(
@@ -846,6 +860,8 @@ with middle_panel:
format_func=lambda x: video_aspect_ratios[x][
0
], # The label is displayed to the user
+ index=default_aspect_index,
+ key=f"video_aspect_for_{params.video_source}",
)
params.video_aspect = VideoAspect(video_aspect_ratios[selected_index][1])
@@ -1279,9 +1295,13 @@ with right_panel:
params.rounded_subtitle_background
)
with st.expander(tr("Click to show API Key management"), expanded=False):
- st.subheader(tr("Manage Pexels and Pixabay API Keys"))
+ st.subheader(tr("Manage Pexels, Pixabay and Coverr API Keys"))
- col1, col2 = st.tabs([tr("Pexels API Keys"), tr("Pixabay API Keys")])
+ col1, col2, col3 = st.tabs([
+ tr("Pexels API Keys"),
+ tr("Pixabay API Keys"),
+ tr("Coverr API Keys"),
+ ])
with col1:
st.subheader(tr("Pexels API Keys"))
@@ -1342,6 +1362,42 @@ with right_panel:
config.save_config()
st.success(tr("Pixabay API Key deleted successfully"))
+ with col3:
+ st.subheader(tr("Coverr API Keys"))
+
+ # 与 pexels/pixabay 不同,coverr_api_keys 是 PR 新增配置项,
+ # 老用户的 config.toml 不一定包含,这里先兜底初始化为空列表,
+ # 防止下面 .append / 索引访问触发 KeyError。
+ if "coverr_api_keys" not in config.app or config.app["coverr_api_keys"] is None:
+ config.app["coverr_api_keys"] = []
+
+ if config.app["coverr_api_keys"]:
+ st.write(tr("Current Keys:"))
+ for key in config.app["coverr_api_keys"]:
+ st.code(key)
+ else:
+ st.info(tr("No Coverr API Keys currently"))
+
+ new_key = st.text_input(tr("Add Coverr API Key"), key="coverr_new_key")
+ if st.button(tr("Add Coverr API Key")):
+ if new_key and new_key not in config.app["coverr_api_keys"]:
+ config.app["coverr_api_keys"].append(new_key)
+ config.save_config()
+ st.success(tr("Coverr API Key added successfully"))
+ elif new_key in config.app["coverr_api_keys"]:
+ st.warning(tr("This API Key already exists"))
+ else:
+ st.error(tr("Please enter a valid API Key"))
+
+ if config.app["coverr_api_keys"]:
+ delete_key = st.selectbox(
+ tr("Select Coverr API Key to delete"), config.app["coverr_api_keys"], key="coverr_delete_key"
+ )
+ if st.button(tr("Delete Selected Coverr API Key")):
+ config.app["coverr_api_keys"].remove(delete_key)
+ config.save_config()
+ st.success(tr("Coverr API Key deleted successfully"))
+
start_button = st.button(tr("Generate Video"), use_container_width=True, type="primary")
if start_button:
config.save_config()
@@ -1351,7 +1407,7 @@ if start_button:
scroll_to_bottom()
st.stop()
- if params.video_source not in ["pexels", "pixabay", "local"]:
+ if params.video_source not in ["pexels", "pixabay", "coverr", "local"]:
st.error(tr("Please Select a Valid Video Source"))
scroll_to_bottom()
st.stop()
@@ -1366,6 +1422,11 @@ if start_button:
scroll_to_bottom()
st.stop()
+ if params.video_source == "coverr" and not config.app.get("coverr_api_keys", ""):
+ st.error(tr("Please Enter the Coverr API Key"))
+ scroll_to_bottom()
+ st.stop()
+
if uploaded_audio_file:
task_dir = utils.task_dir(task_id)
# 上传文件名来自浏览器,不能直接拼到磁盘路径里;这里只保留扩展名,
diff --git a/webui/i18n/de.json b/webui/i18n/de.json
index 83a19e39..6565b683 100644
--- a/webui/i18n/de.json
+++ b/webui/i18n/de.json
@@ -149,6 +149,17 @@
"Pixabay API Key added successfully": "Pixabay-API-Schlüssel erfolgreich hinzugefügt",
"Select Pixabay API Key to delete": "Wählen Sie den zu löschenden Pixabay-API-Schlüssel aus",
"Delete Selected Pixabay API Key": "Ausgewählten Pixabay-API-Schlüssel löschen",
- "Pixabay API Key deleted successfully": "Pixabay-API-Schlüssel erfolgreich gelöscht"
+ "Pixabay API Key deleted successfully": "Pixabay-API-Schlüssel erfolgreich gelöscht",
+ "Manage Pexels, Pixabay and Coverr API Keys": "Pexels-, Pixabay- und Coverr-API-Schlüssel verwalten",
+ "Coverr": "Coverr",
+ "Coverr API Key": "Coverr API-Schlüssel ([API-Schlüssel holen](https://coverr.co/developers?ctx=header_navigation))",
+ "Coverr API Keys": "Coverr API-Schlüssel",
+ "Please Enter the Coverr API Key": "Bitte geben Sie den **Coverr API-Schlüssel** ein",
+ "No Coverr API Keys currently": "Derzeit keine Coverr API-Schlüssel",
+ "Add Coverr API Key": "Coverr API-Schlüssel hinzufügen",
+ "Coverr API Key added successfully": "Coverr API-Schlüssel erfolgreich hinzugefügt",
+ "Select Coverr API Key to delete": "Coverr API-Schlüssel zum Löschen auswählen",
+ "Delete Selected Coverr API Key": "Ausgewählten Coverr API-Schlüssel löschen",
+ "Coverr API Key deleted successfully": "Coverr API-Schlüssel erfolgreich gelöscht"
}
}
diff --git a/webui/i18n/en.json b/webui/i18n/en.json
index b8d4afa0..48d613ad 100644
--- a/webui/i18n/en.json
+++ b/webui/i18n/en.json
@@ -147,6 +147,17 @@
"Select Pixabay API Key to delete": "Select Pixabay API Key to delete",
"Delete Selected Pixabay API Key": "Delete Selected Pixabay API Key",
"Pixabay API Key deleted successfully": "Pixabay API Key deleted successfully",
+ "Manage Pexels, Pixabay and Coverr API Keys": "Manage Pexels, Pixabay and Coverr API Keys",
+ "Coverr": "Coverr",
+ "Coverr API Key": "Coverr API Key ([Get API Key](https://coverr.co/developers?ctx=header_navigation))",
+ "Coverr API Keys": "Coverr API Keys",
+ "Please Enter the Coverr API Key": "Please Enter the **Coverr API Key**",
+ "No Coverr API Keys currently": "No Coverr API Keys currently",
+ "Add Coverr API Key": "Add Coverr API Key",
+ "Coverr API Key added successfully": "Coverr API Key added successfully",
+ "Select Coverr API Key to delete": "Select Coverr API Key to delete",
+ "Delete Selected Coverr API Key": "Delete Selected Coverr API Key",
+ "Coverr API Key deleted successfully": "Coverr API Key deleted successfully",
"Advanced Video Settings": "Advanced Video Settings",
"Video Encoder": "Video Encoder",
"Video Encoder Help": "Advanced option. libx264 is the safest default. When a hardware encoder is selected, the app falls back to libx264 if the current FFmpeg, GPU, or driver cannot use it."
diff --git a/webui/i18n/pt.json b/webui/i18n/pt.json
index ea53df90..faf67578 100644
--- a/webui/i18n/pt.json
+++ b/webui/i18n/pt.json
@@ -131,6 +131,17 @@
"Pixabay API Key added successfully": "Chave de API do Pixabay adicionada com sucesso",
"Select Pixabay API Key to delete": "Selecione a chave de API do Pixabay para excluir",
"Delete Selected Pixabay API Key": "Excluir chave de API do Pixabay selecionada",
- "Pixabay API Key deleted successfully": "Chave de API do Pixabay excluída com sucesso"
+ "Pixabay API Key deleted successfully": "Chave de API do Pixabay excluída com sucesso",
+ "Manage Pexels, Pixabay and Coverr API Keys": "Gerenciar Chaves de API do Pexels, Pixabay e Coverr",
+ "Coverr": "Coverr",
+ "Coverr API Key": "Chave de API do Coverr ([Obter Chave de API](https://coverr.co/developers?ctx=header_navigation))",
+ "Coverr API Keys": "Chaves de API do Coverr",
+ "Please Enter the Coverr API Key": "Por favor, insira a **Chave de API do Coverr**",
+ "No Coverr API Keys currently": "Sem Chaves de API do Coverr no momento",
+ "Add Coverr API Key": "Adicionar Chave de API do Coverr",
+ "Coverr API Key added successfully": "Chave de API do Coverr adicionada com sucesso",
+ "Select Coverr API Key to delete": "Selecione a chave de API do Coverr para excluir",
+ "Delete Selected Coverr API Key": "Excluir chave de API do Coverr selecionada",
+ "Coverr API Key deleted successfully": "Chave de API do Coverr excluída com sucesso"
}
}
diff --git a/webui/i18n/ru.json b/webui/i18n/ru.json
index b9348cbe..83228684 100644
--- a/webui/i18n/ru.json
+++ b/webui/i18n/ru.json
@@ -143,6 +143,17 @@
"Select Pixabay API Key to delete": "Выберите API-ключ Pixabay для удаления",
"Delete Selected Pixabay API Key": "Удалить выбранный API-ключ Pixabay",
"Pixabay API Key deleted successfully": "API-ключ Pixabay удален",
+ "Manage Pexels, Pixabay and Coverr API Keys": "Управление API-ключами Pexels, Pixabay и Coverr",
+ "Coverr": "Coverr",
+ "Coverr API Key": "API-ключ Coverr ([Получить ключ](https://coverr.co/developers?ctx=header_navigation))",
+ "Coverr API Keys": "API-ключи Coverr",
+ "Please Enter the Coverr API Key": "Введите **API-ключ Coverr**",
+ "No Coverr API Keys currently": "Сейчас нет API-ключей Coverr",
+ "Add Coverr API Key": "Добавить API-ключ Coverr",
+ "Coverr API Key added successfully": "API-ключ Coverr успешно добавлен",
+ "Select Coverr API Key to delete": "Выберите API-ключ Coverr для удаления",
+ "Delete Selected Coverr API Key": "Удалить выбранный API-ключ Coverr",
+ "Coverr API Key deleted successfully": "API-ключ Coverr удален",
"Advanced Video Settings": "Дополнительные настройки видео",
"Video Encoder": "Видеокодер",
"Video Encoder Help": "Дополнительная настройка. libx264 считается самым надежным вариантом по умолчанию. Если выбран аппаратный кодер, приложение вернется к libx264, если установленная версия FFmpeg, GPU или драйвер не поддерживают выбранный кодер.",
diff --git a/webui/i18n/tr.json b/webui/i18n/tr.json
index e089eed1..f656ea64 100644
--- a/webui/i18n/tr.json
+++ b/webui/i18n/tr.json
@@ -147,6 +147,17 @@
"Select Pixabay API Key to delete": "Silinecek Pixabay API Anahtarını seçin",
"Delete Selected Pixabay API Key": "Seçili Pixabay API Anahtarını Sil",
"Pixabay API Key deleted successfully": "Pixabay API Anahtarı başarıyla silindi",
+ "Manage Pexels, Pixabay and Coverr API Keys": "Pexels, Pixabay ve Coverr API Anahtarlarını Yönet",
+ "Coverr": "Coverr",
+ "Coverr API Key": "Coverr API Anahtarı ([API Anahtarı Al](https://coverr.co/developers?ctx=header_navigation))",
+ "Coverr API Keys": "Coverr API Anahtarları",
+ "Please Enter the Coverr API Key": "Lütfen **Coverr API Anahtarını** girin",
+ "No Coverr API Keys currently": "Şu anda Coverr API Anahtarı yok",
+ "Add Coverr API Key": "Coverr API Anahtarı Ekle",
+ "Coverr API Key added successfully": "Coverr API Anahtarı başarıyla eklendi",
+ "Select Coverr API Key to delete": "Silinecek Coverr API Anahtarını seçin",
+ "Delete Selected Coverr API Key": "Seçili Coverr API Anahtarını Sil",
+ "Coverr API Key deleted successfully": "Coverr API Anahtarı başarıyla silindi",
"Advanced Video Settings": "Gelişmiş Video Ayarları",
"Video Encoder": "Video Kodlayıcı",
"Video Encoder Help": "Gelişmiş seçenek. libx264 en güvenli varsayılandır. Donanım kodlayıcı seçildiğinde mevcut FFmpeg, GPU veya sürücü bunu kullanamıyorsa uygulama libx264'ye geri döner."
diff --git a/webui/i18n/vi.json b/webui/i18n/vi.json
index acb426e1..32610e3d 100644
--- a/webui/i18n/vi.json
+++ b/webui/i18n/vi.json
@@ -147,6 +147,17 @@
"Select Pixabay API Key to delete": "Chọn API Key Pixabay để xóa",
"Delete Selected Pixabay API Key": "Xóa API Key Pixabay đã chọn",
"Pixabay API Key deleted successfully": "Xóa API Key Pixabay thành công",
+ "Manage Pexels, Pixabay and Coverr API Keys": "Quản Lý API Key Pexels, Pixabay và Coverr",
+ "Coverr": "Coverr",
+ "Coverr API Key": "API Key Coverr ([Lấy API Key](https://coverr.co/developers?ctx=header_navigation))",
+ "Coverr API Keys": "Các API Key Coverr",
+ "Please Enter the Coverr API Key": "Vui lòng nhập **API Key Coverr**",
+ "No Coverr API Keys currently": "Hiện không có API Key Coverr",
+ "Add Coverr API Key": "Thêm API Key Coverr",
+ "Coverr API Key added successfully": "Đã thêm API Key Coverr thành công",
+ "Select Coverr API Key to delete": "Chọn API Key Coverr để xóa",
+ "Delete Selected Coverr API Key": "Xóa API Key Coverr đã chọn",
+ "Coverr API Key deleted successfully": "Xóa API Key Coverr thành công",
"Advanced Video Settings": "Cài Đặt Video Nâng Cao",
"Video Encoder": "Bộ Mã Hóa Video",
"Video Encoder Help": "Tùy chọn nâng cao. libx264 là lựa chọn mặc định an toàn nhất. Khi chọn bộ mã hóa phần cứng, ứng dụng sẽ tự chuyển về libx264 nếu FFmpeg, GPU hoặc driver hiện tại không hỗ trợ."
diff --git a/webui/i18n/zh.json b/webui/i18n/zh.json
index 8c715bed..481e38ba 100644
--- a/webui/i18n/zh.json
+++ b/webui/i18n/zh.json
@@ -147,6 +147,17 @@
"Select Pixabay API Key to delete": "选择要删除的 Pixabay API Key",
"Delete Selected Pixabay API Key": "删除选定的 Pixabay API Key",
"Pixabay API Key deleted successfully": "Pixabay API Key 删除成功",
+ "Manage Pexels, Pixabay and Coverr API Keys": "管理 Pexels、Pixabay 和 Coverr API 密钥",
+ "Coverr": "Coverr",
+ "Coverr API Key": "Coverr API 密钥 ([获取 API Key](https://coverr.co/developers?ctx=header_navigation))",
+ "Coverr API Keys": "Coverr API 密钥列表",
+ "Please Enter the Coverr API Key": "请输入 **Coverr API 密钥**",
+ "No Coverr API Keys currently": "当前没有 Coverr API 密钥",
+ "Add Coverr API Key": "添加 Coverr API 密钥",
+ "Coverr API Key added successfully": "Coverr API 密钥添加成功",
+ "Select Coverr API Key to delete": "选择要删除的 Coverr API 密钥",
+ "Delete Selected Coverr API Key": "删除选中的 Coverr API 密钥",
+ "Coverr API Key deleted successfully": "Coverr API 密钥删除成功",
"Advanced Video Settings": "高级视频设置",
"Video Encoder": "视频编码器",
"Video Encoder Help": "高级选项。默认 libx264 最稳定;选择硬件编码器时,如果当前 FFmpeg、显卡或驱动不可用,会自动回退到 libx264。"