Skip to content

Commit 7042ead

Browse files
author
yuniszhang
committed
Merge branch 'master' of github.com:tencentyun/cos-python-sdk-v5
2 parents 3301558 + 70813e6 commit 7042ead

File tree

5 files changed

+518
-3
lines changed

5 files changed

+518
-3
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
*.pyc
1+
*.pyc

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Qcloud COSv5 SDK
44
.. image:: https://img.shields.io/pypi/v/cos-python-sdk-v5.svg
55
:target: https://pypi.org/search/?q=cos-python-sdk-v5
66
:alt: Pypi
7-
.. image:: https://travis-ci.org/tencentyun/cos-python-sdk-v5.svg?branch=master
8-
:target: https://travis-ci.org/tencentyun/cos-python-sdk-v5
7+
.. image:: https://api.travis-ci.com/tencentyun/cos-python-sdk-v5.svg?branch=master
8+
:target: https://app.travis-ci.com/github/tencentyun/cos-python-sdk-v5
99
:alt: Travis CI
1010

1111
介绍

demo/ci_media.py

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# -*- coding=utf-8
2+
from qcloud_cos import CosConfig
3+
from qcloud_cos import CosS3Client
4+
from qcloud_cos.cos_comm import CiDetectType
5+
6+
import sys
7+
import logging
8+
import os
9+
import time
10+
11+
# 腾讯云COSV5Python SDK, 目前可以支持Python2.6与Python2.7以及Python3.x
12+
13+
# https://cloud.tencent.com/document/product/436/48987
14+
15+
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
16+
17+
# 设置用户属性, 包括secret_id, secret_key, region
18+
# appid已在配置中移除,请在参数Bucket中带上appid。Bucket由bucketname-appid组成
19+
# 这里秘钥是从环境变量取得,如自己测试可改成自己对应的秘钥
20+
secret_id = os.environ["SECRETID"] # 替换为用户的 SecretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
21+
secret_key = os.environ["SECRETKEY"] # 替换为用户的 SecretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
22+
region = 'ap-chongqing' # 替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
23+
# COS支持的所有region列表参见https://www.qcloud.com/document/product/436/6224
24+
token = None # 如果使用永久密钥不需要填入token,如果使用临时密钥需要填入,临时密钥生成和使用指引参见https://cloud.tencent.com/document/product/436/14048
25+
26+
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme='https') # 获取配置对象
27+
client = CosS3Client(config)
28+
29+
30+
bucket_name = 'demo-1253960454'
31+
32+
33+
def ci_get_media_queue():
34+
# 查询媒体队列信息
35+
response = client.ci_get_media_queue(
36+
Bucket=bucket_name
37+
)
38+
print(response)
39+
return response
40+
41+
def ci_create_media_transcode_watermark_jobs():
42+
# 创建转码任务
43+
body = {
44+
'Input':{
45+
'Object':'117374C.mp4'
46+
},
47+
'QueueId': 'pe943803693bd42d1a3105804ddaee525',
48+
'Tag': 'Transcode',
49+
'Operation': {
50+
'Output':{'Bucket':bucket_name, 'Region':region, 'Object':'117374C_output.mp4'},
51+
'TemplateId': 't02db40900dc1c43ad9bdbd8acec6075c5',
52+
# "WatermarkTemplateId": ["", ""],
53+
'Watermark': [
54+
{
55+
'Type':'Text',
56+
'Pos':'TopRight',
57+
'LocMode':'Absolute',
58+
'Dx':'64',
59+
'Dy': '64',
60+
'StartTime':'0',
61+
'EndTime':'1000.5',
62+
'Text': {
63+
'Text': '水印内容',
64+
'FontSize': '90',
65+
'FontType': 'simfang.ttf',
66+
'FontColor': '0xFFEEFF',
67+
'Transparency': '100',
68+
},
69+
},
70+
{
71+
'Type':'Image',
72+
'Pos':'TopLeft',
73+
'LocMode':'Absolute',
74+
'Dx':'100',
75+
'Dy': '100',
76+
'StartTime':'0',
77+
'EndTime':'1000.5',
78+
'Image': {
79+
'Url': 'http://'+bucket_name+".cos."+region+".myqcloud.com/1215shuiyin.jpg",
80+
'Mode': 'Fixed',
81+
'Width': '128',
82+
'Height': '128',
83+
'Transparency': '100',
84+
},
85+
}
86+
]
87+
}
88+
}
89+
# dict中数组类型的标签,都需要特殊处理
90+
lst = [
91+
'<Watermark>',
92+
'<WatermarkTemplateId>',
93+
'</WatermarkTemplateId>',
94+
'</Watermark>'
95+
]
96+
response = client.ci_create_media_jobs(
97+
Bucket=bucket_name,
98+
Jobs=body,
99+
Lst=lst,
100+
ContentType='application/xml'
101+
)
102+
print(response)
103+
return response
104+
105+
def ci_create_media_transcode_jobs():
106+
# 创建转码任务
107+
body = {
108+
'Input':{
109+
'Object':'117374C.mp4'
110+
},
111+
'QueueId': 'pe943803693bd42d1a3105804ddaee525',
112+
'Tag': 'Transcode',
113+
'Operation': {
114+
'Output':{'Bucket':bucket_name, 'Region':region, 'Object':'117374C_output.mp4'},
115+
'TemplateId': 't02db40900dc1c43ad9bdbd8acec6075c5'
116+
}
117+
}
118+
response = client.ci_create_media_jobs(
119+
Bucket=bucket_name,
120+
Jobs=body,
121+
Lst={},
122+
ContentType='application/xml'
123+
)
124+
print(response)
125+
return response
126+
127+
def ci_list_media_transcode_jobs():
128+
# 转码任务
129+
response = client.ci_list_media_jobs(
130+
Bucket=bucket_name,
131+
QueueId='pe943803693bd42d1a3105804ddaee525',
132+
Tag='Transcode',
133+
ContentType='application/xml'
134+
)
135+
print(response)
136+
return response
137+
138+
def ci_get_media_transcode_jobs():
139+
# 转码任务
140+
response = client.ci_get_media_jobs(
141+
Bucket=bucket_name,
142+
JobIDs='j3feb7ccc28fc11eca50b6f68c211dc6c,jb83bcc5a28fb11ecae48a1f29371c5f8',
143+
ContentType='application/xml'
144+
)
145+
print(response)
146+
return response
147+
148+
if __name__ == "__main__":
149+
#ci_get_media_queue()
150+
ci_get_media_transcode_jobs()
151+
#ci_create_media_transcode_jobs()

0 commit comments

Comments
 (0)