All Products
Search
Document Center

Media fingerprinting

Last Updated: Jan 04, 2021

This topic provides examples on how to use the API operations of the media fingerprinting module. The API operations are encapsulated in ApsaraVideo VOD SDK for Python. You can call the API operations to submit media fingerprinting jobs, query media fingerprinting jobs, and query media fingerprinting results.

Initialize a client

Before you can use the SDK, initialize a client. For more information, see Initialization.

Submit a media fingerprinting job

You can call the SubmitAIJob operation to submit a media fingerprinting job.

For more information about the request and response parameters of this operation, see SubmitAIJob. Example:

from aliyunsdkvod.request.v20170321 import SubmitAIJobRequest
def submit_ai_job(clt):
    request = SubmitAIJobRequest.SubmitAIJobRequest()
    request.set_MediaId ('<videoId>')# The video ID.
    request.set_Types('AIMediaDNA')  # The AI type. Set the value to AIMediaDNA.

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    job = submit_ai_job(clt)
    print(json.dumps(job, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

Query media fingerprinting jobs

You can call the ListAIJob operation to query media fingerprinting jobs.

For more information about the request and response parameters of this operation, see ListAIJob. Example:

from aliyunsdkvod.request.v20170321 import ListAIJobRequest
def list_ai_job(clt):
    request = ListAIJobRequest.ListAIJobRequest()
    jobIds = ['jobId1', 'jobId2']
    request.set_JobIds(','.join(jobIds))

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    jobs = list_ai_job(clt)
    print(json.dumps(jobs, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

Query media fingerprinting results

You can call the GetMediaDNAResult operation to query media fingerprinting results.

For more information about the request and response parameters of this operation, see GetMediaDNAResult. Example:

from aliyunsdkvod.request.v20170321 import GetMediaDNAResultRequest
def get_media_dna_result(clt):
    request = GetMediaDNAResultRequest.GetMediaDNAResultRequest()
    request.set_MediaId ('<videoId>')# The video ID.

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    dna = get_media_dna_result(clt)
    print(json.dumps(dna, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())