Drift智能剪辑 API是一种访问Drift剪辑服务器的简单方法,用于创建高质量视频并使其可供下载。通过选择自己喜欢的主题风格或音乐(不选择则智能匹配),将需要剪辑的文件URL及主题、音乐等参数提交剪辑接口即可,任务创建成功后,系统会返回任务ID,通过该ID来获取剪辑。
使用条件
使用剪辑API您只需申请API密钥
协议
Drift API请求使用标准的GET / POST HTTP方法; 响应采用JSON格式。
JSON中返回的数据始终包含“status”字段,其中包含两个值之一:“OK”或“FAIL”。在“FAIL”的情况下,将提供一个或多个附加字段,其中包含解释失败的信息。
流程
创建并提交任务 |
服务器处理 |
检查任务状态(是否完成?) |
下载精剪视频 |
Yes |
No,check again |
认证
API身份验证使用Drift提供的API KEY和API SECRET执行。这些密钥用于为每个API请求生成唯一的请求签名。每个API请求必须具有以下授权字段:
api_key:Drift提供的API KEY。
api_signature:请求的签名。有关如何创建签名的详细信息,请参阅下面的签名生成。
api_timestamp:RFC3339格式的请求的时间戳。
签名生成
使用以下过程生成签名:
1. 以格式创建规范字符串,请求URL:请求主机:请求时间戳。例如:/smartvideo/create:api.driftlife.co:2018-08-08T18:30:02Z
2. 使用SHA-256哈希函数使用Drift API SECRET键创建上述字符串的HMAC(RFC 2104)3. 创建摘要的base 64编码字符串
签名示例:
import datetime
import base64, hmac, hashlib
import json
import requests
API_KEY = '<API KEY>'
API_SECRET = '<API SECRET>'
HOST = 'api.driftlife.co'
def canonical_string(url, host, timestamp):
return "{}:{}:{}".format(url, host, timestamp)
def sign_request(api_secret, url, host, timestamp):
canonical = canonical_string(url, host, timestamp)
sig_hmac = hmac.new(api_secret, canonical, digestmod=hashlib.sha256)
b64_hmac = base64.encodestring(sig_hmac.digest()).strip()
return b64_hmac
def request(path, extra_data=None, protocol='http'):
if not extra_data or not isinstance(extra_data, dict):
extra_data = {}
timestamp = datetime.datetime.utcnow().isoformat("T") + "Z"
api_signature = sign_request(API_SECRET, path, HOST, timestamp)
data = {'api_key': api_key,
'api_signature': api_signature,
'api_timestamp': timestamp}
data.update(extra_data)
headers = {'Content-Type': 'application/json'}
response = requests.post('{}://{}{}'.format(protocol, HOST, path), data=json.dumps(data), headers=headers)
return json.loads(response.text)
接口
- 选择主题
URL | /smartvideo/themes | ||
返回结果(JSON) | |||
正确 | status | 1 | |
tips |
| ||
data | themes主题列表,见Theme Object说明 | ||
错误 | status | 0 | |
tips | 提示信息 | ||
data |
| ||
Theme Object说明
Field | Type | Descripton |
theme_id | String | theme id |
name | String | 主题名称 |
desc | String | 主题说明 |
large_thumb_url | String | 大缩略图地址 |
thumb_url | String | 缩略图地址 |
preview_url | String | Demo地址 |
Theme Object示例:
{
"name": " Happy Holidays!",
"preview_url": "http://musiclib.sightera.com.s3.amazonaws.com/theme/holidays_2017/187/example.mp4",
"theme_id": "187",
"thumb_url": "http://musiclib.sightera.com.s3.amazonaws.com/theme/holidays_2017/187/thumb.jpg",
"large_thumb_url": "http://musiclib.sightera.com.s3.amazonaws.com/theme/holidays_2017/187/lthumb.jpg",
"desc": "Celebrate ALL season long with this festive theme! Make your own holiday greeting to share with family and friends"
}
接口调用示例:
def get_themes(api_key, api_secret, host='api.driftlife.co'):
url = '/smartvideo/themes'
timestamp = datetime.datetime.utcnow().isoformat("T") + "Z"
sig = sign_request(api_secret, url, host, timestamp)
data = {'api_key': api_key,
'api_signature': sig,
'api_timestamp': timestamp}
response = requests.get('https://{}{}'.format(host, url), data)
return response
- 选择音乐
URL | /smartvideo/tracks | |||
返回结果(JSON) | ||||
正确 | status | 1 | ||
tips |
| |||
data | tracks主题列表,见下面Track Object说明 | |||
错误 | status | 0 | ||
tips | 提示信息 | |||
data |
| |||
Track Object说明
Field | Type | Descripton |
track_id | String | track id |
name | String | 音乐名称 |
preview_url | String | Mp3预览地址 |
thumb_url | String | 缩略图地址 |
album | String | 专辑 |
artist | String | 艺术家 |
licensed | Boolean | 是否有版权 |
Track Object示例:
{
"album": "",
"name": "Together We Can",
"artist": "Nicholas Michael Hill",
"preview_url": "http://local.musiclib.sightera.com.s3.amazonaws.com/tracknew/nicholas_michael_hill_564/together_we_can_564_pr.mp3",
"track_id": "23471",
"thumb_url": "http://local.musiclib.sightera.com.s3.amazonaws.com/tracknew/nicholas_michael_hill_138/together_we_can_138.jpg",
"licensed": true
}
接口访问示例:
def get_tracks(api_key, api_secret, host='api.driftlife.co'):
url = '/smartvideo/tracks'
timestamp = datetime.datetime.utcnow().isoformat("T") + "Z"
sig = sign_request(api_secret, url, host, timestamp)
data = {'api_key': api_key,
'api_signature': sig,
'api_timestamp': timestamp,
'filter_tags': {'name': 'instrumental'}
}
headers = {'Content-Type': 'application/json'}
response = requests.post('https://{}{}'.format(host, url), json.dumps(data), headers=headers)
return response
- 制作视频
URL | /smartvideo/create | |||
请求参数 | ||||
参数名称 | 类型 | 说明 | 必填 | |
sources | [] | 资源源文件列表,如:sources = [{'url': 'https:///1.jpg'}, {'url': 'https:///2.jpg'},{'url': 'https:///3.jpg'},{'url': 'https:///4.jpg'},{'url': 'https:///5.jpg'},{'url': 'https:///6.jpg'},{'url': 'https:///9.jpg'}] | 必填 | |
track_id | int | 通过tracks获取的曲目id,默认智能选择 | 可选 | |
theme_id | int | 通过themes获取的主题id,默认智能选择 | 可选 | |
quality | string | 结果视频的质量。默认质量是'sd'。根据您的帐户配置,您可以传递以下值:'fullhd','hd','hq','sd'。 | 可选 | |
product_name | string | 显示的文字 | 可选 | |
logo_url | string | logo地址 | 可选 | |
返回结果(JSON) | ||||
正确 | status | 1 | ||
tips |
| |||
data | video_sessions | |||
错误 | status | 0 | ||
tips | 提示信息 | |||
data |
| |||
接口访问示例:
def create_video(api_key, api_secret, host='api.driftlife.co'):
url = '/smartvideo/create'
timestamp = datetime.datetime.utcnow().isoformat("T") + "Z"
sig = sign_request(api_secret, url, host, timestamp)
data = {'api_key': api_key,
'api_signature': sig,
'api_timestamp': timestamp}
sources = [
{'url': 'https://secure.api.driftlife.co/1.jpg'},
{'url': 'https://secure.api.driftlife.co/2.jpg'},
{'url': 'https://secure.api.driftlife.co/3.jpg', 'mandatory': 'as-is'},
{'url': 'https://secure.api.driftlife.co/4.jpg'},
{'url': 'https://secure.api.driftlife.co/5.jpg', 'mandatory': 'as-is'},
{'url': 'https://secure.api.driftlife.co/6.jpg', 'mandatory': 'as-is'},
{'url': 'https://secure.api.driftlife.co/7.jpg', 'mandatory': 'as-is'}]
data['sources'] = sources
data['product_name'] = 'Hello Drift'
data['logo_url'] = 'https://secure.api.driftlife.co/drift.png'
headers = {'Content-Type': 'application/json'}
response = requests.post('https://{}{}'.format(host, url), json.dumps(data), headers=headers)
return response
- 获取视频
URL | /smartvideo/get | |||
请求参数 | ||||
参数名称 | 类型 | 说明 | 必填 | |
video_session_id | string | create时返回的video_session_id | 必填 | |
返回结果(JSON) | ||||
正确 | status | 1 | ||
tips |
| |||
data | video_session包含下载url及progress等 | |||
错误 | status | 0 | ||
tips | 提示信息 | |||
data |
| |||
接口访问示例:
def get_video(api_key, api_secret, host='api.driftlife.co'):
url = '/smartvideo/get'
timestamp = datetime.datetime.utcnow().isoformat("T") + "Z"
sig = sign_request(api_secret, url, host, timestamp)
data = {'api_key': api_key,
'api_signature': sig,
'api_timestamp': timestamp,
'video_session_id': 'video_session_id'
}
response = requests.get('https://{}{}'.format(host, url), data)
return response