查询媒体-使用OSS文件地址

如果您不知道媒体ID(直播走工作流转点播),可以通过媒体的输入地址进行媒体信息的查询,接口为 QueryMediaListByURL

import os
import sys

from typing import List

from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client() -> Mts20140618Client:
        """
        使用AK&SK初始化账号Client
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
        return Mts20140618Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        query_media_list_by_urlrequest = mts_20140618_models.QueryMediaListByURLRequest(
            #需要查询的媒体文件地址
            file_urls='http://example-bucket-****.oss-cn-shanghai.aliyuncs.com/example.mp4',
            #返回结果中是否包含播放信息
            include_play_list=True,
            #返回结果中是否包含截图信息
            include_snapshot_list=True,
            #返回结果中是否包含媒体信息
            include_media_info=True,
            #返回结果中是否包含摘要列表
            include_summary_list=True
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            client.query_media_list_by_urlwith_options(query_media_list_by_urlrequest, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        query_media_list_by_urlrequest = mts_20140618_models.QueryMediaListByURLRequest(
            # 需要查询的媒体文件地址
            file_urls='http://example-bucket-****.oss-cn-shanghai.aliyuncs.com/example.mp4',
            # 返回结果中是否包含播放信息
            include_play_list=True,
            # 返回结果中是否包含截图信息
            include_snapshot_list=True,
            # 返回结果中是否包含媒体信息
            include_media_info=True,
            # 返回结果中是否包含摘要列表
            include_summary_list=True
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.query_media_list_by_urlwith_options_async(query_media_list_by_urlrequest, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])