test-video-full-flow.ps1 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # Full flow test: create video -> poll results
  2. # Uses cover images from existing videos as test materials
  3. # --- Config ---
  4. $appKey = "ZmNmOGRhNjYzZTAx"
  5. $appSecretB64 = "ZWFhMTIxNTRjMjQ4Y2FkOTE1OWE5ZDZlYThiZWRmNDY="
  6. $appSecret = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($appSecretB64))
  7. $accountId = "12859_117409"
  8. $callbackUrl = "https://server.fmode.cn/api/functions/cut/onemerge"
  9. # --- Generate timestamp and sign ---
  10. $timestamp = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds().ToString()
  11. $signStr = "$timestamp#$appSecret"
  12. $md5 = [System.Security.Cryptography.MD5]::Create()
  13. $signBytes = $md5.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($signStr))
  14. $sign = ($signBytes | ForEach-Object { $_.ToString("x2") }) -join ''
  15. Write-Host "Timestamp: $timestamp"
  16. Write-Host "Sign: $sign"
  17. Write-Host ""
  18. # --- Build materials (use existing cover images as test) ---
  19. $materials = @(
  20. @{ type = "pic"; value = "https://img.kuaizi.co/video/12859/12172925/749/1080x1920_5000_96/b65038bd93c1214e3ffb99e964379a8a.jpg" },
  21. @{ type = "pic"; value = "https://img.kuaizi.co/video/12859/12172918/749/1080x1920_5000_96/71d10a2e42c548492410d3f1f466320b.jpg" },
  22. @{ type = "pic"; value = "https://img.kuaizi.co/video/12859/12172872/749/1080x1920_5000_96/70f54baeb92a44d35f022b31068311dd.jpg" }
  23. )
  24. $preId = $timestamp
  25. $apiBody = @{
  26. account_id = $accountId
  27. callback_url = $callbackUrl
  28. material_list = $materials
  29. tags = "test,openclaw,skill"
  30. proportion = "9:16"
  31. video_duration = @{ min = 10; max = 15 }
  32. pre_id = $preId
  33. compose_number = 1
  34. ai_voice = 1
  35. ai_bgm = 1
  36. ai_flower = 1
  37. ai_subtitle = 0
  38. original_voice = 0
  39. }
  40. $relayData = @{
  41. apiPath = "/v2/video/vlog/create"
  42. apiBody = $apiBody
  43. appKey = $appKey
  44. timestamp = $timestamp
  45. sign = $sign
  46. } | ConvertTo-Json -Depth 5 -Compress
  47. $requestBody = @{
  48. action = "relay"
  49. relayData = $relayData
  50. } | ConvertTo-Json -Compress
  51. # --- Step 1: Create video ---
  52. Write-Host "=== Step 1: kuaizi-video-create ===" -ForegroundColor Cyan
  53. try {
  54. $r1 = Invoke-RestMethod -Uri "https://server.fmode.cn/api/functions/cut/onemerge" -Method POST -ContentType "application/json" -Body $requestBody -TimeoutSec 30
  55. Write-Host "Response:" -ForegroundColor Green
  56. $r1 | ConvertTo-Json -Depth 5
  57. # Extract task_id
  58. $taskId = ""
  59. if ($r1.data -and $r1.data.task_id) {
  60. $taskId = $r1.data.task_id
  61. } elseif ($r1.task_id) {
  62. $taskId = $r1.task_id
  63. }
  64. if ($taskId) {
  65. Write-Host ""
  66. Write-Host "task_id: $taskId" -ForegroundColor Yellow
  67. # --- Step 2: Poll for results ---
  68. Write-Host ""
  69. Write-Host "=== Step 2: kuaizi-video-query (polling) ===" -ForegroundColor Cyan
  70. Write-Host "Polling every 15s, max 4 attempts for this test..."
  71. $pollBody = @{
  72. id = "sWvRr8RvPT"
  73. _ApplicationId = "ncloudmaster"
  74. action = "query"
  75. taskId = $taskId
  76. } | ConvertTo-Json -Compress
  77. for ($i = 1; $i -le 4; $i++) {
  78. Write-Host " Poll #$i..." -NoNewline
  79. $r2 = Invoke-RestMethod -Uri "https://server.fmode.cn/api/functions" -Method POST -ContentType "application/json" -Body $pollBody -TimeoutSec 15
  80. $dataCount = 0
  81. if ($r2.data) { $dataCount = $r2.data.Count }
  82. if ($dataCount -gt 0) {
  83. Write-Host " Got $dataCount video(s)!" -ForegroundColor Green
  84. $r2 | ConvertTo-Json -Depth 5
  85. break
  86. } else {
  87. Write-Host " No results yet (still generating)" -ForegroundColor DarkYellow
  88. if ($i -lt 4) {
  89. Write-Host " Waiting 15s..."
  90. Start-Sleep -Seconds 15
  91. }
  92. }
  93. }
  94. Write-Host ""
  95. Write-Host "Note: Video generation typically takes 2-5 min. Use taskId=$taskId to check later." -ForegroundColor Yellow
  96. } else {
  97. Write-Host "No task_id in response" -ForegroundColor Red
  98. }
  99. } catch {
  100. Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
  101. if ($_.Exception.Response) {
  102. $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
  103. Write-Host "Response body: $($reader.ReadToEnd())" -ForegroundColor Red
  104. }
  105. }