Skip to content

Commit 66c0377

Browse files
init commit
1 parent 58cc956 commit 66c0377

19 files changed

+1064
-0
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.env
2+
.DS_Store
3+
4+
*.log
5+
*.sql
6+
*.pyc
7+
8+
.cache/
9+
.vscode/
10+
.idea/
11+
12+
13+

LICENSE.txt

Lines changed: 34 additions & 0 deletions
Large diffs are not rendered by default.

docs/install.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
##Installation
2+
3+
**install sdk libraries from github**
4+
5+
````
6+
cd your-workspace-folder
7+
git clone https://github.com/qencode-dev/qencode-api-python-client
8+
cd qencode-api-python-client
9+
pip install -r requirements.txt
10+
python setup.py install
11+
````
12+
13+
**install from pip**
14+
15+
````
16+
sudo pip install qencode
17+
````

docs/quickstart.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## Installation
2+
3+
**install sdk libraries from github**
4+
5+
````
6+
cd your-workspace-folder
7+
git clone https://github.com/qencode-dev/qencode-api-python-client
8+
cd qencode-api-python-client
9+
pip install -r requirements.txt
10+
python setup.py install
11+
````
12+
13+
**Usage**
14+
15+
````
16+
import qencode
17+
18+
client = qencode.client(API_KEY)
19+
client.create()
20+
21+
task = client.create_task()
22+
task.start(TRANSCODING_PROFILEID, VIDO_URL)
23+
24+
````
25+
26+
27+
**Documentation**
28+
29+
Documentation is available at <https://docs.qencode.com>

docs/usage.md

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
##Usage
2+
3+
**Usage by transcoding profile ID**
4+
5+
````
6+
import sys
7+
import os.path
8+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
9+
import qencode
10+
import time
11+
12+
13+
API_KEY = 'Your API KEY'
14+
TRANSCODING_PROFILEID = 'Your profile ID'
15+
VIDO_URL = 'your source url'
16+
17+
18+
19+
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)
56+
57+
58+
if __name__ == '__main__':
59+
start_encode()
60+
````
61+
62+
**Usage by custom parameters**
63+
64+
````
65+
import sys
66+
import os.path
67+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
68+
import qencode
69+
import time
70+
71+
API_KEY = 'Your API KEY'
72+
73+
params = qencode.custom_params()
74+
75+
FORMAT = qencode.format()
76+
STREAM = qencode.stream()
77+
DESTINATION = qencode.destination()
78+
VIDEO_CODEC = qencode.x264_video_codec()
79+
80+
81+
DESTINATION.url = "..."
82+
DESTINATION.key = "..."
83+
DESTINATION.secret = "..."
84+
DESTINATION.remove_null_params()
85+
86+
VIDEO_CODEC.vprofile = "baseline"
87+
VIDEO_CODEC.level = 31
88+
VIDEO_CODEC.coder = 0
89+
VIDEO_CODEC.flags2 = "-bpyramid+fastpskip-dct8x8"
90+
VIDEO_CODEC.partitions = "+parti8x8+parti4x4+partp8x8+partb8x8"
91+
VIDEO_CODEC.directpred = 2
92+
VIDEO_CODEC.remove_null_params()
93+
94+
STREAM.profile = "baseline"
95+
STREAM.size = "1920x1080"
96+
STREAM.audio_bitrate = 128
97+
STREAM.video_codec_parameters = VIDEO_CODEC
98+
STREAM.remove_null_params()
99+
100+
FORMAT.stream = [STREAM]
101+
FORMAT.output = "advanced_hls"
102+
FORMAT.destination = DESTINATION
103+
FORMAT.remove_null_params()
104+
105+
params.source = 'your source url'
106+
params.format = [FORMAT]
107+
108+
109+
def start_encode():
110+
111+
"""
112+
Create client object
113+
:param api_key: string. required
114+
:param api_url: string. not required
115+
:param api_version: int. not required. default 'v1'
116+
:return: client object
117+
"""
118+
client = qencode.client(API_KEY)
119+
client.create()
120+
if client.error:
121+
print 'encoder error:', client.error, client.message
122+
raise SystemExit
123+
124+
"""
125+
Create task
126+
:return: task object
127+
"""
128+
129+
task = client.create_task()
130+
task.custom_start(params)
131+
if task.error:
132+
print 'task error:', task.error, task.message
133+
raise SystemExit
134+
135+
while True:
136+
status = task.status()
137+
print '{0} | {1} | {2} | error: {3}'.format(params.source,
138+
status.get('status'),
139+
status.get('percent'),
140+
status.get('error'),
141+
status.get('error_description'))
142+
if status['error']:
143+
break
144+
if status['status'] == 'completed':
145+
break
146+
time.sleep(15)
147+
148+
149+
if __name__ == '__main__':
150+
start_encode()
151+
````
152+
**Usage with callback methods**
153+
154+
````
155+
def my_callback(e):
156+
print e
157+
158+
def my_callback2(e):
159+
print e
160+
161+
...
162+
163+
task.start(TRANSCODING_PROFILEID, VIDO_URL)
164+
if task.error:
165+
raise SystemExit
166+
167+
task.progress_changed(my_callback)
168+
task.task_completed(my_callback2)
169+
````
170+
171+
**Documentation**
172+
173+
Documentation is available at <https://docs.qencode.com>

qencode/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
def client(api_key, api_url=None, version=None, **kwargs):
3+
from . client import Client
4+
return Client(api_key, api_url=api_url, version=version, **kwargs)
5+
6+
def custom_params():
7+
from . custom_params import CustomTranscodingParams
8+
return CustomTranscodingParams()
9+
10+
def format():
11+
from . custom_params import Format
12+
return Format()
13+
14+
def destination():
15+
from . custom_params import Destination
16+
return Destination()
17+
18+
def stream():
19+
from . custom_params import Stream
20+
return Stream()
21+
22+
def x264_video_codec():
23+
from . custom_params import Libx264_VideoCodecParameters
24+
return Libx264_VideoCodecParameters()
25+
26+
def x265_video_codec():
27+
from . custom_params import Libx265_VideoCodecParameters
28+
return Libx265_VideoCodecParameters()
29+
30+
31+

qencode/client.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from . httptools import Http
2+
from . task import Task
3+
4+
class Client(object):
5+
6+
"""
7+
:return: encoder object
8+
9+
"""
10+
def __init__(self, api_key, api_url=None, version=None, **kwargs):
11+
self.api_key = api_key
12+
self.api_url = api_url if api_url else 'https://api.qencode.com/'
13+
self.version = version if version else 'v1'
14+
self.connect = Http(self.version, self.api_url)
15+
self.access_token = None
16+
self.error = None
17+
self.message = ''
18+
self._get_access_token()
19+
20+
def create_task(self, **kwargs):
21+
return Task(self.access_token, self.connect, **kwargs)
22+
23+
def refresh_access_token(self, **kwargs):
24+
response = self.connect.request('access_token', dict(api_key=self.api_key))
25+
if not response['error']:
26+
self.access_token = response['token']
27+
else:
28+
self.error = response['error']
29+
self.message = response.get('message')
30+
31+
def _get_access_token(self):
32+
response = self.connect.request('access_token', dict(api_key=self.api_key))
33+
if not response['error']:
34+
self.access_token = response['token']
35+
else:
36+
self.error = response['error']
37+
self.message = response.get('message')

qencode/const.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
REPEAT = 32
2+
SLEEP_REGULAR = 10
3+
SLEEP_ERROR = 60
4+
COMPLETED_STATUS = ['completed', 'saved']

0 commit comments

Comments
 (0)