This commit is contained in:
2024-12-07 15:00:10 +08:00
parent ea5e994a3b
commit fb51d144c0
6 changed files with 116 additions and 35 deletions

View File

@ -8,13 +8,14 @@ import util.system
session = requests.Session()
logger = logging.getLogger(__name__)
def sync_center():
"""
通过接口获取任务
:return: 任务列表
"""
try:
response = session.post(os.getenv('API_ENDPOINT'), json={
response = session.post(os.getenv('API_ENDPOINT') + "/sync", json={
'accessKey': os.getenv('ACCESS_KEY'),
'clientStatus': util.system.get_sys_info()
}, timeout=10)
@ -39,39 +40,59 @@ def get_template_info(template_id):
:type template_id: str
:return: 模板信息
"""
try:
response = session.post('{0}/template/{1}'.format(os.getenv('API_ENDPOINT'), template_id), json={
'accessKey': os.getenv('ACCESS_KEY'),
'clientStatus': util.system.get_sys_info()
}, timeout=10)
except requests.RequestException as e:
logger.error("请求失败!", e)
return None
data = response.json()
remote_template_info = data.get('data', {})
logger.debug("获取模板信息结果:【%s", remote_template_info)
template = {
'id': template_id,
'name': '模板名称',
'description': '板描述',
'scenic_name': remote_template_info.get('scenicName', '景区'),
'name': remote_template_info.get('name', ''),
'video_size': '1920x1080',
'frame_rate': 30,
'overall_duration': 30,
'video_parts': [
{
'source': './template/test_template/1.mp4',
'mute': True,
},
{
'source': 'PLACEHOLDER_CAM_ID',
'mute': True,
'overlays': [
'./template/test_template/2.mov'
],
'luts': [
'./template/test_template/cube.cube'
]
},
{
'source': './template/test_template/3.mp4',
'mute': True,
}
],
'overall_template': {
'source': None,
'mute': False,
'audios': [
'./template/test_template/bgm.acc'
]
},
]
}
return template
def _template_normalizer(template_info):
_template = {}
_placeholder_type = template_info.get('isPlaceholder', -1)
if _placeholder_type == 0:
# 固定视频
_template['source'] = template_info.get('sourceUrl', '')
elif _placeholder_type == 1:
# 占位符
_template['source'] = "PLACEHOLDER_" + template_info.get('sourceUrl', '')
_template['mute'] = template_info.get('mute', True)
else:
_template['source'] = None
_overlays = template_info.get('overlays', '')
if _overlays:
_template['overlays'] = _overlays.split(",")
_audios = template_info.get('audios', '')
if _audios:
_template['audios'] = _audios.split(",")
_luts = template_info.get('luts', '')
if _luts:
_template['luts'] = _luts.split(",")
return _template
# outer template definition
overall_template = _template_normalizer(remote_template_info)
template['overall_template'] = overall_template
# inter template definition
inter_template_list = remote_template_info.get('children', [])
for children_template in inter_template_list:
parts = _template_normalizer(children_template)
template['video_parts'].append(parts)
template['local_path'] = os.path.join(os.getenv('TEMPLATE_DIR'), str(template_id))
return template