All Products
Search
Document Center

ApsaraVideo Media Processing:Query a media file based on its OSS URL

Last Updated:Nov 15, 2024

If you use a workflow to create a video-on-demand (VOD) file from a live stream, you cannot obtain the media ID of the live stream. In this case, you can call the QueryMediaListByURL operation to query the live stream by using its Object Storage Service (OSS) URL.

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:
        """
        Use your AccessKey ID and AccessKey secret to initialize a client.
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. ,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. ,
            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(
            # The URL of the media file to be queried.
            file_urls='http://example-bucket-****.oss-cn-shanghai.aliyuncs.com/example.mp4',
            # Specify whether to include playback information in the response.
            include_play_list=True,
            # Specify whether to include snapshot information in the response.
            include_snapshot_list=True,
            # Specify whether to include media information in the response.
            include_media_info=True,
            # Specify whether to include summaries in the response.
            include_summary_list=True
        )
        runtime = util_models.RuntimeOptions()
        try:
            # Write your own code to display the response of the API operation if necessary.
            client.query_media_list_by_urlwith_options(query_media_list_by_urlrequest, runtime)
        except Exception as error:
            # Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            # The error message.
            print(error.message)
            # The URL of the corresponding error diagnostics page.
            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(
            # The URL of the media file to be queried.
            file_urls='http://example-bucket-****.oss-cn-shanghai.aliyuncs.com/example.mp4',
            # Specify whether to include playback information in the response.
            include_play_list=True,
            # Specify whether to include snapshot information in the response.
            include_snapshot_list=True,
            # Specify whether to include media information in the response.
            include_media_info=True,
            # Specify whether to include summaries in the response.
            include_summary_list=True
        )
        runtime = util_models.RuntimeOptions()
        try:
            # Write your own code to display the response of the API operation if necessary.
            await client.query_media_list_by_urlwith_options_async(query_media_list_by_urlrequest, runtime)
        except Exception as error:
            # Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            # The error message.
            print(error.message)
            # The URL of the corresponding error diagnostics page.
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


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