Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
584 changes: 584 additions & 0 deletions demo/ai_recognition_demo.py

Large diffs are not rendered by default.

33 changes: 0 additions & 33 deletions demo/ci_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,39 +78,6 @@ def ci_get_ai_bucket():
return response


def ci_get_ai_queue():
# 查询ai处理队列信息
response = client.ci_get_ai_queue(
Bucket=bucket_name,
)
print(response)
return response


def ci_put_ai_queue():
# 更新ai队列信息
body = {
'Name': 'ai-queue',
'QueueID': 'pa2c2afbe68xxxxxxxxxxxxxxxxxxxxxx',
'State': 'Active',
'NotifyConfig': {
'Type': 'Url',
'Url': 'http://www.demo.callback.com',
'Event': 'TaskFinish',
'State': 'On',
'ResultFormat': 'JSON',
}
}
response = client.ci_update_ai_queue(
Bucket=bucket_name,
QueueId='pa2c2afbe68c44xxxxxxxxxxxxxxxxxxxx',
Request=body,
ContentType='application/xml'
)
print(response)
return response


def ci_get_media_pic_queue():
# 查询图片处理队列信息
response = client.ci_get_media_pic_queue(
Expand Down
27 changes: 25 additions & 2 deletions demo/ci_speech_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
bucket_name = 'examplebucket-1250000000'


def ci_open_asr_bucket():
# 开通智能语音服务
response, data = client.ci_open_asr_bucket(
Bucket=bucket_name
)
print(response)
print(data)
return response, data


def ci_get_asr_bucket():
# 查询语音识别开通状态
response = client.ci_get_asr_bucket(
Expand All @@ -39,6 +49,16 @@ def ci_get_asr_bucket():
return response


def ci_close_asr_bucket():
# 关闭智能语音服务
response, data = client.ci_close_asr_bucket(
Bucket=bucket_name
)
print(response)
print(data)
return response, data


def ci_get_asr_queue():
# 查询语音识别队列信息
response = client.ci_get_asr_queue(
Expand Down Expand Up @@ -166,10 +186,13 @@ def ci_delete_asr_template():
# ci_get_asr_bucket()
# ci_get_asr_queue()
# ci_put_asr_queue()
ci_create_asr_template()
# ci_create_asr_template()
# ci_get_asr_template()
# ci_update_asr_template()
# ci_delete_asr_template()
ci_create_asr_jobs()
# ci_create_asr_jobs()
# ci_get_asr_jobs()
# ci_list_asr_jobs()
# ci_close_asr_bucket()
# ci_open_asr_bucket()
ci_get_asr_bucket()
91 changes: 90 additions & 1 deletion demo/ci_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -1730,10 +1730,95 @@ def ci_update_smart_cover_template():
return response


noise_reduction_template_config = {
# 固定值:NoiseReduction
# 是否必传:是
'Tag': "NoiseReduction",
# 模板名称,仅支持中文、英文、数字、_、-和*,长度不超过 64。
# 是否必传:是
'Name': "noise_reduction_test",
# 降噪参数
# 是否必传:是
'NoiseReduction': {
# 封装格式,支持 mp3、m4a、wav
# 是否必传:否
'Format': "wav",
# 采样率单位:Hz可选 8000、12000、16000、24000、32000、44100、48000
# 是否必传:否
'Samplerate': "8000",
},
}


def ci_create_noise_reduction_template():
# 创建音频降噪模板
response = client.ci_create_template(
Bucket=bucket_name,
Template=noise_reduction_template_config,
)
print(response)
return response


def ci_update_noise_reduction_template():
# 更新音频降噪模板
response = client.ci_update_template(
Bucket=bucket_name,
TemplateId='t1ec6c1xxxxxxxxxxxxxxxxxxxxxx',
Template=noise_reduction_template_config,
)
print(response)
return response


video_target_rec_template_config = {
# 模板类型:VideoTargetRec
# 是否必传:是
'Tag': "VideoTargetRec",
# 模板名称,仅支持中文、英文、数字、_、-和*,长度不超过 64
# 是否必传:是
'Name': "video_target_rec_test",
# 视频目标检测 参数
# 是否必传:是
'VideoTargetRec': {
# 是否开启人体检测,取值 true/false
# 是否必传:否
'Body': "true",
# 是否开启宠物检测,取值 true/false
# 是否必传:否
'Pet': "true",
# 是否开启车辆检测,取值 true/false
# 是否必传:否
'Car': "false",
},
}


def ci_create_video_target_template():
# 创建视频目标检测模板
response = client.ci_create_template(
Bucket=bucket_name,
Template=video_target_rec_template_config,
)
print(response)
return response


def ci_update_video_target_template():
# 更新视频目标检测模板
response = client.ci_update_template(
Bucket=bucket_name,
TemplateId='t17de5xxxxxxxxxxxxxxxxxxxxxxx',
Template=video_target_rec_template_config,
)
print(response)
return response


if __name__ == "__main__":
# ci_create_snapshot_template()
# ci_update_snapshot_template()
ci_create_transcode_template()
# ci_create_transcode_template()
# ci_update_transcode_template()
# ci_create_high_speed_hd_template()
# ci_update_high_speed_hd_template()
Expand All @@ -1756,4 +1841,8 @@ def ci_update_smart_cover_template():
# ci_update_tts_template()
# ci_create_smart_cover_template()
# ci_update_smart_cover_template()
# ci_create_noise_reduction_template()
# ci_update_noise_reduction_template()
# ci_create_video_target_template()
ci_update_video_target_template()

100 changes: 100 additions & 0 deletions demo/hls_decrypt_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# -*- coding=utf-8
import base64
import jwt
from urllib.parse import quote, quote_plus
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
from datetime import datetime, timedelta

import sys
import logging
import os

# 腾讯云COSV5Python SDK, 目前可以支持Python2.6与Python2.7以及Python3.x

# 媒体处理相关API请参考 https://cloud.tencent.com/document/product/460/84790

logging.basicConfig(level=logging.INFO, stream=sys.stdout)

# 设置用户属性, 包括secret_id, secret_key, region
# appid已在配置中移除,请在参数Bucket中带上appid。Bucket由bucketname-appid组成
# 这里秘钥是从环境变量取得,如自己测试可改成自己对应的秘钥
secret_id = os.environ["SECRETID"] # 替换为用户的 SecretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
secret_key = os.environ["SECRETKEY"] # 替换为用户的 SecretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
region = 'ap-chongqing' # 替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
# COS支持的所有region列表参见https://www.qcloud.com/document/product/436/6224
token = None # 如果使用永久密钥不需要填入token,如果使用临时密钥需要填入,临时密钥生成和使用指引参见https://cloud.tencent.com/document/product/436/14048

config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme='https') # 获取配置对象
client = CosS3Client(config)


bucket_name = 'demo-1250000000'
play_key = 'play_key'
object_name = 'test.m3u8'


def generate_token():
now = datetime.now()
expire_time = now + timedelta(minutes=30)
path_encoded = quote(object_name)
object = quote_plus(path_encoded)

headers = {
# 加密的算法,固定为 HS256
"alg": "HS256",
# 类型,固定为 JWT
"typ": "JWT"
}
token_info = {
# 固定为 CosCiToken, 必填参数
'Type': 'CosCiToken',
# app id,必填参数
'AppId': '1250000000',
# 播放文件所在的BucketId, 必填参数
'BucketId': bucket_name,
# 播放文件名
'Object': object,
# 固定为client,必填参数
'Issuer': 'client',
# token颁发时间戳,必填参数
'IssuedTimeStamp': now.timestamp(),
# token过期时间戳,非必填参数,默认1天过期
'ExpireTimeStamp': expire_time.timestamp(),
# token使用次数限制,非必填参数,默认限制100000次
'UsageLimit': 20,
# 是否加密解密密钥(播放时解密ts视频流的密钥),1表示对解密密钥加密,0表示不对解密密钥加密。
'ProtectContentKey': 1,
}
if token_info['ProtectContentKey'] == 1:
public_key = """-----BEGIN PUBLIC KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxBgQCj9GNktf2yA0Mp8aCzxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx54Jl4NVNewBLPZq1WFxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxKpSCdl9hHxFZ732ixxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxx
-----END PUBLIC KEY-----"""
base64_public_key = base64.urlsafe_b64encode(public_key.encode('utf-8')).decode('utf-8')
token_info.update({
# 保护模式,填写为 rsa1024 ,则表示使用 RSA 非对称加密的方式保护,公私钥对长度为 1024 bit
'ProtectSchema': "rsa1024",
# 公钥。1024 bit 的 RSA 公钥,需使用 Base64 进行编码
'PublicKey': base64_public_key,
})
return jwt.encode(token_info, play_key, algorithm="HS256", headers=headers)


def get_url():
url = client.get_presigned_download_url(
Bucket=bucket_name, # 存储桶名称
Key="/" + object_name,
Expired=3600, # 预签名超时时间
)
if token is not None:
url = url + "&x-cos-security-token=" + token
url = url + "&tokenType=JwtToken&expires=3600&ci-process=pm3u8&token=" + generate_token()
return url


if __name__ == '__main__':
print(generate_token())
print(get_url())
18 changes: 9 additions & 9 deletions demo/meta_insight_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def ci_describe_dataset():
# 查询数据集

response, data = client.ci_describe_dataset(
Datasetname="数据集名称",
DatasetName="数据集名称",
Statistics="",
ContentType="application/json"
)
Expand All @@ -261,7 +261,7 @@ def ci_describe_dataset_binding():
# 查询数据集与存储桶的绑定关系

response, data = client.ci_describe_dataset_binding(
Datasetname="数据集名称",
DatasetName="数据集名称",
Uri="uri",
ContentType="application/json"
)
Expand All @@ -274,9 +274,9 @@ def ci_describe_dataset_bindings():
# 查询绑定关系列表

response, data = client.ci_describe_dataset_bindings(
Datasetname="数据集名称",
Maxresults=100,
Nexttoken="下一页",
DatasetName="数据集名称",
MaxResults=100,
NextToken="下一页",
ContentType="application/json"
)
print(response)
Expand All @@ -288,8 +288,8 @@ def ci_describe_datasets():
# 列出数据集

response, data = client.ci_describe_datasets(
Maxresults=100,
Nexttoken="下一页",
MaxResults=100,
NextToken="下一页",
Prefix="数据集前缀",
ContentType="application/json"
)
Expand All @@ -302,7 +302,7 @@ def ci_describe_file_meta_index():
# 查询元数据索引

response, data = client.ci_describe_file_meta_index(
Datasetname="数据集名称",
DatasetName="数据集名称",
Uri="cos://facesearch-12500000000",
ContentType="application/json"
)
Expand Down Expand Up @@ -369,7 +369,7 @@ def ci_update_file_meta_index():
'DatasetName': "test001",
# 用于建立索引的文件信息。
# 是否必传:是
'UpdateMetaFile': {
'File': {
# 自定义ID。该文件索引到数据集后,作为该行元数据的属性存储,用于和您的业务系统进行关联、对应。您可以根据业务需求传入该值,例如将某个URI关联到您系统内的某个ID。推荐传入全局唯一的值。在查询时,该字段支持前缀查询和排序,详情请见[字段和操作符的支持列表](https://cloud.tencent.com/document/product/460/106154)。
# 是否必传:否
'CustomId': "001",
Expand Down
1 change: 1 addition & 0 deletions qcloud_cos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .cos_auth import CosS3Auth
from .cos_comm import get_date
from .meta_insight import MetaInsightClient
from .ai_recognition import AIRecognitionClient

import logging

Expand Down
Loading