全部产品
云市场

视频AI

更新时间:2019-01-24 15:40:00

初始化客户端

使用前请先初始化客户端,参考 init_vod_client 接口。

提交AI作业

接口参数和返回字段请参考 SubmitAIJob

  1. from aliyunsdkvod.request.v20170321 import SubmitAIJobRequest
  2. def submit_ai_job(clt):
  3. request = SubmitAIJobRequest.SubmitAIJobRequest()
  4. request.set_MediaId('<videoId>') # 视频ID
  5. request.set_Types('AIVideoCover') # AI类型,请确保已开通该类型AI服务
  6. request.set_accept_format('JSON')
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. job = submit_ai_job(clt)
  12. print(json.dumps(job, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())

查询AI作业

接口参数和返回字段请参考 ListAIJob

  1. from aliyunsdkvod.request.v20170321 import ListAIJobRequest
  2. def list_ai_job(clt):
  3. request = ListAIJobRequest.ListAIJobRequest()
  4. jobIds = ['jobId1', 'jobId2']
  5. request.set_JobIds(','.join(jobIds))
  6. request.set_accept_format('JSON')
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. jobs = list_ai_job(clt)
  12. print(json.dumps(jobs, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())

添加AI模板

接口参数和返回字段请参考 AddAITemplate

  1. from aliyunsdkvod.request.v20170321 import AddAITemplateRequest
  2. def add_ai_template(clt):
  3. request = AddAITemplateRequest.AddAITemplateRequest()
  4. # 设置模板类型,以智能审核模板为例
  5. request.set_TemplateType('AIMediaAudit')
  6. # 设置模板名称
  7. request.set_TemplateName('My AI Template')
  8. # 设置模板详细配置
  9. auditItem = ['terrorism', 'porn']
  10. auditRange = ['video', 'image-cover', 'text-title']
  11. auditContent = ['screen']
  12. templateConfig = {'AuditItem': auditItem, 'AuditRange': auditRange, 'AuditContent': auditContent,
  13. 'AuditAutoBlock': 'no'}
  14. request.set_TemplateConfig(json.dumps(templateConfig))
  15. request.set_accept_format('JSON')
  16. response = json.loads(clt.do_action_with_exception(request))
  17. return response
  18. try:
  19. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  20. res = add_ai_template(clt)
  21. print(res['TemplateId'])
  22. print(json.dumps(res, ensure_ascii=False, indent=4))
  23. except Exception as e:
  24. print(e)
  25. print(traceback.format_exc())

删除AI模板

接口参数和返回字段请参考 DeleteAITemplate

  1. from aliyunsdkvod.request.v20170321 import DeleteAITemplateRequest
  2. def delete_ai_template(clt):
  3. request = DeleteAITemplateRequest.DeleteAITemplateRequest()
  4. request.set_TemplateId('<TemplateId>')
  5. request.set_accept_format('JSON')
  6. response = json.loads(clt.do_action_with_exception(request))
  7. return response
  8. try:
  9. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  10. res = delete_ai_template(clt)
  11. print(json.dumps(res, ensure_ascii=False, indent=4))
  12. except Exception as e:
  13. print(e)
  14. print(traceback.format_exc())

修改AI模板

接口参数和返回字段请参考 UpdateAITemplate

  1. from aliyunsdkvod.request.v20170321 import UpdateAITemplateRequest
  2. def update_ai_template(clt):
  3. request = UpdateAITemplateRequest.UpdateAITemplateRequest()
  4. # 设置模板ID
  5. request.set_TemplateId('<TemplateId>')
  6. # 设置模板名称
  7. request.set_TemplateName('New AI Template Name')
  8. # 设置模板详细配置
  9. auditItem = ['terrorism', 'porn']
  10. auditRange = ['video', 'image-cover']
  11. auditContent = ['screen']
  12. templateConfig = {'AuditItem': auditItem, 'AuditRange': auditRange, 'AuditContent': auditContent,
  13. 'AuditAutoBlock': 'yes'}
  14. request.set_TemplateConfig(json.dumps(templateConfig))
  15. request.set_accept_format('JSON')
  16. response = json.loads(clt.do_action_with_exception(request))
  17. return response
  18. try:
  19. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  20. res = update_ai_template(clt)
  21. print(json.dumps(res, ensure_ascii=False, indent=4))
  22. except Exception as e:
  23. print(e)
  24. print(traceback.format_exc())

查询AI模板

接口参数和返回字段请参考 GetAITemplate

  1. from aliyunsdkvod.request.v20170321 import GetAITemplateRequest
  2. def get_ai_template(clt):
  3. request = GetAITemplateRequest.GetAITemplateRequest()
  4. request.set_TemplateId('<TemplateId>')
  5. request.set_accept_format('JSON')
  6. response = json.loads(clt.do_action_with_exception(request))
  7. return response
  8. try:
  9. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  10. template = get_ai_template(clt)
  11. print(template['TemplateInfo'])
  12. except Exception as e:
  13. print(e)
  14. print(traceback.format_exc())

查询AI模板列表

接口参数和返回字段请参考 ListAITemplate

  1. from aliyunsdkvod.request.v20170321 import ListAITemplateRequest
  2. def list_ai_template(clt):
  3. request = ListAITemplateRequest.ListAITemplateRequest()
  4. request.set_TemplateType('AIMediaAudit')
  5. request.set_accept_format('JSON')
  6. response = json.loads(clt.do_action_with_exception(request))
  7. return response
  8. try:
  9. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  10. templates = list_ai_template(clt)
  11. print(templates['TemplateInfoList'])
  12. except Exception as e:
  13. print(e)
  14. print(traceback.format_exc())

设置默认AI模板

接口参数和返回字段请参考 SetDefaultAITemplate

  1. from aliyunsdkvod.request.v20170321 import SetDefaultAITemplateRequest
  2. def set_default_ai_template(clt):
  3. request = SetDefaultAITemplateRequest.SetDefaultAITemplateRequest()
  4. request.set_TemplateId('<TemplateId>')
  5. request.set_accept_format('JSON')
  6. response = json.loads(clt.do_action_with_exception(request))
  7. return response
  8. try:
  9. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  10. res = set_default_ai_template(clt)
  11. print(json.dumps(res, ensure_ascii=False, indent=4))
  12. except Exception as e:
  13. print(e)
  14. print(traceback.format_exc())

查询默认AI模板

接口参数和返回字段请参考 GetDefaultAITemplate

  1. from aliyunsdkvod.request.v20170321 import GetDefaultAITemplateRequest
  2. def get_default_ai_template(clt):
  3. request = GetDefaultAITemplateRequest.GetDefaultAITemplateRequest()
  4. request.set_TemplateType('AIMediaAudit')
  5. request.set_accept_format('JSON')
  6. response = json.loads(clt.do_action_with_exception(request))
  7. return response
  8. try:
  9. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  10. template = get_default_ai_template(clt)
  11. print(template['TemplateInfo'])
  12. print(json.dumps(template, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())