|
1 | | -##Usage |
| 1 | +# Usage |
2 | 2 |
|
3 | | -**Usage by transcoding profile ID** |
| 3 | +## Usage by transcoding profile ID |
4 | 4 |
|
5 | | -``` |
6 | | -import sys |
| 5 | +```python |
7 | 6 | import os.path |
8 | | -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) |
9 | | -import qencode |
| 7 | +import sys |
10 | 8 | import time |
11 | 9 |
|
| 10 | +import qencode |
12 | 11 |
|
13 | 12 | API_KEY = 'Your API KEY' |
14 | 13 | TRANSCODING_PROFILEID = 'Your profile ID' |
15 | | -VIDO_URL = 'your source url' |
16 | | -
|
| 14 | +VIDEO_URL = 'your source url' |
17 | 15 |
|
18 | 16 |
|
19 | 17 | def start_encode(): |
20 | | - """ |
21 | | - Create client object |
22 | | - :param api_key: string. required |
23 | | - :param api_url: string. not required |
24 | | - :param api_version: int. not required. default 'v1' |
25 | | - :return: client object |
26 | | - """ |
27 | | - client = qencode.client(API_KEY) |
28 | | - client.create() |
29 | | - if client.error: |
30 | | - print 'encoder error:', client.error, client.message |
31 | | - raise SystemExit |
32 | | -
|
33 | | - """ |
34 | | - :return: task object |
35 | | - """ |
36 | | - task = client.create_task() |
37 | | - task.start_time = 0.0 |
38 | | - task.duration = 10.0 |
39 | | - task.start(TRANSCODING_PROFILEID, VIDO_URL) |
40 | | - if task.error: |
41 | | - print 'task error:', task.error, task.message |
42 | | - raise SystemExit |
43 | | -
|
44 | | - while True: |
45 | | - status = task.status() |
46 | | - print '{0} | {1} | {2} | error: {3}'.format(VIDO_URL, |
47 | | - status.get('status'), |
48 | | - status.get('percent'), |
49 | | - status.get('error'), |
50 | | - status.get('error_description')) |
51 | | - if status['error']: |
52 | | - break |
53 | | - if status['status'] == 'completed': |
54 | | - break |
55 | | - time.sleep(15) |
| 18 | + client = qencode.client(API_KEY) |
| 19 | + client.create() |
| 20 | + if client.error: |
| 21 | + print 'encoder error:', client.error, client.message |
| 22 | + raise SystemExit |
| 23 | + |
| 24 | + task = client.create_task() |
| 25 | + task.start_time = 0.0 |
| 26 | + task.duration = 10.0 |
| 27 | + task.start(TRANSCODING_PROFILEID, VIDEO_URL) |
| 28 | + if task.error: |
| 29 | + print 'task error:', task.error, task.message |
| 30 | + raise SystemExit |
| 31 | + |
| 32 | + while True: |
| 33 | + status = task.status() |
| 34 | + print ( |
| 35 | + '{0} | {1} | {2} | error: {3}'.format( |
| 36 | + VIDEO_URL, |
| 37 | + status.get('status'), |
| 38 | + status.get('percent'), |
| 39 | + status.get('error'), |
| 40 | + status.get('error_description'), |
| 41 | + ) |
| 42 | + ) |
| 43 | + if status['error']: |
| 44 | + break |
| 45 | + if status['status'] == 'completed': |
| 46 | + break |
| 47 | + time.sleep(15) |
56 | 48 |
|
57 | 49 |
|
58 | 50 | if __name__ == '__main__': |
59 | | - start_encode() |
| 51 | + start_encode() |
60 | 52 | ``` |
61 | 53 |
|
62 | | -**Usage by custom parameters** |
| 54 | +## Usage by custom parameters |
63 | 55 |
|
64 | | -``` |
65 | | -import sys |
| 56 | +```python |
66 | 57 | import os.path |
67 | | -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) |
68 | | -import qencode |
| 58 | +import sys |
69 | 59 | import time |
70 | 60 |
|
| 61 | +import qencode |
| 62 | + |
71 | 63 | API_KEY = 'Your API KEY' |
72 | 64 |
|
73 | 65 | params = qencode.custom_params() |
@@ -103,68 +95,72 @@ params.format = [FORMAT] |
103 | 95 |
|
104 | 96 |
|
105 | 97 | def start_encode(): |
106 | | -
|
107 | | - """ |
| 98 | + """ |
108 | 99 | Create client object |
109 | 100 | :param api_key: string. required |
110 | 101 | :param api_url: string. not required |
111 | 102 | :param api_version: int. not required. default 'v1' |
112 | 103 | :return: client object |
113 | | - """ |
114 | | - client = qencode.client(API_KEY) |
115 | | - client.create() |
116 | | - if client.error: |
117 | | - print 'encoder error:', client.error, client.message |
118 | | - raise SystemExit |
119 | | -
|
120 | | - """ |
| 104 | + """ |
| 105 | + client = qencode.client(API_KEY) |
| 106 | + client.create() |
| 107 | + if client.error: |
| 108 | + print('encoder error:', client.error, client.message) |
| 109 | + raise SystemExit |
| 110 | + |
| 111 | + """ |
121 | 112 | Create task |
122 | 113 | :return: task object |
123 | | - """ |
124 | | -
|
125 | | - task = client.create_task() |
126 | | - task.custom_start(params) |
127 | | - if task.error: |
128 | | - print 'task error:', task.error, task.message |
129 | | - raise SystemExit |
130 | | -
|
131 | | - while True: |
132 | | - status = task.status() |
133 | | - print '{0} | {1} | {2} | error: {3}'.format(params.source, |
134 | | - status.get('status'), |
135 | | - status.get('percent'), |
136 | | - status.get('error'), |
137 | | - status.get('error_description')) |
138 | | - if status['error']: |
139 | | - break |
140 | | - if status['status'] == 'completed': |
141 | | - break |
142 | | - time.sleep(15) |
| 114 | + """ |
| 115 | + task = client.create_task() |
| 116 | + task.custom_start(params) |
| 117 | + if task.error: |
| 118 | + print('task error:', task.error, task.message) |
| 119 | + raise SystemExit |
| 120 | + |
| 121 | + while True: |
| 122 | + status = task.status() |
| 123 | + print( |
| 124 | + '{0} | {1} | {2} | error: {3}'.format( |
| 125 | + params.source, |
| 126 | + status.get('status'), |
| 127 | + status.get('percent'), |
| 128 | + status.get('error'), |
| 129 | + status.get('error_description'), |
| 130 | + ) |
| 131 | + ) |
| 132 | + if status['error']: |
| 133 | + break |
| 134 | + if status['status'] == 'completed': |
| 135 | + break |
| 136 | + time.sleep(15) |
143 | 137 |
|
144 | 138 |
|
145 | 139 | if __name__ == '__main__': |
146 | | - start_encode() |
| 140 | + start_encode() |
147 | 141 | ``` |
148 | 142 |
|
149 | | -**Usage with callback methods** |
| 143 | +## Usage with callback methods |
150 | 144 |
|
151 | 145 | ``` |
152 | | -def my_callback(e): |
153 | | - print e |
| 146 | +def on_process_changed(process_data): |
| 147 | + print('on_process_changed', process_data) |
154 | 148 |
|
155 | | -def my_callback2(e): |
156 | | - print e |
157 | 149 |
|
158 | | -... |
| 150 | +def on_task_completed(process_data): |
| 151 | + print('on_task_completed', process_data) |
159 | 152 |
|
160 | | -task.start(TRANSCODING_PROFILEID, VIDO_URL) |
| 153 | +
|
| 154 | +# ... |
| 155 | +
|
| 156 | +task.start(TRANSCODING_PROFILEID, VIDEO_URL) |
161 | 157 | if task.error: |
162 | | - raise SystemExit |
| 158 | + raise SystemExit |
163 | 159 |
|
164 | 160 | task.progress_changed(my_callback) |
165 | | -task.task_completed(my_callback2) |
| 161 | +task.task_completed(on_task_completed) |
166 | 162 | ``` |
167 | 163 |
|
168 | | -**Documentation** |
| 164 | +## Documentation |
169 | 165 |
|
170 | 166 | Documentation is available at <https://docs.qencode.com> |
0 commit comments