66sys .path .append (os .path .abspath (os .path .join (os .path .dirname (__file__ ), os .path .pardir )))
77import qencode
88import time
9+ import json
910
1011
1112API_KEY = '5a5db6fa5b4c5'
1213TRANSCODING_PROFILEID = '5a5db6fa5b8ac'
1314VIDO_URL = 'https://qa.qencode.com/static/1.mp4'
15+ line = "-" * 80 + "\n "
1416
1517
1618
@@ -22,9 +24,10 @@ def start_encode():
2224 :param api_version: int. not required. default 'v1'
2325 :return: client object
2426 """
27+ print line
2528 client = qencode .client (API_KEY )
2629 if client .error :
27- print 'encoder error:' , client . error , client .message
30+ print 'Error: %s \n ' % client .message
2831 raise SystemExit
2932
3033 """
@@ -35,22 +38,35 @@ def start_encode():
3538 task .duration = 10.0
3639 task .start (TRANSCODING_PROFILEID , VIDO_URL )
3740 if task .error :
38- print 'task error:' , task . error , task .message
41+ print 'Error: %s \n ' % task .message
3942 raise SystemExit
4043
4144 while True :
4245 status = task .status ()
43- print '{0} | {1} | {2} | error: {3}' .format (VIDO_URL ,
44- status .get ('status' ),
45- status .get ('percent' ),
46- status .get ('error' ),
47- status .get ('error_description' ))
46+ try :
47+ print_status (status )
48+ except BaseException as e :
49+ print str (e )
4850 if status ['error' ]:
4951 break
5052 if status ['status' ] == 'completed' :
5153 break
52- time .sleep (15 )
54+ time .sleep (10 )
55+
56+
57+ def print_status (status ):
58+ if not status ['error' ] and status ['status' ] != 'error' :
59+ print "Status: {0} {1}%" .format (status .get ('status' ), status .get ('percent' ))
60+ elif status ['error' ] or status ['status' ] == 'error' :
61+ print "Error: %s\n " % (status .get ('error_description' ))
62+ if status ['status' ] == 'completed' :
63+ print line
64+ for video in status ['videos' ]:
65+ meta = json .loads (video ['meta' ])
66+ print 'Resolution: %s' % meta .get ('resolution' )
67+ print 'Url: %s' % video .get ('url' )
68+ print line
5369
5470
5571if __name__ == '__main__' :
56- start_encode ()
72+ start_encode ()
0 commit comments