|
|
@ -1,29 +1,13 @@
|
|
|
|
|
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
import base64
|
|
|
|
import base64
|
|
|
|
|
|
|
|
from log import logger
|
|
|
|
|
|
|
|
|
|
|
|
with open('cfg.json', 'r') as f:
|
|
|
|
with open('cfg.json', 'r') as f:
|
|
|
|
cfg_dict = json.load(f)
|
|
|
|
cfg_dict = json.load(f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def send_result(file_path, url):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
发送视频
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
|
|
file_path:
|
|
|
|
|
|
|
|
url:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
username = cfg_dict['username']
|
|
|
|
|
|
|
|
password = cfg_dict['password']
|
|
|
|
|
|
|
|
headers = {'Content-type': 'video/mp4', 'Authorization': 'Basic ' + f'<{username}>:<{password}>'}
|
|
|
|
|
|
|
|
files = {'file': open(file_path, 'rb')}
|
|
|
|
|
|
|
|
response = requests.post(url, files=files, headers=headers)
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def encode_info(info):
|
|
|
|
def encode_info(info):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
加密
|
|
|
|
加密
|
|
|
@ -38,3 +22,24 @@ def decode_info(encoded_info):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
info = base64.b64decode(encoded_info.encode('utf-8')).decode('utf-8')
|
|
|
|
info = base64.b64decode(encoded_info.encode('utf-8')).decode('utf-8')
|
|
|
|
return info
|
|
|
|
return info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SendResult:
|
|
|
|
|
|
|
|
def __init__(self, url):
|
|
|
|
|
|
|
|
self.url = url
|
|
|
|
|
|
|
|
self.username = decode_info(cfg_dict['username'])
|
|
|
|
|
|
|
|
self.password = decode_info(cfg_dict['password'])
|
|
|
|
|
|
|
|
self.headers = {'Content-type': 'video/mp4', 'Authorization': 'Basic ' + f'<{self.username}>:<{self.password}>'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def post(self, file_path):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
response = requests.post(self.url, files=file_path, headers=self.headers)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
logger.error(f'post请求错误:{e}')
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
send_result_obj = SendResult()
|
|
|
|
|
|
|
|
send_result_obj.post('test.mp4v')
|
|
|
|