update
This commit is contained in:
@ -52,7 +52,7 @@ def display_operation_status():
|
||||
status = st.session_state.operation_status
|
||||
message_type = status.get("type", "info")
|
||||
message = status.get("message", "")
|
||||
|
||||
print(f"{message}")
|
||||
if message_type == "success":
|
||||
st.toast(f"✅ {message}")
|
||||
elif message_type == "error":
|
||||
@ -92,6 +92,7 @@ def search_pixabay_videos(api_key, query, target_count=20, buffer=2):
|
||||
if not data.get("hits"): break
|
||||
for video in data["hits"]:
|
||||
try:
|
||||
if video.get('duration', 0) < 12: break
|
||||
video_details = video.get('videos', {}).get('large', {})
|
||||
width, height = video_details.get('width', 0), video_details.get('height', 0)
|
||||
if width > 0 and height > 0 and width >= height:
|
||||
@ -128,7 +129,8 @@ def search_pexels_videos(api_key: str, query: str, target_count: int = 20) -> tu
|
||||
params = {
|
||||
"query": query,
|
||||
"per_page": target_count + 5, # 多取一些以過濾
|
||||
"orientation": 'landscape'
|
||||
"orientation": 'landscape',
|
||||
"min_duration": 12
|
||||
}
|
||||
|
||||
try:
|
||||
@ -139,10 +141,17 @@ def search_pexels_videos(api_key: str, query: str, target_count: int = 20) -> tu
|
||||
videos = data.get("videos", [])
|
||||
if not videos:
|
||||
return True, "在 Pexels 找不到符合條件的影片,請嘗試其他關鍵字。", []
|
||||
|
||||
final_results = videos[:target_count]
|
||||
return True, f"成功從 Pexels 找到 {len(final_results)} 個橫式影片。", final_results
|
||||
filtered_videos = [
|
||||
v for v in videos if v.get("duration", 0) >= 12
|
||||
]
|
||||
|
||||
if not filtered_videos:
|
||||
return True, "找到影片,但沒有任何一部長度超過 12 秒。", []
|
||||
|
||||
# 取回目標數量的結果
|
||||
final_results = filtered_videos[:target_count]
|
||||
|
||||
return True, f"成功找到 {len(final_results)} 個符合條件的影片。", final_results
|
||||
except requests.RequestException as e:
|
||||
# Pexels 的錯誤訊息通常在 response body 中
|
||||
error_info = ""
|
||||
|
||||
Reference in New Issue
Block a user