forked from Qencode-Corp/qencode-api-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_custom_with_json.py
More file actions
67 lines (52 loc) · 1.42 KB
/
start_custom_with_json.py
File metadata and controls
67 lines (52 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
import qencode
import time
import json
from qencode import QencodeClientException, QencodeTaskException
#replace with your API KEY (can be found in your Project settings on Qencode portal)
API_KEY = 'your-api-qencode-key'
params = """
{"query": {
"source": "https://qencode.com/static/1.mp4",
"format": [
{
"output": "mp4",
"size": "320x240",
"video_codec": "libx264"
}
]
}
}
"""
def start_encode():
"""
Create client object
:param api_key: string. required
:param api_url: string. not required
:param api_version: int. not required. default 'v1'
:return: task object
"""
client = qencode.client(API_KEY)
if client.error:
raise QencodeClientException(client.message)
print 'The client created. Expire date: %s' % client.expire
task = client.create_task()
if task.error:
raise QencodeTaskException(task.message)
task.custom_start(params)
if task.error:
raise QencodeTaskException(task.message)
print 'Start encode. Task: %s' % task.task_token
while True:
status = task.status()
# print status
print json.dumps(status, indent=2, sort_keys=True)
if status['error'] or status['status'] == 'completed':
break
time.sleep(5)
if __name__ == '__main__':
start_encode()