Skip to content

Commit 4a259cb

Browse files
updates for getting status of encoding
1 parent fd44ffa commit 4a259cb

File tree

5 files changed

+54
-26
lines changed

5 files changed

+54
-26
lines changed

qencode3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def x265_video_codec():
2929

3030
from . exeptions import QencodeClientException, QencodeTaskException
3131

32-
__version__ = "0.9.25"
32+
__version__ = "0.9.26"
3333
__status__ = "Beta"
3434
__author__ = "Qencode"
3535

qencode3/const.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
REPEAT = 32
22
SLEEP_REGULAR = 10
33
SLEEP_ERROR = 60
4-
COMPLETED_STATUS = ['completed', 'saved']
4+
COMPLETED_STATUS = ['completed', 'saved']
5+
6+
ERROR_OK = 0
7+
ERROR_SERVER_INTERNAL = 1
8+
ERROR_BAD_APP_ID = 2
9+
ERROR_APP_ID_NOT_FOUND = 3
10+
ERROR_BAD_TOKEN = 4
11+
ERROR_TOKEN_NOT_FOUND = 5
12+
ERROR_TARIFF_NOT_PAID = 6
13+
ERROR_MASTER_NOT_FOUND = 7
14+
ERROR_SYSTEM_BUSY = 8
15+
ERROR_BAD_PAYLOAD = 9
16+
ERROR_PROJECT_NOT_FOUND = 10
17+
ERROR_BAD_PROFILE = 11
18+
ERROR_PROFILE_NOT_FOUND = 12
19+
ERROR_BAD_TOKENS = 13
20+
ERROR_FIELD_REQUIRED = 14

qencode3/httptools.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ def __init__(self, version, url, debug=False):
1212

1313
def _call_server(self, url, post_data):
1414
if not url:
15-
response = dict(error=True, message='AttributeError: not URL')
15+
response = dict(error=True, message='AttributeError: Bad URL: ' + str(url))
1616
return json.dumps(response)
1717
data = urlencode(post_data).encode("utf-8")
1818
request = urllib2.Request(url, data)
19+
#print('call_server: ', url, data)
1920
try:
2021
res = urllib2.urlopen(request)
2122
except urllib2.HTTPError as e:
@@ -48,4 +49,4 @@ def post(self, url, data):
4849
response = json.loads(response)
4950
except ValueError as e:
5051
response = dict(error=True, message=repr(e))
51-
return response
52+
return response

qencode3/task.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Task(object):
1010
def __init__(self, access_token, connect, debug=False, **kwargs):
1111
self.connect = connect
1212
self.status_url = None
13+
self.main_status_url = '{0}/{1}/status'.format(self.connect.url, self.connect.version)
1314
self.task_token = None
1415
self.upload_url = None
1516
self.access_token = access_token
@@ -166,33 +167,43 @@ def _create_task(self, count):
166167

167168
def _start_encode(self, api_name, data):
168169
res = self.connect.request(api_name, data)
169-
if not res['error']:
170-
self.status_url = res.get('status_url')
170+
if not res['error'] and res.get('status_url'):
171+
self.status_url = res['status_url']
171172
else:
172-
self.status_url = '{0}/{1}/status'.format(self.connect.url, self.connect.version)
173-
self.error = res['error']
173+
self.status_url = self.main_status_url
174+
self.error = res.get('error')
174175
self.message = res.get('message')
175176

176177
def _status(self):
177178
response = self.connect.post(self.status_url, dict(task_tokens=self.task_token))
178-
if not response['error']:
179+
status = None
180+
181+
if response['error'] == ERROR_BAD_TOKENS:
182+
raise ValueError('Bad token: ' + str(self.task_token))
183+
184+
if 'statuses' in response and self.task_token in response['statuses']:
185+
status = response['statuses'][self.task_token]
186+
187+
if not status and self.status_url != self.main_status_url:
188+
self.status_url = self.main_status_url
189+
response = self.connect.post(self.status_url, dict(task_tokens=self.task_token))
190+
if 'statuses' in response and self.task_token in response['statuses']:
179191
status = response['statuses'][self.task_token]
180-
if not status:
181-
status = self._status2()
182-
return status
183-
else:
184-
status = self._status2()
185-
return status
186192

193+
if status and 'status_url' in status:
194+
self.status_url = status['status_url']
187195

188-
def _status2(self):
189-
response = self.connect.request('status', {'task_tokens[]': self.task_token})
190-
if not response['error']:
191-
res = response['statuses'][self.task_token]
192-
if res:
193-
return res
194-
else:
195-
return dict(error=True, message='Error getting status')
196-
else:
197-
return response
196+
return status
197+
198+
199+
# def _status2(self):
200+
# response = self.connect.request('status', {'task_tokens[]': self.task_token})
201+
# if not response['error']:
202+
# res = response['statuses'][self.task_token]
203+
# if res:
204+
# return res
205+
# else:
206+
# return dict(error=True, message='Error getting status')
207+
# else:
208+
# return response
198209

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
setup(
1515
name='qencode3',
16-
version='0.9.25',
16+
version='0.9.26',
1717
description="Qencode client library to easily setup a working solution using Python v3.x.",
1818
long_description=long_description,
1919
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)