You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
5.9KB

  1. # -*- coding: utf-8 -*-
  2. # This file is auto-generated, don't edit it. Thanks.
  3. import sys
  4. from typing import List
  5. from Tea.core import TeaCore
  6. from alibabacloud_vod20170321.client import Client as Vod20170321Client
  7. from alibabacloud_tea_openapi import models as open_api_models
  8. from alibabacloud_darabonba_env.client import Client as EnvClient
  9. from alibabacloud_vod20170321 import models as vod_20170321_models
  10. from alibabacloud_tea_console.client import Client as ConsoleClient
  11. from alibabacloud_tea_util.client import Client as UtilClient
  12. class Sample:
  13. """
  14. write your Darabonba code here...
  15. """
  16. def __init__(self):
  17. pass
  18. @staticmethod
  19. def init_vod_client(
  20. access_key_id: str,
  21. access_key_secret: str,
  22. region_id: str,
  23. ) -> Vod20170321Client:
  24. """
  25. 使用AK&SK初始化账号Client
  26. """
  27. config = open_api_models.Config()
  28. config.access_key_id = access_key_id
  29. config.access_key_secret = access_key_secret
  30. config.region_id = region_id
  31. return Vod20170321Client(config)
  32. @staticmethod
  33. def main(
  34. args: List[str],
  35. ) -> None:
  36. client = Sample.init_vod_client('LTAI5tSJ62TLMUb4SZuf285A', 'MWYynm30filZ7x0HqSHlU3pdLVNeI7', args[0])
  37. # 1.获取视频上传地址和凭证,并生成视频信息
  38. create_upload_video_request = vod_20170321_models.CreateUploadVideoRequest(
  39. title=args[1],
  40. file_name=args[2]
  41. )
  42. create_upload_video_response = client.create_upload_video(create_upload_video_request)
  43. ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(create_upload_video_response)))
  44. # 媒体id
  45. upload_video_id = create_upload_video_response.body.video_id
  46. ConsoleClient.log(upload_video_id)
  47. # 如果视频文件过大,上传超时后可以刷新视频凭证,然后继续上传
  48. refresh_upload_video_request = vod_20170321_models.RefreshUploadVideoRequest(
  49. video_id=upload_video_id
  50. )
  51. refresh_upload_video_reponse = client.refresh_upload_video(refresh_upload_video_request)
  52. ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(refresh_upload_video_reponse)))
  53. # # 2.oss视频文件上传,需要用户实现
  54. # # 3.上传过程中,获取媒体上传详情
  55. # get_upload_details_request = vod_20170321_models.GetUploadDetailsRequest(
  56. # media_ids=upload_video_id
  57. # )
  58. # get_upload_details_reponse = client.get_upload_details(get_upload_details_request)
  59. # ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(get_upload_details_reponse)))
  60. # # 4.媒体上传完成之后,可以获取媒体播放信息进行播放
  61. # # 4.1 通过播放凭证播放
  62. # get_play_info_request = vod_20170321_models.GetPlayInfoRequest(
  63. # video_id=upload_video_id
  64. # )
  65. # get_play_info_reponse = client.get_play_info(get_play_info_request)
  66. # ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(get_play_info_reponse)))
  67. # # 4.2 通过播放地址播放
  68. # get_video_play_auth_request = vod_20170321_models.GetVideoPlayAuthRequest(
  69. # video_id=upload_video_id
  70. # )
  71. # get_video_play_auth_reponse = client.get_video_play_auth(get_video_play_auth_request)
  72. # ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(get_video_play_auth_reponse)))
  73. @staticmethod
  74. async def main_async(
  75. args: List[str],
  76. ) -> None:
  77. client = Sample.init_vod_client(EnvClient.get_env('ACCESS_KEY_ID'), EnvClient.get_env('ACCESS_KEY_SECRET'), args[0])
  78. # 1.获取视频上传地址和凭证,并生成视频信息
  79. create_upload_video_request = vod_20170321_models.CreateUploadVideoRequest(
  80. title=args[1],
  81. file_name=args[2]
  82. )
  83. create_upload_video_response = await client.create_upload_video_async(create_upload_video_request)
  84. ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(create_upload_video_response)))
  85. # 媒体id
  86. upload_video_id = create_upload_video_response.body.video_id
  87. ConsoleClient.log(upload_video_id)
  88. # 如果视频文件过大,上传超时后可以刷新视频凭证,然后继续上传
  89. refresh_upload_video_request = vod_20170321_models.RefreshUploadVideoRequest(
  90. video_id=upload_video_id
  91. )
  92. refresh_upload_video_reponse = await client.refresh_upload_video_async(refresh_upload_video_request)
  93. ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(refresh_upload_video_reponse)))
  94. # 2.oss视频文件上传,需要用户实现
  95. # 3.上传过程中,获取媒体上传详情
  96. get_upload_details_request = vod_20170321_models.GetUploadDetailsRequest(
  97. media_ids=upload_video_id
  98. )
  99. get_upload_details_reponse = await client.get_upload_details_async(get_upload_details_request)
  100. ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(get_upload_details_reponse)))
  101. # 4.媒体上传完成之后,可以获取媒体播放信息进行播放
  102. # 4.1 通过播放凭证播放
  103. get_play_info_request = vod_20170321_models.GetPlayInfoRequest(
  104. video_id=upload_video_id
  105. )
  106. get_play_info_reponse = await client.get_play_info_async(get_play_info_request)
  107. ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(get_play_info_reponse)))
  108. # 4.2 通过播放地址播放
  109. get_video_play_auth_request = vod_20170321_models.GetVideoPlayAuthRequest(
  110. video_id=upload_video_id
  111. )
  112. get_video_play_auth_reponse = await client.get_video_play_auth_async(get_video_play_auth_request)
  113. ConsoleClient.log(UtilClient.to_jsonstring(TeaCore.to_map(get_video_play_auth_reponse)))
  114. if __name__ == '__main__':
  115. Sample.main(['cn-shanghai', "/home/thsw/chenyukun/video/111111.mp4", "/home/thsw/chenyukun/video/111111.mp4"])