Skip to content

Commit 5adafdb

Browse files
committed
first commit
0 parents  commit 5adafdb

20 files changed

Lines changed: 966 additions & 0 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

LICENSE.txt

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

README.md

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

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+
from qencode import encoder, task
17+
18+
encoder_obj = encoder(API_KEY, api_url=API_URL)
19+
encoder_obj.create_encoder()
20+
21+
task_obj = task(encoder_obj.access_token, encoder_obj.connect)
22+
task_obj.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: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
##Usage
2+
3+
**Usage by transcoding profile ID**
4+
5+
````
6+
from qencode import encoder, task
7+
import time
8+
9+
API_KEY = 'Your Api Key'
10+
TRANSCODING_PROFILEID = 'Your Profile ID'
11+
12+
VIDO_URL = 'Sourse Video Url'
13+
API_URL = 'https://qa.qencode.com'
14+
15+
16+
def start_encode():
17+
"""
18+
Create encoder object
19+
:param api_key: string
20+
:param api_url: string. not required
21+
:return: encode object
22+
"""
23+
encoder_obj = encoder(API_KEY, api_url=API_URL)
24+
encoder_obj.create_encoder()
25+
if encoder_obj.error:
26+
print 'encoder error:', encoder_obj.error, encoder_obj.message
27+
raise SystemExit
28+
29+
"""
30+
Create task
31+
:param access_token: string. access_token from encoder object
32+
:param connect: string. connect object from encoder object
33+
:return: task object
34+
"""
35+
task_obj = task(encoder_obj.access_token, encoder_obj.connect)
36+
task_obj.start(TRANSCODING_PROFILEID, VIDO_URL)
37+
if task_obj.error:
38+
raise SystemExit
39+
40+
while True:
41+
status = task_obj.status()
42+
print status
43+
if status['error']:
44+
break
45+
if status['status'] == 'completed':
46+
break
47+
time.sleep(15)
48+
49+
if __name__ == '__main__':
50+
start_encode()
51+
````
52+
53+
**Usage by custom parameters**
54+
55+
````
56+
from qencode import encoder, task, custom_params
57+
import time
58+
59+
API_KEY = 'Your Api Key'
60+
API_URL = 'https://qa.qencode.com'
61+
62+
format = custom_params.format
63+
stream = custom_params.stream
64+
destination = custom_params.destination
65+
video_codec = custom_params.x264_video_codec
66+
params = custom_params.base
67+
68+
destination.url = "s3://s3-eu-west-2.amazonaws.com/qencode-test"
69+
destination.key = "AKIAIKZIPSJ7SDAIWK4A"
70+
destination.secret = "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"
71+
72+
video_codec.vprofile = "baseline"
73+
video_codec.level = 31
74+
video_codec.coder = 0
75+
video_codec.flags2 = "-bpyramid+fastpskip-dct8x8"
76+
video_codec.partitions = "+parti8x8+parti4x4+partp8x8+partb8x8"
77+
video_codec.directpred = 2
78+
79+
stream.size = "1920x1080"
80+
stream.audio_bitrate = 128
81+
stream.video_codec_parameters = video_codec
82+
83+
format.stream = [stream]
84+
format.output = "advanced_hls"
85+
format.destination = destination
86+
87+
params.source = 'https://qa.stagevids.com/static/1.mp4'
88+
params.format = [format]
89+
90+
91+
92+
def start_encode():
93+
94+
"""
95+
Create encoder object
96+
:param api_key: string
97+
:param api_url: string. not required
98+
:return: encode object
99+
"""
100+
encoder_obj = encoder(API_KEY, api_url=API_URL)
101+
encoder_obj.create_encoder()
102+
if encoder_obj.error:
103+
print 'encoder error:', encoder_obj.error, encoder_obj.message
104+
raise SystemExit
105+
106+
"""
107+
Create task
108+
:param access_token: string. access_token from encoder object
109+
:param connect: string. connect object from encoder object
110+
:return: task object
111+
"""
112+
task_obj = task(encoder_obj.access_token, encoder_obj.connect)
113+
task_obj.custom_start(params)
114+
if task_obj.error:
115+
raise SystemExit
116+
117+
while True:
118+
status = task_obj.status()
119+
print status
120+
if status['error']:
121+
break
122+
if status['status'] == 'completed':
123+
break
124+
time.sleep(15)
125+
126+
127+
if __name__ == '__main__':
128+
start_encode()
129+
````
130+
**Usage with callback methods**
131+
132+
````
133+
def my_callback(e):
134+
print e
135+
136+
def my_callback2(e):
137+
print e
138+
139+
...
140+
141+
task_obj.start(TRANSCODING_PROFILEID, VIDO_URL)
142+
if task_obj.error:
143+
raise SystemExit
144+
145+
task_obj.progress_changed(my_callback)
146+
task_obj.task_completed(my_callback2)
147+
````
148+
149+
**Documentation**
150+
151+
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 QencodeApiClient
4+
return QencodeApiClient(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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from httptools import Http
2+
from task import Task
3+
4+
class QencodeApiClient(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-qa.qencode.com' # '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+
19+
20+
def create(self):
21+
response = self.connect.request('access_token', dict(api_key=self.api_key))
22+
if not response['error']:
23+
self.access_token = response['token']
24+
else:
25+
self.error = response['error']
26+
self.message = response.get('message')
27+
28+
def create_task(self, **kwargs):
29+
return Task(self.access_token, self.connect, **kwargs)

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)