|
- # -*- coding: UTF-8 -*-
- import json
- import traceback
- from aliyunsdkcore.client import AcsClient
- from aliyunsdkvod.request.v20170321 import CreateUploadVideoRequest
- from aliyunsdkvod.request.v20170321 import GetPlayInfoRequest
- from vodsdk.AliyunVodUtils import *
- from vodsdk.AliyunVodUploader import AliyunVodUploader
- from vodsdk.UploadVideoRequest import UploadVideoRequest
-
- # # # 填入AccessKey信息
- def init_vod_client(accessKeyId, accessKeySecret):
- regionId = 'cn-shanghai' # 点播服务接入地域
- connectTimeout = 3 # 连接超时,单位为秒
- return AcsClient(accessKeyId, accessKeySecret, regionId, auto_retry=True, max_retry_time=3, timeout=connectTimeout)
- def create_upload_video(clt):
- request = CreateUploadVideoRequest.CreateUploadVideoRequest()
- request.set_Title('dddddd')
- request.set_FileName('/home/thsw/chenyukun/video/111111.mp4')
- request.set_Description('Video Description')
- # //CoverURL示例:http://192.168.0.0/16/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png
- # request.set_CoverURL('<your Cover URL>')
- # request.set_Tags('tag1,tag2')
- # request.set_CateId(0)
-
- # request.set_accept_format('JSON')
- response = json.loads(clt.do_action_with_exception(request))
- return response
-
- try:
- clt = init_vod_client('LTAI5tSJ62TLMUb4SZuf285A', 'MWYynm30filZ7x0HqSHlU3pdLVNeI7')
- uploadInfo = create_upload_video(clt)
- print(json.dumps(uploadInfo, ensure_ascii=False, indent=4))
-
- except Exception as e:
- print(e)
- print(traceback.format_exc())
-
- # 刷新音视频凭证
- # from aliyunsdkvod.request.v20170321 import RefreshUploadVideoRequest
- # def refresh_upload_video(clt, videoId):
- # request = RefreshUploadVideoRequest.RefreshUploadVideoRequest()
- # request.set_VideoId(videoId)
- # request.set_accept_format('JSON')
- # return json.loads(clt.do_action_with_exception(request))
- #
- # try:
- # clt = init_vod_client('LTAI5tSJ62TLMUb4SZuf285A', 'MWYynm30filZ7x0HqSHlU3pdLVNeI7')
- # uploadInfo = refresh_upload_video(clt, "d6c419c33da245758f71e362b5ee8b56")
- # print(json.dumps(uploadInfo, ensure_ascii=False, indent=4))
- #
- # except Exception as e:
- # print(e)
- # print(traceback.format_exc())
- #
- #
- # # 获取播放地址
- # def init_vod_client(accessKeyId, accessKeySecret):
- # regionId = 'cn-shanghai' # 点播服务接入地域
- # connectTimeout = 3 # 连接超时,单位为秒
- # return AcsClient(accessKeyId, accessKeySecret, regionId, auto_retry=True, max_retry_time=3, timeout=connectTimeout)
- # def get_play_info(clt, videoId):
- # request = GetPlayInfoRequest.GetPlayInfoRequest()
- # request.set_accept_format('JSON')
- # request.set_VideoId(videoId)
- # request.set_AuthTimeout(3600*5)
- # response = json.loads(clt.do_action_with_exception(request))
- # return response
- #
- # try:
- # clt = init_vod_client('LTAI5tSJ62TLMUb4SZuf285A', 'MWYynm30filZ7x0HqSHlU3pdLVNeI7')
- # playInfo = get_play_info(clt, uploadInfo["VideoId"])
- # print(json.dumps(playInfo, ensure_ascii=False, indent=4))
- #
- # except Exception as e:
- # print(e)
- # print(traceback.format_exc())
- #
- # # 获取视频播放凭证
- # from aliyunsdkvod.request.v20170321 import GetVideoPlayAuthRequest
- # def get_video_playauth(clt, videoId):
- # request = GetVideoPlayAuthRequest.GetVideoPlayAuthRequest()
- # request.set_accept_format('JSON')
- # request.set_VideoId(videoId)
- # request.set_AuthInfoTimeout(3000)
- # response = json.loads(clt.do_action_with_exception(request))
- # return response
- #
- # try:
- # clt = init_vod_client('LTAI5tSJ62TLMUb4SZuf285A', 'MWYynm30filZ7x0HqSHlU3pdLVNeI7')
- # playAuth = get_video_playauth(clt, uploadInfo["VideoId"])
- # print(json.dumps(playAuth, ensure_ascii=False, indent=4))
- #
- # except Exception as e:
- # print(e)
- # print(traceback.format_exc())
-
-
-
-
-
-
-
- # accessKeyId='LTAI5tSJ62TLMUb4SZuf285A'
- # accessKeySecret='MWYynm30filZ7x0HqSHlU3pdLVNeI7'
- # filePath="/home/thsw/chenyukun/video/111111.mp4"
- # # 测试上传本地音视频
- # def testUploadLocalVideo(accessKeyId, accessKeySecret, filePath, storageLocation=None):
- # try:
- # # 可以指定上传脚本部署的ECS区域。如果ECS区域和视频点播存储区域相同,则自动使用内网上传,上传更快且更省公网流量。
- # # ecsRegionId ="cn-shanghai"
- # # uploader = AliyunVodUploader(accessKeyId, accessKeySecret, ecsRegionId)
- # # 不指定上传脚本部署的ECS区域。
- # uploader = AliyunVodUploader(accessKeyId, accessKeySecret)
- # uploadVideoRequest = UploadVideoRequest(filePath, 'aiOnLineVideo')
- # # 可以设置视频封面,如果是本地或网络图片可使用UploadImageRequest上传图片到视频点播,获取到ImageURL
- # #ImageURL示例:https://example.com/sample-****.jpg
- # #uploadVideoRequest.setCoverURL('<your Image URL>')
- # # 标签
- # # uploadVideoRequest.setTags('taa')
- # if storageLocation:
- # uploadVideoRequest.setStorageLocation(storageLocation)
- # videoId = uploader.uploadLocalVideo(uploadVideoRequest)
- # print("videoId: %s" % (videoId))
- #
- # except AliyunVodException as e:
- # print(e)
- # testUploadLocalVideo(accessKeyId, accessKeySecret, filePath)
|