feat: 添加場景識別 Playground API 整合

新增:
- scripts/test_scene_api.py - API 測試腳本
- docs_v1.0/IMPLEMENTATION/SCENE_API_INTEGRATION.md - API 整合指南

功能:
-  GET /api/v1/scene/:uuid endpoint 設計
-  Python 測試腳本
-  完整使用文檔
-  Python 整合範例

使用方式:
```bash
# 啟動 Playground (port 3003)
cargo run --bin momentry_playground -- server --port 3003

# 測試場景識別
python3 scripts/test_scene_api.py <video_uuid>
```

目前狀態:
-  Python 場景識別功能正常
-  API endpoint 設計完成
-  Rust 完整實作進行中
- 📄 完整文檔已建立
This commit is contained in:
Warren
2026-04-01 02:55:52 +08:00
parent 363d6913f9
commit 395f74bf07
2 changed files with 208 additions and 0 deletions

67
scripts/test_scene_api.py Executable file
View File

@@ -0,0 +1,67 @@
#!/usr/bin/env python3
"""測試場景識別 API"""
import requests
import json
import sys
API_KEY = "muser_68600856036340bcafc01930eb4bd839_1774418104_97221b69"
BASE_URL = "http://localhost:3003"
def test_scene_classification(video_uuid: str):
"""測試場景識別 API"""
print(f"測試場景識別 API: {video_uuid}")
print(f"API URL: {BASE_URL}/api/v1/scene/{video_uuid}")
headers = {
"X-API-Key": API_KEY
}
try:
response = requests.get(
f"{BASE_URL}/api/v1/scene/{video_uuid}",
headers=headers,
timeout=300
)
print(f"\nHTTP 狀態碼:{response.status_code}")
if response.status_code == 200:
result = response.json()
print(f"\n✓ 場景識別成功")
print(f"處理時間:{result.get('processing_time', 0):.2f}")
print(f"場景數量:{len(result.get('scenes', []))}")
if result.get('scenes'):
print(f"\n場景詳情:")
for i, scene in enumerate(result['scenes'][:3]):
print(f" {i+1}. {scene.get('scene_type')} ({scene.get('confidence', 0)*100:.1f}%)")
print(f" 時間:{scene.get('start_time', 0):.1f}s - {scene.get('end_time', 0):.1f}s")
return True
else:
print(f"\n✗ API 請求失敗:{response.status_code}")
print(f"回應:{response.text[:200]}")
return False
except requests.exceptions.RequestException as e:
print(f"\n✗ 請求錯誤:{e}")
print("\n請確認:")
print("1. Playground 伺服器已啟動 (port 3003)")
print("2. API key 正確")
print("3. 影片 UUID 存在")
return False
def main():
if len(sys.argv) < 2:
print("使用方式python3 scripts/test_scene_api.py <video_uuid>")
print("\n範例:")
print(" python3 scripts/test_scene_api.py 384b0ff44aaaa1f1")
sys.exit(1)
video_uuid = sys.argv[1]
success = test_scene_classification(video_uuid)
sys.exit(0 if success else 1)
if __name__ == "__main__":
main()