跳转到正文Baichentoken
控制台

视频保存与下载

查询得到 status: completed 后,使用响应里的 video_url 下载文件,或通过创建任务所在正式站的鉴权下载接口获取文件。

同站鉴权下载

curl --fail --location --connect-timeout 15 --max-time 600 \
  'https://api.e6t.cn/v1/videos/YOUR_TASK_ID/content' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -o result.mp4

YOUR_TASK_ID 是正式站创建响应中的 id,Key 使用同一正式站的 Video 分组密钥。只有任务完成后才能下载;任务不存在、未完成或无权访问时,会返回错误。不要将这里的任务 ID 换成网关或上游的内部 ID。

该接口与极途上游自己的下载接口不是同一个服务。客户调用正式站地址即可,无需拼接上游下载路径。

获取下载地址

curl https://api.e6t.cn/v1/videos/TASK_ID \
  -H 'Authorization: Bearer YOUR_API_KEY'
{
  "id": "task_example",
  "status": "completed",
  "progress": 100,
  "video_url": "https://cdn.example.com/result.mp4",
  "completed_at": 1791000042
}

以下 cdn.example.com 只是示例,需要换成实际返回地址。对返回的媒体链接不要附带 API Key;需要鉴权下载时使用上面的同站接口。

cURL 和 wget

curl --fail -L 'https://cdn.example.com/result.mp4' -o result.mp4
wget 'https://cdn.example.com/result.mp4' -O result.mp4

cURL 的 -L 跟随重定向,--fail 使 HTTP 错误返回非零退出码。

Python

import requests

video_url = "https://cdn.example.com/result.mp4"
with requests.get(video_url, stream=True, timeout=60) as response:
    response.raise_for_status()
    with open("result.mp4", "wb") as output:
        for chunk in response.iter_content(chunk_size=8192):
            if chunk:
                output.write(chunk)

Node.js

示例先保存到临时文件,传输完成后再改名,避免把不完整文件当作成功结果。

import { createWriteStream } from 'node:fs';
import { rename, rm } from 'node:fs/promises';
import { Readable } from 'node:stream';
import { pipeline } from 'node:stream/promises';

const temporary = './result.mp4.part';
try {
  const response = await fetch('https://cdn.example.com/result.mp4');
  if (!response.ok || !response.body) {
    throw new Error(`Download failed: HTTP ${response.status}`);
  }
  await pipeline(Readable.fromWeb(response.body), createWriteStream(temporary));
  await rename(temporary, './result.mp4');
} catch (error) {
  await rm(temporary, { force: true });
  throw error;
}

验证下载

检查状态码、文件类型、文件大小和播放情况。HTML 登录页或错误页不能作为视频使用。

curl -I 'https://cdn.example.com/result.mp4'
ls -lh result.mp4

若服务提供校验和,可以进行校验。Content-Length 可用于辅助核对大小,但并不替代完整性校验。

下载失败

  1. 重新查询原任务,确认仍为 completed。
  2. 使用最新响应的 video_url 重试。
  3. 403 / 404 时检查权限、过期和地址是否正确。
  4. 临时 5xx 或网络错误采用有限次数的退避重试。
  5. 只有下载服务明确要求且确认地址可信时,才向该下载服务发送认证信息。

长期存储

把文件转存到自己的对象存储,并记录任务 ID、模型、创建与完成时间、文件大小及存储位置。视频链接的有效期按实际服务策略为准,不能当作永久地址。

断点续传取决于下载服务是否支持 Range 请求,可按支持情况使用 wget -c 等工具。

On this page