全部产品
云市场

点播CDN

更新时间:2019-01-31 17:54:31

初始化客户端

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

预热缓存

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

  1. from aliyunsdkvod.request.v20170321 import PreloadVodObjectCachesRequest
  2. def preload_object_caches(clt):
  3. request = PreloadVodObjectCachesRequest.PreloadVodObjectCachesRequest()
  4. objectPath = ['http://test.com/fd.mp4',
  5. 'http://test.com/ld.mp4']
  6. request.set_ObjectPath("\n".join(objectPath))
  7. request.set_accept_format('JSON')
  8. response = json.loads(clt.do_action_with_exception(request))
  9. return response
  10. try:
  11. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  12. res = preload_object_caches(clt)
  13. print(res['PreloadTaskId'])
  14. print(json.dumps(res, ensure_ascii=False, indent=4))
  15. except Exception as e:
  16. print(e)
  17. print(traceback.format_exc())

刷新缓存

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

  1. from aliyunsdkvod.request.v20170321 import RefreshVodObjectCachesRequest
  2. def refresh_object_caches(clt):
  3. request = RefreshVodObjectCachesRequest.RefreshVodObjectCachesRequest()
  4. objectPath = ['http://test.com/fd.mp4',
  5. 'http://test.com/ld.mp4']
  6. request.set_ObjectPath("\n".join(objectPath))
  7. request.set_accept_format('JSON')
  8. response = json.loads(clt.do_action_with_exception(request))
  9. return response
  10. try:
  11. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  12. res = refresh_object_caches(clt)
  13. print(res['RefreshTaskId'])
  14. print(json.dumps(res, ensure_ascii=False, indent=4))
  15. except Exception as e:
  16. print(e)
  17. print(traceback.format_exc())

查询刷新和预热状态

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

  1. from aliyunsdkvod.request.v20170321 import DescribeVodRefreshTasksRequest
  2. def describe_refresh_task(clt):
  3. request = DescribeVodRefreshTasksRequest.DescribeVodRefreshTasksRequest()
  4. request.set_DomainName('test.com')
  5. request.set_ObjectType('preload')
  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. res = describe_refresh_task(clt)
  12. print(res['Tasks']['Task'])
  13. print(json.dumps(res, ensure_ascii=False, indent=4))
  14. except Exception as e:
  15. print(e)
  16. print(traceback.format_exc())

查询刷新预热次数限制和余量

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

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

查询流量数据

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

  1. from aliyunsdkvod.request.v20170321 import DescribeVodDomainTrafficDataRequest
  2. def describe_domain_traffic_data(clt):
  3. request = DescribeVodDomainTrafficDataRequest.DescribeVodDomainTrafficDataRequest()
  4. request.set_DomainName("example.test.com")
  5. request.set_StartTime("2019-01-15T15:59:59Z")
  6. request.set_EndTime("2019-01-20T15:59:58Z")
  7. request.set_accept_format('JSON')
  8. response = json.loads(clt.do_action_with_exception(request))
  9. return response
  10. try:
  11. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  12. res = describe_domain_traffic_data(clt)
  13. print(res['TrafficDataPerInterval']['DataModule'])
  14. print(json.dumps(res, ensure_ascii=False, indent=4))
  15. except Exception as e:
  16. print(e)
  17. print(traceback.format_exc())

查询网络带宽

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

  1. from aliyunsdkvod.request.v20170321 import DescribeVodDomainBpsDataRequest
  2. def describe_domain_bps_data(clt):
  3. request = DescribeVodDomainBpsDataRequest.DescribeVodDomainBpsDataRequest()
  4. request.set_DomainName("example.test.com")
  5. request.set_StartTime("2019-01-15T15:59:59Z")
  6. request.set_EndTime("2019-01-20T15:59:58Z")
  7. request.set_accept_format('JSON')
  8. response = json.loads(clt.do_action_with_exception(request))
  9. return response
  10. try:
  11. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  12. res = describe_domain_bps_data(clt)
  13. print(res['BpsDataPerInterval']['DataModule'])
  14. print(json.dumps(res, ensure_ascii=False, indent=4))
  15. except Exception as e:
  16. print(e)
  17. print(traceback.format_exc())

下载域名日志

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

  1. from aliyunsdkvod.request.v20170321 import DescribeVodDomainLogRequest
  2. def describe_domain_log(clt):
  3. request = DescribeVodDomainLogRequest.DescribeVodDomainLogRequest()
  4. request.set_DomainName("example.test.com")
  5. request.set_StartTime("2019-01-15T15:59:59Z")
  6. request.set_EndTime("2019-01-20T15:59:58Z")
  7. request.set_PageNumber(1)
  8. request.set_PageSize(300)
  9. request.set_accept_format('JSON')
  10. response = json.loads(clt.do_action_with_exception(request))
  11. return response
  12. try:
  13. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  14. res = describe_domain_log(clt)
  15. logDetail = res['DomainLogDetails']['DomainLogDetail'][0]
  16. print("TotalLogCount: %s" % (logDetail['PageInfos']['Total']))
  17. print(logDetail['LogInfos']['LogInfoDetail'])
  18. print(json.dumps(res, ensure_ascii=False, indent=4))
  19. except Exception as e:
  20. print(e)
  21. print(traceback.format_exc())