Beispiel #1
0
def disableStreams(access_key, secret_key, hub, streamTitle, disabledTill):
    """
    禁播流
    https://developer.qiniu.com/pili/api/2775/off-the-air-flow
    :param access_key: 公钥
    :param secret_key: 私钥
    :param hub: 直播空间
    :param streamTitle: 流名
    :param disabledTill: 整数,Unix 时间戳,表示流禁播的结束时间,单位 s(秒),-1 表示永久禁播。0 表示解除禁播。

    :return:
            200 {}
            612 {
                "error": "stream not found"
            }
    """
    auth = QiniuMacAuth(access_key, secret_key)

    # 流名base64安全编码
    EncodedStreamTitle = urlsafe_base64_encode(streamTitle)

    # 请求URL
    url = f'http://pili.qiniuapi.com/v2/hubs/{hub}/streams/{EncodedStreamTitle}/disabled'

    # 请求体
    body = {"disabledTill": disabledTill}

    # 发起POST请求
    ret, res = http._post_with_qiniu_mac(url, body, auth)
    headers = {"code": res.status_code, "reqid": res.req_id, "xlog": res.x_log}

    # 格式化响应体
    Headers = json.dumps(headers, indent=4, ensure_ascii=False)
    result = json.dumps(ret, indent=4, ensure_ascii=False)
    return Headers, result
def createStreams(access_key, secret_key, namespaceId, body):
    """
    创建流
    https://developer.qiniu.com/qvs/api/6734/create-flow
    :param access_key: 公钥
    :param secret_key: 私钥
    :param namespaceId: 空间ID
    :param body: 请求体
            {
                "streamId":"device009", // 必填,流名称, 流名称在空间中唯一,可包含 字母、数字、中划线、下划线;1 ~ 100 个字符长;创建后将不可修改
                "desc":"流说明信息", // 非必填,关于流的描述信息
                "recordTemplateId":"d102sns2mwhd", // 非必填,录制模版ID,配置流维度的录制模板
                "snapshotTemplateId":"截图模板ID" // 非必填,截图模版ID,配置流维度的截图模板
            }

    :return:
           200 { }
    """
    auth = QiniuMacAuth(access_key, secret_key)

    # 请求URL
    url = f"http://qvs.qiniuapi.com/v1/namespaces/{namespaceId}/streams"

    # 发起POST请求
    ret, res = http._post_with_qiniu_mac(url, body, auth=auth)
    headers = {"code": res.status_code, "reqid": res.req_id, "xlog": res.x_log}

    # 格式化响应体
    Headers = json.dumps(headers, indent=4, ensure_ascii=False)
    result = json.dumps(ret, indent=4, ensure_ascii=False)
    return Headers, result
def enableStreams(access_key, secret_key, namespaceId, streamId):
    """
    启用流
    https://developer.qiniu.com/qvs/api/6739/enable-the-flow
    :param access_key: 公钥
    :param secret_key: 私钥
    :param namespaceId: 空间ID
    :param streamId: 流ID

    :return:
            {
                "code": 200
            }
    """
    auth = QiniuMacAuth(access_key, secret_key)

    # 请求URL
    url = f"http://qvs.qiniuapi.com/v1/namespaces/{namespaceId}/streams/{streamId}/enabled"

    # 发起POST请求
    ret, res = http._post_with_qiniu_mac(url, None, auth=auth)
    headers = {"code": res.status_code, "reqid": res.req_id, "xlog": res.x_log}

    # 格式化响应体
    Headers = json.dumps(headers, indent=4, ensure_ascii=False)
    result = json.dumps(ret, indent=4, ensure_ascii=False)
    return Headers, result
Beispiel #4
0
def saveasStreams(access_key, secret_key, hub, streamTitle, body):
    """
    保存直播截图
    https://developer.qiniu.com/pili/api/2520/save-the-live-capture
    :param access_key: 公钥
    :param secret_key: 私钥
    :param hub: 直播空间
    :param streamTitle: 流名
    :param body: 请求体

    :return:
        200 {
            "fname": "<Fname>"
        }
    """
    auth = QiniuMacAuth(access_key, secret_key)

    # 流名base64安全编码
    EncodedStreamTitle = urlsafe_base64_encode(streamTitle)

    # 请求URL
    url = f'http://pili.qiniuapi.com/v2/hubs/{hub}/streams/{EncodedStreamTitle}/snapshot'

    # 发起POST请求
    ret, res = http._post_with_qiniu_mac(url, body, auth)
    headers = {"code": res.status_code, "reqid": res.req_id, "xlog": res.x_log}

    # 格式化响应体内容
    Headers = json.dumps(headers, indent=4, ensure_ascii=False)
    result = json.dumps(ret, indent=4, ensure_ascii=False)

    return Headers, result
Beispiel #5
0
def createStreams(access_key, secret_key, hub, streamTitle):
    """
    创建流
    https://developer.qiniu.com/pili/api/2515/create-a-flow
    :param access_key: 公钥
    :param secret_key: 私钥
    :param hub: 直播空间
    :param streamTitle: 流名

    :return:
            200 {}
            614 {
                "error": "stream already exists"
            }
    """
    auth = QiniuMacAuth(access_key, secret_key)

    # 请求体
    body = {"key": streamTitle}

    # 请求URL
    url = f'http://pili.qiniuapi.com/v2/hubs/{hub}/streams'

    # 发起POST请求
    ret, res = http._post_with_qiniu_mac(url, body, auth)
    headers = {"code": res.status_code, "reqid": res.req_id, "xlog": res.x_log}

    # 格式化响应体
    Headers = json.dumps(headers, indent=4, ensure_ascii=False)
    result = json.dumps(ret, indent=4, ensure_ascii=False)
    return Headers, result
Beispiel #6
0
    def domain_offline(self, name):
        """
        下线域名,文档 https://developer.qiniu.com/fusion/api/4246/the-domain-name#5

        Args:
            name:     域名, 如果是泛域名,必须以点号 . 开头
            bosy:     创建域名参数
        Returns:
            {}
        """
        url = '{0}/domain/{1}/offline'.format(self.server, name)
        return http._post_with_qiniu_mac(url, None, self.auth)
Beispiel #7
0
def video_appraisal(auth, vid, url, ops, params=None):
    """
    @vid 视频唯一的ID
    @url 视频鉴黄的地址
    @params 字典,视频处理的参数
    @ops 视频检测命令 [AppraisalOperation...]
    具体参数格式参考:
    https://developer.qiniu.com/dora/manual/4258/video-pulp'''
    """
    if params is not None:
        if not isinstance(params, dict):
            raise TypeError(
                "params must be instance of dict, invalid params: %s" % params)
    if not isinstance(ops, list):
        raise TypeError("ops must be instance of list, invalid ops: %s" % ops)
    if len(ops) <= 0:
        raise ValueError("length of ops must greater than zero")
    if not isinstance(auth, QiniuMacAuth):
        raise TypeError("auth must be instance of QiniuMacAuth")

    def getop(operation):
        d = {
            "op": operation.op,
        }
        if operation.hook_url:
            d["hookURL"] = operation.hook_url
        if operation.params:
            d["params"] = operation.params
        return d

    ops = [getop(op) for op in ops]

    if params:
        data = {
            "data": {
                "uri": url,
            },
            "params": params
        }
    else:
        data = {
            "data": {
                "uri": url,
            },
        }
    data['ops'] = ops

    return _post_with_qiniu_mac("http://argus.atlab.ai/v1/video/%s" % vid,
                                data, auth)
Beispiel #8
0
    def create_app(self, args):
        """创建应用

        在指定区域创建一个新应用,所属应用为当前请求方。

        Args:
            - args: 请求参数(json),参考 http://kirk-docs.qiniu.com/apidocs/

        Returns:
            - result        成功返回所创建的应用信息,若失败则返回None
            - ResponseInfo  请求的Response信息
        """

        url = '{0}/v3/apps'.format(self.host)
        return http._post_with_qiniu_mac(url, args, self.auth)
Beispiel #9
0
    def create_app(self, args):
        """创建应用

        在指定区域创建一个新应用,所属应用为当前请求方。

        Args:
            - args: 请求参数(json),参考 http://kirk-docs.sdk.com/apidocs/

        Returns:
            - result        成功返回所创建的应用信息,若失败则返回None
            - ResponseInfo  请求的Response信息
        """

        url = '{0}/v3/apps'.format(self.host)
        return http._post_with_qiniu_mac(url, args, self.auth)
Beispiel #10
0
def is_image_valid(image_url):
    url = 'http://ai.qiniuapi.com/v3/image/censor'
    auth = QiniuMacAuth(QINIU_ACCESS_KEY, QINIU_SECRET_KEY)
    body = {
        "data": {
            "uri": "<uri>"
        },
        "params": {
            "scenes": []
        }
    }
    body["params"]["scenes"] = ['pulp', 'terror', 'politician']
    body["data"]["uri"] = image_url
    ret, res = http._post_with_qiniu_mac(url, body, auth)

    if res.status_code == 200:
        is_valid = ret['result']['suggestion'] == 'pass'
    else:
        is_valid = False
    return is_valid
Beispiel #11
0
    def async_fetch(self, urls, bucket, host=None, key=None, md5=None, etag=None, callback_url=None,
                    callback_body=None, callback_body_type=None, callback_host=None, file_type=0):
        """异步抓取文件:
        从指定URL抓取资源,并将该资源存储到指定空间中,具体规格参考:
        https://developer.qiniu.com/kodo/api/4097/asynch-fetch

        Args:
            url:    指定的URL
            bucket: 目标资源空间
            key:    目标资源文件名

        Returns:
            一个dict变量,成功返回NULL,失败返回{"error": "<errMsg string>"}
            一个ResponseInfo对象
        """
        data = {"url": ";".join(urls), "bucket": bucket}
        if host:
            data["host"] = host
        if md5:
            data["md5"] = md5
        if key:
            data["key"] = key
        if etag:
            data["etag"] = etag
        if callback_url:
            data["callbackurl"] = callback_url
        if callback_body:
            data["callbackbody"] = callback_body
        if callback_body_type:
            data["callbackbodytype"] = callback_body_type
        if callback_host:
            data["callbackhost"] = callback_host
        if file_type:
            data["file_type"] = file_type

        api_host = self.zone.get_api_host(bucket, self.auth)
        url = "http://%s/%s" % (api_host, "sisyphus/fetch")
        return http._post_with_qiniu_mac(url, data, self.auth, headers={
            "Host": api_host,
            "Content-Type": "application/json",
        })
def createTemplate(access_key, secret_key, body):
    """
    创建模板
    https://developer.qiniu.com/qvs/api/6721/create-template
    :param access_key: 公钥
    :param secret_key: 私钥
    :param body: 请求体
        {
            "name": 必填,模版名称,格式为 1 ~ 100个字符,可包含小写字母、数字、中划线
            "desc":非必填,模板描述
            "bucket": 必填,模版对应的对象存储的bucket
            "deleteAfterDays": 必填,存储过期时间,默认永久不过期
            "fileType": 必填,文件存储类型,取值:0(普通存储),1(低频存储)
            "recordFileFormat": 非必填,录制文件存储格式,取值:0(m3u8格式存储)
            "templateType": 必填,模板类型,取值:0(录制模版), 1(截图模版)
            "recordType":templateType为0时须指定,录制模式, 0(不录制),1(实时录制)
            "jpgOverwriteStatus": templateType为1时须指定,开启覆盖式截图(一般用于流封面)
            "jpgSequenceStatus":templateType为1时须指定,开启序列式截图
            "jpgOnDemandStatus":templateType为1时须指定,开启按需截图
            "recordInterval":非必填,录制文件时长 单位为秒,600~3600
            "snapInterval": 非必填,截图间隔, 单位为秒, 10~600
        }

    :return:
        {

        }
    """
    auth = QiniuMacAuth(access_key, secret_key)

    # 请求URL
    url = "http://qvs.qiniuapi.com/v1/templates"

    # 发起POST请求
    ret, res = http._post_with_qiniu_mac(url, body, auth)
    headers = {"code": res.status_code, "reqid": res.req_id, "xlog": res.x_log}

    # 格式化响应体
    Headers = json.dumps(headers, indent=4, ensure_ascii=False)
    result = json.dumps(ret, indent=4, ensure_ascii=False)
    return Headers, result
Beispiel #13
0
def saveasPlayBack(access_key, secret_key, hub, streamTitle, body):
    """
    录制直播回放
    https://developer.qiniu.com/pili/api/2777/save-the-live-playback
    :param access_key: 公钥
    :param secret_key: 私钥
    :param hub: 直播空间
    :param streamTitle: 流名
    :param body: 请求体

    :return:
        200 {
            "fname": "<Fname>",
            "persistentID": "<PersistentID>"
        }
        612 {
            "error": "stream not found"
        }
        619 {
            "error": "no data" // 没有直播数据
        }
    """
    auth = QiniuMacAuth(access_key, secret_key)
    print('==')
    print(auth.__dict__)
    print('==')

    # 流名base64安全编码
    EncodedStreamTitle = urlsafe_base64_encode(streamTitle)

    # 请求URL
    url = f'http://pili.qiniuapi.com/v2/hubs/{hub}/streams/{EncodedStreamTitle}/saveas'

    # 发起POST请求
    ret, res = http._post_with_qiniu_mac(url, body, auth)
    headers = {"code": res.status_code, "reqid": res.req_id, "xlog": res.x_log}

    # 格式化响应体
    Headers = json.dumps(headers, indent=4, ensure_ascii=False)
    result = json.dumps(ret, indent=4, ensure_ascii=False)
    return Headers, result
Beispiel #14
0
 def set_bucketImagesource(self,
                           bucket_name,
                           resourceDomain,
                           resourceHost=None):
     """
     设置 存储空间 镜像源
     https://developer.qiniu.com/kodo/api/3966/bucket-image-source
     Args:
         bucket_name: 存储空间名
     """
     resourceDomain = urlsafe_base64_encode(resourceDomain)
     resourceHost = urlsafe_base64_encode(resourceHost)
     if resourceHost is None or resourceHost == "":
         url = "{0}/image/{1}/from/{2}".format(
             config.get_default("default_uc_host"), bucket_name,
             resourceDomain)
     else:
         url = "{0}/image/{1}/from/{2}/host/{3}".format(
             config.get_default("default_uc_host"), bucket_name,
             resourceDomain, resourceHost)
     data = None
     return http._post_with_qiniu_mac(url, data, self.auth)
Beispiel #15
0
def saveasStreams(access_key, secret_key, hub, streamTitle, body):
    """
    修改流转码配置
    https://developer.qiniu.com/pili/api/2521/modify-the-flow-configuration
    :param access_key: 公钥
    :param secret_key: 私钥
    :param hub: 直播空间
    :param streamTitle: 流名
    :param body: 请求体

    :return:
        200 {}
        400 {
            "error": "invalid stream key" // 只能修改原始流,包含@的流不允许
        }
        400 {
            "error": "invalid args" // 转码配置不存在
        }
        612 {
            "error": "stream not found"
        }
    """
    auth = QiniuMacAuth(access_key, secret_key)

    # 流名base64安全编码
    EncodedStreamTitle = urlsafe_base64_encode(streamTitle)

    # 请求地址
    url = f'http://pili.qiniuapi.com/v2/hubs/{hub}/streams/{EncodedStreamTitle}/converts'

    # 发起post请求
    ret, res = http._post_with_qiniu_mac(url, body, auth)
    headers = {"code": res.status_code, "reqid": res.req_id, "xlog": res.x_log}

    # 格式化响应体内容
    Headers = json.dumps(headers, indent=4, ensure_ascii=False)
    result = json.dumps(ret, indent=4, ensure_ascii=False)

    return Headers, result
Beispiel #16
0
def batchListOnlineStreamsInfo(access_key, secret_key, hub, body):
    """
    批量查询直播实时信息
    https://developer.qiniu.com/pili/api/3764/batch-query-broadcast-real-time-information
    :param access_key: 公钥
    :param secret_key: 私钥
    :param hub: 直播空间
    :param body: 请求体

    :return:
        200 {
                "items": [
                    {
                        "key": "<StreamTitle>",
                        "startAt": <StartAt>,
                        "clientIP": "<ClientIP>",
                        "bps": <Bps>, // 当前码率
                        "fps": {
                            "audio": <Audio>,
                            "video": <Video>,
                            "data": <Data>
                    },
                    ...
                ]
            }
    """
    auth = QiniuMacAuth(access_key, secret_key)

    # 请求URL
    url = f'http://pili.qiniuapi.com/v2/hubs/{hub}/livestreams'

    # 发起POST请求
    ret, res = http._post_with_qiniu_mac(url, body, auth)
    headers = {"code": res.status_code, "reqid": res.req_id, "xlog": res.x_log}

    # 格式化响应体
    Headers = json.dumps(headers, indent=4, ensure_ascii=False)
    result = json.dumps(ret, indent=4, ensure_ascii=False)
    return Headers, result
Beispiel #17
0
def createNamespaces(access_key, secret_key, body):
    """
    创建空间
    https://developer.qiniu.com/qvs/api/6726/create-namespace
    :param access_key: 公钥
    :param secret_key: 私钥
    :param body: 请求体
        {
            "name": 必填,空间名称(格式"^[a-zA-Z0-9_-]{1,100}$")
            "desc":非必填,空间描述
            "accessType": 必填,接入类型(rtmp或者gb28181)
            "rtmpUrlType": accessType为“rtmp”时 必填,推拉流地址计算方式,1:static, 2:dynamic
            "domains": rtmpUrlType为1时必填,直播域名,列表格式
            "callBack":非必填,回调地址,可用于获取空间内设备/流状态更新时的信息
            "recordTemplateId": 非必填,录制模版ID,需要录制功能时输入对应的模板ID,录制模板ID可以模板管理中获取
            "snapshotTemplateId":非必填,截图模版ID,需要截图功能时输入对应的模板ID,截图模板ID可以模板管理中获取
            "recordTemplateApplyAll":非必填,空间模版是否应用到全局
            "snapshotTemplateApplyAll":非必填,截图模版是否应用到全局
        }

    :return:
        {

        }
    """
    auth = QiniuMacAuth(access_key, secret_key)

    # 请求URL
    url = "http://qvs.qiniuapi.com/v1/namespaces"

    # 发起POST请求
    ret, res = http._post_with_qiniu_mac(url, body, auth)
    headers = {"code": res.status_code, "reqid": res.req_id, "xlog": res.x_log}

    # 格式化响应体
    Headers = json.dumps(headers, indent=4, ensure_ascii=False)
    result = json.dumps(ret, indent=4, ensure_ascii=False)
    return Headers, result
import requests, json

"""
旧版OCR身份证识别(idcard)
https://developer.qiniu.com/dora/api/4276/ocr-sari-idcard
"""

# AK、SK
access_key = '<access_key>'
secret_key = '<secret_key>'

auth = QiniuMacAuth(access_key, secret_key)

# 请求URL
url = 'http://ai.qiniuapi.com/v1/ocr/idcard'

# 请求参数
body = {
    "data": {
        # 身份证图片链接
        "uri": ""
    }
}

ret, res = http._post_with_qiniu_mac(url, body, auth)
headers = {"code": res.status_code, "reqid": res.req_id, "xlog": res.x_log}

print(json.dumps(headers, indent=4, ensure_ascii=False))
print(json.dumps(ret, indent=4, ensure_ascii=False))

Beispiel #19
0
 def __post(self, url, data=None):
     return http._post_with_qiniu_mac(url, data, self.auth)
Beispiel #20
0
from qiniu import QiniuMacAuth, http
import requests, time

#  密钥队初始化
access_key = 'your_AK'
secret_key = 'your_SK'
q = QiniuMacAuth(access_key, secret_key)

url = 'http://ai.qiniuapi.com/v3/video/censor'   # 请求url
data = {"data": {"uri": "http://cdn.vcore.hk/1528336770927592712019-02-181550474493.mp4"}, "params": {"scenes": ["pulp", "terror", "politician"]}}
ret, info = http._post_with_qiniu_mac(url, data, q)
job = ret['job']

time.sleep(10)
# 根据job得到结果
url1 = 'http://ai.qiniuapi.com/v3/jobs/video/{}'.format(job)
token = "Qiniu " + q.token_of_request("GET", "ai.qiniuapi.com", url1, "")
r = requests.get(url1, headers={'Authorization': token})
print(r.text)


Beispiel #21
0
 def __post(self, url, data=None):
     return http._post_with_qiniu_mac(url, data, self.auth)
Beispiel #22
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import qiniu
from qiniu import QiniuMacAuth
from qiniu import http

access_key = os.getenv('QINIU_ACCESS_KEY')
secret_key = os.getenv('QINIU_SECRET_KEY')

auth = QiniuMacAuth(access_key, secret_key)

url = 'http://ai.qiniuapi.com/v1/eval/detection'
data = {"data": {"uri": "http://o8smkso2w.bkt.clouddn.com/dog.jpg"}}
req = http._post_with_qiniu_mac(url, data, auth)
print(req[0])
Beispiel #23
0
from qiniu import QiniuMacAuth
from qiniu import http

# 初始化AK,SK
access_key = 'your_AK'
secret_key = 'your_SK'
q = QiniuMacAuth(access_key, secret_key)

# 包体和接口
data = {'data': {'uri': 'http://7xlv47.com1.z0.glb.clouddn.com/pulpsexy.jpg'}}
# body = json.dumps(data).encode('utf-8')
# url = 'http://ai.qiniuapi.com/v1/image/censor'
url = 'http://ai.qiniuapi.com/v1/pulp'
# # 生成七牛鉴权,专门用来数据处理的鉴权
# token = q.token_of_request(method='POST', host='ai.qiniuapi.com', url=url, qheaders='', content_type='application/json', body=body)
#
# headers= {
#     'Content-Type': 'application/json',
#     'Authorization': 'Qiniu {0}'.format(token)
# }
# print(headers)

res1 = http._post_with_qiniu_mac(url=url, data=data, auth=q)
# res = requests.post(url=url, headers=headers, data=json.dumps(data))
print(res1)

Beispiel #24
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

from qiniu import QiniuMacAuth
from qiniu import http
import json
from configobj import ConfigObj

config = ConfigObj("../../.config.ini", encoding='UTF8')
# 读配置文件
access_key = config['account']['access_key']
secret_key = config['account']['secret_key']

q_auth = QiniuMacAuth(access_key, secret_key)
data_json = "{\"data\":{\"uri\":\"http://7xlv47.com1.z0.glb.clouddn.com/pulpsexy.jpg\"}" + "}"
url = "http://argus.atlab.ai/v1/pulp"
content_type = "application/json"
# data = data_json.encode('utf-8')
authorization = "Qiniu " + q_auth.token_of_request("POST", "argus.atlab.ai", url, "", content_type, data_json)
headers = {}
headers["Host"] = "argus.atlab.ai"
headers["Content-Type"] = content_type
ret, info = http._post_with_qiniu_mac(url, json.loads(data_json), q_auth)
print(info)