Skip to content

Commit

Permalink
Merge pull request #3 from tencentyun/master
Browse files Browse the repository at this point in the history
同步master修改到fork的分支
  • Loading branch information
degangliu authored Nov 26, 2021
2 parents d517151 + 96ca0c8 commit 14156ac
Show file tree
Hide file tree
Showing 8 changed files with 520 additions and 188 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ release copy api

## [v1.6.8](https://github.com/tencentyun/cos-python-sdk-v5/compare/v1.6.7...v1.6.8) - 2019-05-14

MD5 check support both unicode and bytes

### Merged

- S3 [`#85`](https://github.com/tencentyun/cos-python-sdk-v5/pull/85)
Expand Down
325 changes: 174 additions & 151 deletions demo/ci_media.py
Original file line number Diff line number Diff line change
@@ -1,151 +1,174 @@
# -*- coding=utf-8
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
from qcloud_cos.cos_comm import CiDetectType

import sys
import logging
import os
import time

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

# https://cloud.tencent.com/document/product/436/48987

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-1253960454'


def ci_get_media_queue():
# 查询媒体队列信息
response = client.ci_get_media_queue(
Bucket=bucket_name
)
print(response)
return response

def ci_create_media_transcode_watermark_jobs():
# 创建转码任务
body = {
'Input':{
'Object':'117374C.mp4'
},
'QueueId': 'pe943803693bd42d1a3105804ddaee525',
'Tag': 'Transcode',
'Operation': {
'Output':{'Bucket':bucket_name, 'Region':region, 'Object':'117374C_output.mp4'},
'TemplateId': 't02db40900dc1c43ad9bdbd8acec6075c5',
# "WatermarkTemplateId": ["", ""],
'Watermark': [
{
'Type':'Text',
'Pos':'TopRight',
'LocMode':'Absolute',
'Dx':'64',
'Dy': '64',
'StartTime':'0',
'EndTime':'1000.5',
'Text': {
'Text': '水印内容',
'FontSize': '90',
'FontType': 'simfang.ttf',
'FontColor': '0xFFEEFF',
'Transparency': '100',
},
},
{
'Type':'Image',
'Pos':'TopLeft',
'LocMode':'Absolute',
'Dx':'100',
'Dy': '100',
'StartTime':'0',
'EndTime':'1000.5',
'Image': {
'Url': 'http://'+bucket_name+".cos."+region+".myqcloud.com/1215shuiyin.jpg",
'Mode': 'Fixed',
'Width': '128',
'Height': '128',
'Transparency': '100',
},
}
]
}
}
# dict中数组类型的标签,都需要特殊处理
lst = [
'<Watermark>',
'<WatermarkTemplateId>',
'</WatermarkTemplateId>',
'</Watermark>'
]
response = client.ci_create_media_jobs(
Bucket=bucket_name,
Jobs=body,
Lst=lst,
ContentType='application/xml'
)
print(response)
return response

def ci_create_media_transcode_jobs():
# 创建转码任务
body = {
'Input':{
'Object':'117374C.mp4'
},
'QueueId': 'pe943803693bd42d1a3105804ddaee525',
'Tag': 'Transcode',
'Operation': {
'Output':{'Bucket':bucket_name, 'Region':region, 'Object':'117374C_output.mp4'},
'TemplateId': 't02db40900dc1c43ad9bdbd8acec6075c5'
}
}
response = client.ci_create_media_jobs(
Bucket=bucket_name,
Jobs=body,
Lst={},
ContentType='application/xml'
)
print(response)
return response

def ci_list_media_transcode_jobs():
# 转码任务
response = client.ci_list_media_jobs(
Bucket=bucket_name,
QueueId='pe943803693bd42d1a3105804ddaee525',
Tag='Transcode',
ContentType='application/xml'
)
print(response)
return response

def ci_get_media_transcode_jobs():
# 转码任务
response = client.ci_get_media_jobs(
Bucket=bucket_name,
JobIDs='j3feb7ccc28fc11eca50b6f68c211dc6c,jb83bcc5a28fb11ecae48a1f29371c5f8',
ContentType='application/xml'
)
print(response)
return response

if __name__ == "__main__":
#ci_get_media_queue()
ci_get_media_transcode_jobs()
#ci_create_media_transcode_jobs()
# -*- coding=utf-8
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
from qcloud_cos.cos_comm import CiDetectType

import sys
import logging
import os
import time

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

# https://cloud.tencent.com/document/product/436/48987

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-1253960454'


def ci_get_media_queue():
# 查询媒体队列信息
response = client.ci_get_media_queue(
Bucket=bucket_name
)
print(response)
return response

def ci_create_media_transcode_watermark_jobs():
# 创建转码任务
body = {
'Input':{
'Object':'117374C.mp4'
},
'QueueId': 'pe943803693bd42d1a3105804ddaee525',
'Tag': 'Transcode',
'Operation': {
'Output':{'Bucket':bucket_name, 'Region':region, 'Object':'117374C_output.mp4'},
'TemplateId': 't02db40900dc1c43ad9bdbd8acec6075c5',
# "WatermarkTemplateId": ["", ""],
'Watermark': [
{
'Type':'Text',
'Pos':'TopRight',
'LocMode':'Absolute',
'Dx':'64',
'Dy': '64',
'StartTime':'0',
'EndTime':'1000.5',
'Text': {
'Text': '水印内容',
'FontSize': '90',
'FontType': 'simfang.ttf',
'FontColor': '0xFFEEFF',
'Transparency': '100',
},
},
{
'Type':'Image',
'Pos':'TopLeft',
'LocMode':'Absolute',
'Dx':'100',
'Dy': '100',
'StartTime':'0',
'EndTime':'1000.5',
'Image': {
'Url': 'http://'+bucket_name+".cos."+region+".myqcloud.com/1215shuiyin.jpg",
'Mode': 'Fixed',
'Width': '128',
'Height': '128',
'Transparency': '100',
},
}
]
}
}
# dict中数组类型的标签,都需要特殊处理
lst = [
'<Watermark>',
'<WatermarkTemplateId>',
'</WatermarkTemplateId>',
'</Watermark>'
]
response = client.ci_create_media_jobs(
Bucket=bucket_name,
Jobs=body,
Lst=lst,
ContentType='application/xml'
)
print(response)
return response

def ci_create_media_transcode_jobs():
# 创建转码任务
body = {
'Input':{
'Object':'117374C.mp4'
},
'QueueId': 'pe943803693bd42d1a3105804ddaee525',
'Tag': 'Transcode',
'Operation': {
'Output':{'Bucket':bucket_name, 'Region':region, 'Object':'117374C_output.mp4'},
'TemplateId': 't02db40900dc1c43ad9bdbd8acec6075c5'
}
}
response = client.ci_create_media_jobs(
Bucket=bucket_name,
Jobs=body,
Lst={},
ContentType='application/xml'
)
print(response)
return response

def ci_list_media_transcode_jobs():
# 转码任务
response = client.ci_list_media_jobs(
Bucket=bucket_name,
QueueId='pe943803693bd42d1a3105804ddaee525',
Tag='Transcode',
ContentType='application/xml'
)
print(response)
return response

def ci_get_media_transcode_jobs():
# 转码任务
response = client.ci_get_media_jobs(
Bucket=bucket_name,
JobIDs='j3feb7ccc28fc11eca50b6f68c211dc6c,jb83bcc5a28fb11ecae48a1f29371c5f8',
ContentType='application/xml'
)
print(response)
return response

def get_media_info():
# 获取媒体信息
response = client.get_media_info(
Bucket=bucket_name,
Key='demo.mp4'
)
print(response)

def get_snapshot():
# 产生同步截图
response = client.get_snapshot(
Bucket=bucket_name,
Key='demo.mp4',
Time='1.5',
Width='480',
Format='png'
)
print(response)
response['Body'].get_stream_to_file('snapshot.jpg')


if __name__ == "__main__":
ci_get_media_queue()
#ci_get_media_transcode_jobs()
#ci_create_media_transcode_jobs()
#get_media_info()
#get_snapshot()
26 changes: 22 additions & 4 deletions qcloud_cos/cos_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,29 @@ def filter_headers(data):
"content-disposition",
"content-encoding",
"content-type",
"expires",
"content-md5",
"content-length",
"host"
"expect",
"expires",
"host",
"if-match",
"if-modified-since",
"if-none-match",
"if-unmodified-since",
"origin",
"range",
"response-cache-control",
"response-content-disposition",
"response-content-encoding",
"response-content-language",
"response-content-type",
"response-expires",
"transfer-encoding",
"versionid",
]
headers = {}
for i in data:
if str.lower(i) in valid_headers or str.lower(i[0]) == "x":
if str.lower(i) in valid_headers or str.lower(i).startswith("x-cos-"):
headers[i] = data[i]
return headers

Expand Down Expand Up @@ -123,12 +138,13 @@ def __call__(self, r):

class CosRtmpAuth(AuthBase):

def __init__(self, conf, bucket=None, channel=None, params={}, expire=10000):
def __init__(self, conf, bucket=None, channel=None, params={}, expire=3600, presign_expire=0):
self._secret_id = conf._secret_id
self._secret_key = conf._secret_key
self._token = conf._token
self._anonymous = conf._anonymous
self._expire = expire
self._presign_expire = presign_expire
self._params = params
if self._token:
self._params['q-token'] = self._token
Expand All @@ -139,6 +155,8 @@ def get_rtmp_sign(self):
canonicalized_param = ''
for k, v in self._params.iteritems():
canonicalized_param += '{key}={value}&'.format(key=k, value=v)
if self._presign_expire >= 60:
canonicalized_param += 'presign={value}'.format(value=self._presign_expire)
canonicalized_param = canonicalized_param.rstrip('&')
rtmp_str = u"{path}\n{params}\n".format(path=self._path, params=canonicalized_param)
logger.debug("rtmp str: " + rtmp_str)
Expand Down
Loading

0 comments on commit 14156ac

Please sign in to comment.