Skip to content

Commit 37c1c9c

Browse files
authored
Merge pull request #248 from bug-is-zhang/master
Update ci sdk and demo
2 parents d6e5807 + 406cfae commit 37c1c9c

File tree

2 files changed

+216
-3
lines changed

2 files changed

+216
-3
lines changed

demo/ci_media.py

Lines changed: 115 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
client = CosS3Client(config)
2828

2929

30-
bucket_name = 'demo-1253960454'
30+
bucket_name = 'demo-1250000000'
3131

3232

3333
def ci_get_media_bucket():
@@ -1051,7 +1051,7 @@ def ci_create_segment_video_body_jobs():
10511051
# Foreground(输出前景视频)、
10521052
# Combination(输出抠图后的前景与自定义背景合成后的视频)
10531053
'Mode': 'Mask',
1054-
# 非必选 抠图模式,当前支持 HumanSeg、GreenScreenSeg。 默认值 HumanSeg
1054+
# 非必选 抠图模式,当前支持 HumanSeg(人像抠图)、GreenScreenSeg(绿幕抠图)、SolidColorSeg(纯色背景抠图)。 默认值 HumanSeg
10551055
# 'SegmentType': 'GreenScreenSeg',
10561056
# 非必选 mode为Foreground时可指定此参数,背景颜色为蓝色,取值范围为0-255, 默认值为0
10571057
# 'BackgroundBlue': '255',
@@ -1062,7 +1062,13 @@ def ci_create_segment_video_body_jobs():
10621062
# 非必选 mode为Combination时,必需指定此参数,传入背景文件,背景文件需与object在同存储桶下
10631063
# 'BackgroundLogoUrl': 'http://testpic-1253960454.cos.ap-chongqing.myqcloud.com'
10641064
# 非必选 阈值 可以调整alpha通道的边缘,调整抠图的边缘位置 取值范围为0-255, 默认值为0
1065-
# 'BinaryThreshold': '200'
1065+
# 'BinaryThreshold': '200',
1066+
# 非必选 纯色背景抠图的背景色(红), 当 SegmentType 为 SolidColorSeg 生效,取值范围为0-255,默认值为 0
1067+
# 'RemoveRed': '200',
1068+
# 非必选 纯色背景抠图的背景色(绿), 当 SegmentType 为 SolidColorSeg 生效,取值范围为0-255,默认值为 0
1069+
# 'RemoveGreen': '200',
1070+
# 非必选 纯色背景抠图的背景色(蓝), 当 SegmentType 为 SolidColorSeg 生效,取值范围为0-255,默认值为 0
1071+
# 'RemoveBlue': '200'
10661072
},
10671073
# 输出配置
10681074
'Output': {
@@ -1494,6 +1500,112 @@ def ci_create_image_inspect_jobs():
14941500
return response
14951501

14961502

1503+
def ci_create_image_inspect_batch_jobs():
1504+
# 创建异常图片检测批量处理任务
1505+
body = {
1506+
# 批量任务名称
1507+
# 存量触发任务名称,支持中文、英文、数字、—和_,长度限制128字符
1508+
# 必选
1509+
'Name': 'image-inspect-auto-move-batch-process',
1510+
# 批量处理任务类型:
1511+
# 支持 Job(独立异步任务) Workflow(工作流)
1512+
'Type': 'Job',
1513+
# 待操作的对象信息
1514+
# 必传参数
1515+
'Input': {
1516+
# 'UrlFile': 'https://ziroom-tech-1255976291.cos.ap-beijing.myqcloud.com/ci_ziroom-tech_scankey_url.txt',
1517+
# Object 前缀
1518+
'Prefix': '/',
1519+
},
1520+
# 操作规则
1521+
# 必传参数
1522+
'Operation': {
1523+
# 按对象的last modify时间过滤的触发范围,若传入此参数,则当前任务仅处理指定事件范围内的对象
1524+
# 非必传
1525+
# 创建的任务类型,此处固定值为ImageInspect
1526+
# 必传参数
1527+
'Tag': 'ImageInspect',
1528+
# 任务参数集合
1529+
# 必传参数
1530+
'JobParam': {
1531+
# 异常图片检测配置
1532+
# 非必选
1533+
'ImageInspect': {
1534+
# 是否开启检测到异常图片检测后自动对图片进行处理的动作,false/true,非必选,默认false
1535+
'AutoProcess': 'true',
1536+
# 在检测到为异常图片后的处理动作,有效值为:
1537+
# BackupObject:移动图片到固定目录下,目录名为abnormal_images_backup/,由后台自动创建
1538+
# SwitchObjectToPrivate:将图片权限设置为私有
1539+
# DeleteObject:删除图片
1540+
# 非必选参数,默认值为BackupObject
1541+
'ProcessType': 'BackupObject'
1542+
},
1543+
},
1544+
1545+
},
1546+
1547+
}
1548+
response = client.ci_create_inventory_trigger_jobs(
1549+
Bucket=bucket_name,
1550+
JobBody=body,
1551+
ContentType='application/xml'
1552+
)
1553+
print(response)
1554+
return response
1555+
1556+
1557+
def ci_create_image_inspect_workflow_batch_jobs():
1558+
# 创建异常图片检测工作流批量处理任务
1559+
1560+
body = {
1561+
# 批量任务名称
1562+
# 存量触发任务名称,支持中文、英文、数字、—和_,长度限制128字符
1563+
# 必选
1564+
'Name': 'image-inspect-auto-move-batch-process',
1565+
# 批量处理任务类型:
1566+
# 支持 Job(独立异步任务) Workflow(工作流)
1567+
'Type': 'Workflow',
1568+
# 待操作的对象信息
1569+
# 必传参数
1570+
'Input': {
1571+
# 'UrlFile': 'https://ziroom-tech-1255976291.cos.ap-beijing.myqcloud.com/ci_ziroom-tech_scankey_url.txt',
1572+
# Object 前缀
1573+
'Prefix': '/',
1574+
},
1575+
# 操作规则
1576+
# 必传参数
1577+
'Operation': {
1578+
# 按对象的last modify时间过滤的触发范围,若传入此参数,则当前任务仅处理指定事件范围内的对象
1579+
# 非必传
1580+
'TimeInterval': {
1581+
'Start': '2023-05-01T00:00:00+0800',
1582+
'End': '2023-06-01T00:00:00+0800'
1583+
},
1584+
# 创建的任务类型,此处固定值为ImageInspect
1585+
# 必传参数
1586+
'WorkflowIds': 'w2504f47ad46exxxxxxxxxxxxxx',
1587+
},
1588+
1589+
}
1590+
response = client.ci_create_inventory_trigger_jobs(
1591+
Bucket=bucket_name,
1592+
JobBody=body,
1593+
ContentType='application/xml'
1594+
)
1595+
print(response)
1596+
return response
1597+
1598+
1599+
def ci_delete_inventory_trigger_jobs():
1600+
# 删除指定的批量处理任务
1601+
response = client.ci_delete_inventory_trigger_jobs(
1602+
Bucket=bucket_name, # 桶名称
1603+
JobId='b97c37f492adf11xxxxxxxxxxxx', # 需要删除的工作流ID
1604+
)
1605+
print(response)
1606+
return response
1607+
1608+
14971609
if __name__ == "__main__":
14981610
# ci_get_media_queue()
14991611
# ci_get_media_transcode_jobs()

qcloud_cos/cos_client.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9277,6 +9277,107 @@ def ci_cancel_jobs(self, Bucket, JobID, **kwargs):
92779277
logger.debug("ci_cancel_jobs:%s", rt.content)
92789278
return ''
92799279

9280+
def ci_create_inventory_trigger_jobs(self, Bucket, JobBody, **kwargs):
9281+
""" 创建批量处理任务接口 https://cloud.tencent.com/document/product/460/80155
9282+
:param Bucket(string): 存储桶名称.
9283+
:param JobBody(dict): 创建批量处理任务的配置.
9284+
:param kwargs(dict): 设置请求的headers.
9285+
:return(dict): 查询成功返回的结果,dict类型.
9286+
.. code-block:: python
9287+
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
9288+
client = CosS3Client(config)
9289+
# 创建任务接口
9290+
response = client.ci_create_inventory_trigger_jobs(
9291+
Bucket='bucket'
9292+
JobBody={},
9293+
)
9294+
print response
9295+
"""
9296+
headers = mapped(kwargs)
9297+
final_headers = {}
9298+
params = {}
9299+
for key in headers:
9300+
if key.startswith("response"):
9301+
params[key] = headers[key]
9302+
else:
9303+
final_headers[key] = headers[key]
9304+
headers = final_headers
92809305

9306+
params = format_values(params)
9307+
xml_config = format_xml(data=JobBody, root='Request')
9308+
path = "/inventorytriggerjob"
9309+
url = self._conf.uri(bucket=Bucket, path=path, endpoint=self._conf._endpoint_ci)
9310+
logger.info("ci_create_inventory_trigger_jobs result, url=:{url} ,headers=:{headers}, params=:{params}, xml_config=:{xml_config}".format(
9311+
url=url,
9312+
headers=headers,
9313+
params=params,
9314+
xml_config=xml_config))
9315+
rt = self.send_request(
9316+
method='POST',
9317+
url=url,
9318+
bucket=Bucket,
9319+
data=xml_config,
9320+
auth=CosS3Auth(self._conf, path, params=params),
9321+
params=params,
9322+
headers=headers,
9323+
ci_request=True)
9324+
9325+
data = xml_to_dict(rt.content)
9326+
# 单个元素时将dict转为list
9327+
format_dict(data, ['JobsDetail'])
9328+
return data
9329+
9330+
def ci_delete_inventory_trigger_jobs(self, Bucket, JobId, **kwargs):
9331+
""" 取消指定批量任务接口 https://cloud.tencent.com/document/product/460/76892
9332+
9333+
:param Bucket(string): 存储桶名称.
9334+
:param JobId(string): 需要取消的批量任务ID.
9335+
:param kwargs(dict): 设置请求的headers.
9336+
:return(dict): 查询成功返回的结果,dict类型.
9337+
9338+
.. code-block:: python
9339+
9340+
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
9341+
client = CosS3Client(config)
9342+
# 更新工作流状态接口
9343+
response = client.ci_delete_inventory_trigger_jobs(
9344+
Bucket='bucket'
9345+
JobId='',
9346+
)
9347+
print response
9348+
"""
9349+
headers = mapped(kwargs)
9350+
final_headers = {}
9351+
params = {}
9352+
for key in headers:
9353+
if key.startswith("response"):
9354+
params[key] = headers[key]
9355+
else:
9356+
final_headers[key] = headers[key]
9357+
headers = final_headers
9358+
9359+
params = format_values(params)
9360+
9361+
path = "/inventorytriggerjob/" + JobId
9362+
url = self._conf.uri(bucket=Bucket, path=path, endpoint=self._conf._endpoint_ci)
9363+
url = url + '?cancel'
9364+
logger.info("ci_delete_inventory_trigger_jobs result, url=:{url} ,headers=:{headers}, params=:{params}".format(
9365+
url=url,
9366+
headers=headers,
9367+
params=params))
9368+
rt = self.send_request(
9369+
method='PUT',
9370+
url=url,
9371+
bucket=Bucket,
9372+
auth=CosS3Auth(self._conf, path, params=params),
9373+
params=params,
9374+
headers=headers,
9375+
ci_request=True)
9376+
9377+
data = xml_to_dict(rt.content)
9378+
# 单个元素时将dict转为list
9379+
return data
9380+
9381+
92819382
if __name__ == "__main__":
92829383
pass

0 commit comments

Comments
 (0)