|
@@ -6,7 +6,16 @@ import operator
|
|
|
import base64
|
|
|
import time
|
|
|
from Crypto.Cipher import AES
|
|
|
+import oss2
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+endpoint = 'http://oss-cn-hongkong.aliyuncs.com' # Suppose that your bucket is in the Hangzhou region.
|
|
|
+auth = oss2.Auth('LTAI5t5ZyATP7DL4nMdK51eL', 'WnJqm3jpuP0JUMo3to8wzcVHgIrBAB')
|
|
|
+bucket = oss2.Bucket(auth, endpoint, 'oss-aliyun-hk')
|
|
|
+
|
|
|
+
|
|
|
+# 判断流程能否处理
|
|
|
def support(event):
|
|
|
return True
|
|
|
|
|
@@ -76,18 +85,32 @@ def handle(faas__request_wrap):
|
|
|
|
|
|
process_start_time = time.time()
|
|
|
content = None
|
|
|
+ next_command = None
|
|
|
+
|
|
|
+
|
|
|
if operator.contains(task['resultType'], '[B'):
|
|
|
video_bytes = r.content
|
|
|
if task['tsPart']['key']['method'] != 'NONE':
|
|
|
key_bytes = base64.b64decode(task['tsPart']['key']['key'])
|
|
|
iv_bytes = base64.b64decode(task['tsPart']['key']['iv'])
|
|
|
- video_bytes = Aes_byte(key_bytes, iv_bytes).AES_decrypt(r.content)
|
|
|
- content = 'save to http://itlym.cn/'
|
|
|
- file_path = task['tsPart']['filePath']
|
|
|
- if not os.path.exists(os.path.dirname(file_path)):
|
|
|
- os.makedirs(os.path.dirname(file_path))
|
|
|
- with open(file_path, 'wb') as f:
|
|
|
- f.write(video_bytes)
|
|
|
+ video_bytes = Aes_byte(key_bytes, iv_bytes).AES_decrypt(video_bytes)
|
|
|
+
|
|
|
+ remote_path = 'spider/' + task['progressId'] + '/0000.ts'
|
|
|
+ bucket.put_object(remote_path, video_bytes)
|
|
|
+ content = remote_path
|
|
|
+
|
|
|
+ # file_path = task['tsPart']['filePath']
|
|
|
+ # if not os.path.exists(os.path.dirname(file_path)):
|
|
|
+ # os.makedirs(os.path.dirname(file_path))
|
|
|
+ # with open(file_path, 'wb') as f:
|
|
|
+ # f.write(video_bytes)
|
|
|
+ # content = 'file_path'
|
|
|
+
|
|
|
+ next_command = 'upload_to_oss'
|
|
|
+ next_command = 'upload_to_disk'
|
|
|
+ next_command = 'upload_to_ssh'
|
|
|
+ next_command = 'upload_to_webdav'
|
|
|
+ # todo 路径放上下文
|
|
|
|
|
|
else:
|
|
|
# encoding是从http中的header中的charset字段中提取的编码方式,若header中没有charset字段则默认为ISO - 8859 - 1 编码模式,则无法解析中文,这是乱码的原因
|
|
@@ -111,7 +134,11 @@ def handle(faas__request_wrap):
|
|
|
+ ' req_cost=%.2f' % req_cost + ' process_cost=%.2f' % process_cost)
|
|
|
|
|
|
result = {
|
|
|
- 'content': content
|
|
|
+ 'process_result': {
|
|
|
+ 'spider': context
|
|
|
+ },
|
|
|
+ 'content': content,
|
|
|
+ 'next-command': next_command
|
|
|
}
|
|
|
|
|
|
- return result
|
|
|
+ return content
|