|
- # -*- coding: utf-8 -*-
- # This file is auto-generated, don't edit it. Thanks.
- import sys
-
- from typing import List
- from Tea.core import TeaCore
-
- from alibabacloud_vod20170321.client import Client as Vod20170321Client
- from alibabacloud_tea_openapi import models as open_api_models
- from alibabacloud_darabonba_env.client import Client as EnvClient
- from alibabacloud_vod20170321 import models as vod_20170321_models
- from alibabacloud_tea_console.client import Client as ConsoleClient
- from alibabacloud_tea_util.client import Client as UtilClient
-
-
- class Sample:
- """
- write your Darabonba code here...
- """
- def __init__(self):
- pass
-
- @staticmethod
- def init_vod_client(
- access_key_id: str,
- access_key_secret: str,
- region_id: str,
- ) -> Vod20170321Client:
- """
- 使用AK&SK初始化账号Client
- """
- config = open_api_models.Config()
- config.access_key_id = access_key_id
- config.access_key_secret = access_key_secret
- config.region_id = region_id
- return Vod20170321Client(config)
-
- @staticmethod
- def main(
- args: List[str],
- ) -> None:
- client = Sample.init_vod_client('LTAI5tSJ62TLMUb4SZuf285A', 'MWYynm30filZ7x0HqSHlU3pdLVNeI7', args[0])
- # 1.获取视频上传地址和凭证,并生成视频信息
- create_upload_video_request = vod_20170321_models.CreateUploadVideoRequest(
- title=args[1],
- file_name=args[2]
- )
- create_upload_video_response = client.create_upload_video(create_upload_video_request)
- ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(create_upload_video_response)))
- # 媒体id
- upload_video_id = create_upload_video_response.body.video_id
- ConsoleClient.log(upload_video_id)
- # 如果视频文件过大,上传超时后可以刷新视频凭证,然后继续上传
- refresh_upload_video_request = vod_20170321_models.RefreshUploadVideoRequest(
- video_id=upload_video_id
- )
- refresh_upload_video_reponse = client.refresh_upload_video(refresh_upload_video_request)
- ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(refresh_upload_video_reponse)))
- # # 2.oss视频文件上传,需要用户实现
- # # 3.上传过程中,获取媒体上传详情
- # get_upload_details_request = vod_20170321_models.GetUploadDetailsRequest(
- # media_ids=upload_video_id
- # )
- # get_upload_details_reponse = client.get_upload_details(get_upload_details_request)
- # ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(get_upload_details_reponse)))
- # # 4.媒体上传完成之后,可以获取媒体播放信息进行播放
- # # 4.1 通过播放凭证播放
- # get_play_info_request = vod_20170321_models.GetPlayInfoRequest(
- # video_id=upload_video_id
- # )
- # get_play_info_reponse = client.get_play_info(get_play_info_request)
- # ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(get_play_info_reponse)))
- # # 4.2 通过播放地址播放
- # get_video_play_auth_request = vod_20170321_models.GetVideoPlayAuthRequest(
- # video_id=upload_video_id
- # )
- # get_video_play_auth_reponse = client.get_video_play_auth(get_video_play_auth_request)
- # ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(get_video_play_auth_reponse)))
-
- @staticmethod
- async def main_async(
- args: List[str],
- ) -> None:
- client = Sample.init_vod_client(EnvClient.get_env('ACCESS_KEY_ID'), EnvClient.get_env('ACCESS_KEY_SECRET'), args[0])
- # 1.获取视频上传地址和凭证,并生成视频信息
- create_upload_video_request = vod_20170321_models.CreateUploadVideoRequest(
- title=args[1],
- file_name=args[2]
- )
- create_upload_video_response = await client.create_upload_video_async(create_upload_video_request)
- ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(create_upload_video_response)))
- # 媒体id
- upload_video_id = create_upload_video_response.body.video_id
- ConsoleClient.log(upload_video_id)
- # 如果视频文件过大,上传超时后可以刷新视频凭证,然后继续上传
- refresh_upload_video_request = vod_20170321_models.RefreshUploadVideoRequest(
- video_id=upload_video_id
- )
- refresh_upload_video_reponse = await client.refresh_upload_video_async(refresh_upload_video_request)
- ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(refresh_upload_video_reponse)))
- # 2.oss视频文件上传,需要用户实现
- # 3.上传过程中,获取媒体上传详情
- get_upload_details_request = vod_20170321_models.GetUploadDetailsRequest(
- media_ids=upload_video_id
- )
- get_upload_details_reponse = await client.get_upload_details_async(get_upload_details_request)
- ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(get_upload_details_reponse)))
- # 4.媒体上传完成之后,可以获取媒体播放信息进行播放
- # 4.1 通过播放凭证播放
- get_play_info_request = vod_20170321_models.GetPlayInfoRequest(
- video_id=upload_video_id
- )
- get_play_info_reponse = await client.get_play_info_async(get_play_info_request)
- ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(get_play_info_reponse)))
- # 4.2 通过播放地址播放
- get_video_play_auth_request = vod_20170321_models.GetVideoPlayAuthRequest(
- video_id=upload_video_id
- )
- get_video_play_auth_reponse = await client.get_video_play_auth_async(get_video_play_auth_request)
- ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(get_video_play_auth_reponse)))
-
-
- if __name__ == '__main__':
- Sample.main(['cn-shanghai', "/home/thsw/chenyukun/video/111111.mp4", "/home/thsw/chenyukun/video/111111.mp4"])
|