获取视频内容
curl --request GET \
--url https://api.heizhu.lol/v1/videos/{task_id}/content \
--header 'Authorization: Bearer <token>'const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.heizhu.lol/v1/videos/{task_id}/content', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.heizhu.lol/v1/videos/{task_id}/content"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)"<string>"{
"error": "<string>",
"code": "<string>",
"message": "<string>",
"success": true
}{
"error": "<string>",
"code": "<string>",
"message": "<string>",
"success": true
}獲取影片內容
下載或流式讀取已完成任務的影片檔案。
GET
https://api.heizhu.lol
/
v1
/
videos
/
{task_id}
/
content
获取视频内容
curl --request GET \
--url https://api.heizhu.lol/v1/videos/{task_id}/content \
--header 'Authorization: Bearer <token>'const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.heizhu.lol/v1/videos/{task_id}/content', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.heizhu.lol/v1/videos/{task_id}/content"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)"<string>"{
"error": "<string>",
"code": "<string>",
"message": "<string>",
"success": true
}{
"error": "<string>",
"code": "<string>",
"message": "<string>",
"success": true
}任務狀態為
completed 後,使用內容介面讀取生成影片。介面可能直接返回影片流,也可能跟隨安全代理讀取最終影片。
string
必填
已完成的影片任務 ID。
下載到檔案
curl -L https://api.heizhu.lol/v1/videos/task_xxxxxxxxxx/content \
-H "Authorization: Bearer $BLACKPIG_API_KEY" \
--output result.mp4
-L 用於跟隨可能出現的重定向。內容介面同樣需要 Bearer Token。
JavaScript
const response = await fetch(
`https://api.heizhu.lol/v1/videos/${taskId}/content`,
{
headers: {
Authorization: `Bearer ${process.env.BLACKPIG_API_KEY}`,
},
},
);
if (!response.ok) {
throw new Error(await response.text());
}
const video = Buffer.from(await response.arrayBuffer());
await fs.promises.writeFile('result.mp4', video);
使用建議
- 僅在任務狀態為
completed後請求內容。 - 獲取成功後,將結果儲存到你自己的物件儲存。
- 不要在前端暴露平臺 Token;由你的服務端獲取後再提供受控下載。
- 對較大檔案使用流式寫入,避免全部載入記憶體。
