Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

128 rindas
5.2KB

  1. # -*- coding: UTF-8 -*-
  2. import json
  3. import traceback
  4. from aliyunsdkcore.client import AcsClient
  5. from aliyunsdkvod.request.v20170321 import CreateUploadVideoRequest
  6. from aliyunsdkvod.request.v20170321 import GetPlayInfoRequest
  7. from voduploadsdk.AliyunVodUtils import *
  8. from voduploadsdk.AliyunVodUploader import AliyunVodUploader
  9. from voduploadsdk.UploadVideoRequest import UploadVideoRequest
  10. # # # 填入AccessKey信息
  11. def init_vod_client(accessKeyId, accessKeySecret):
  12. regionId = 'cn-shanghai' # 点播服务接入地域
  13. connectTimeout = 3 # 连接超时,单位为秒
  14. return AcsClient(accessKeyId, accessKeySecret, regionId, auto_retry=True, max_retry_time=3, timeout=connectTimeout)
  15. def create_upload_video(clt):
  16. request = CreateUploadVideoRequest.CreateUploadVideoRequest()
  17. request.set_Title('dddddd')
  18. request.set_FileName('/home/thsw/chenyukun/video/111111.mp4')
  19. request.set_Description('Video Description')
  20. # //CoverURL示例:http://192.168.0.0/16/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png
  21. # request.set_CoverURL('<your Cover URL>')
  22. # request.set_Tags('tag1,tag2')
  23. # request.set_CateId(0)
  24. # request.set_accept_format('JSON')
  25. response = json.loads(clt.do_action_with_exception(request))
  26. return response
  27. try:
  28. clt = init_vod_client('LTAI5tSJ62TLMUb4SZuf285A', 'MWYynm30filZ7x0HqSHlU3pdLVNeI7')
  29. uploadInfo = create_upload_video(clt)
  30. print(json.dumps(uploadInfo, ensure_ascii=False, indent=4))
  31. except Exception as e:
  32. print(e)
  33. print(traceback.format_exc())
  34. # 刷新音视频凭证
  35. # from aliyunsdkvod.request.v20170321 import RefreshUploadVideoRequest
  36. # def refresh_upload_video(clt, videoId):
  37. # request = RefreshUploadVideoRequest.RefreshUploadVideoRequest()
  38. # request.set_VideoId(videoId)
  39. # request.set_accept_format('JSON')
  40. # return json.loads(clt.do_action_with_exception(request))
  41. #
  42. # try:
  43. # clt = init_vod_client('LTAI5tSJ62TLMUb4SZuf285A', 'MWYynm30filZ7x0HqSHlU3pdLVNeI7')
  44. # uploadInfo = refresh_upload_video(clt, "d6c419c33da245758f71e362b5ee8b56")
  45. # print(json.dumps(uploadInfo, ensure_ascii=False, indent=4))
  46. #
  47. # except Exception as e:
  48. # print(e)
  49. # print(traceback.format_exc())
  50. #
  51. #
  52. # # 获取播放地址
  53. # def init_vod_client(accessKeyId, accessKeySecret):
  54. # regionId = 'cn-shanghai' # 点播服务接入地域
  55. # connectTimeout = 3 # 连接超时,单位为秒
  56. # return AcsClient(accessKeyId, accessKeySecret, regionId, auto_retry=True, max_retry_time=3, timeout=connectTimeout)
  57. # def get_play_info(clt, videoId):
  58. # request = GetPlayInfoRequest.GetPlayInfoRequest()
  59. # request.set_accept_format('JSON')
  60. # request.set_VideoId(videoId)
  61. # request.set_AuthTimeout(3600*5)
  62. # response = json.loads(clt.do_action_with_exception(request))
  63. # return response
  64. #
  65. # try:
  66. # clt = init_vod_client('LTAI5tSJ62TLMUb4SZuf285A', 'MWYynm30filZ7x0HqSHlU3pdLVNeI7')
  67. # playInfo = get_play_info(clt, uploadInfo["VideoId"])
  68. # print(json.dumps(playInfo, ensure_ascii=False, indent=4))
  69. #
  70. # except Exception as e:
  71. # print(e)
  72. # print(traceback.format_exc())
  73. #
  74. # # 获取视频播放凭证
  75. # from aliyunsdkvod.request.v20170321 import GetVideoPlayAuthRequest
  76. # def get_video_playauth(clt, videoId):
  77. # request = GetVideoPlayAuthRequest.GetVideoPlayAuthRequest()
  78. # request.set_accept_format('JSON')
  79. # request.set_VideoId(videoId)
  80. # request.set_AuthInfoTimeout(3000)
  81. # response = json.loads(clt.do_action_with_exception(request))
  82. # return response
  83. #
  84. # try:
  85. # clt = init_vod_client('LTAI5tSJ62TLMUb4SZuf285A', 'MWYynm30filZ7x0HqSHlU3pdLVNeI7')
  86. # playAuth = get_video_playauth(clt, uploadInfo["VideoId"])
  87. # print(json.dumps(playAuth, ensure_ascii=False, indent=4))
  88. #
  89. # except Exception as e:
  90. # print(e)
  91. # print(traceback.format_exc())
  92. # accessKeyId='LTAI5tSJ62TLMUb4SZuf285A'
  93. # accessKeySecret='MWYynm30filZ7x0HqSHlU3pdLVNeI7'
  94. # filePath="/home/thsw/chenyukun/video/111111.mp4"
  95. # # 测试上传本地音视频
  96. # def testUploadLocalVideo(accessKeyId, accessKeySecret, filePath, storageLocation=None):
  97. # try:
  98. # # 可以指定上传脚本部署的ECS区域。如果ECS区域和视频点播存储区域相同,则自动使用内网上传,上传更快且更省公网流量。
  99. # # ecsRegionId ="cn-shanghai"
  100. # # uploader = AliyunVodUploader(accessKeyId, accessKeySecret, ecsRegionId)
  101. # # 不指定上传脚本部署的ECS区域。
  102. # uploader = AliyunVodUploader(accessKeyId, accessKeySecret)
  103. # uploadVideoRequest = UploadVideoRequest(filePath, 'aiOnLineVideo')
  104. # # 可以设置视频封面,如果是本地或网络图片可使用UploadImageRequest上传图片到视频点播,获取到ImageURL
  105. # #ImageURL示例:https://example.com/sample-****.jpg
  106. # #uploadVideoRequest.setCoverURL('<your Image URL>')
  107. # # 标签
  108. # # uploadVideoRequest.setTags('taa')
  109. # if storageLocation:
  110. # uploadVideoRequest.setStorageLocation(storageLocation)
  111. # videoId = uploader.uploadLocalVideo(uploadVideoRequest)
  112. # print("videoId: %s" % (videoId))
  113. #
  114. # except AliyunVodException as e:
  115. # print(e)
  116. # testUploadLocalVideo(accessKeyId, accessKeySecret, filePath)