Пример #1
0
def vsample(bucket, key, picFormat, startSecond, duration, pattern, resolution=None, rotate=None, interval=None):
    #准备命令
    cmd = "vsample"

    #组织参数
    cmdParams = {
        "ss": startSecond,
        "t": duration,
        "pattern": pattern,
    }
    if resolution:
        cmdParams.update({"s": resolution})
    if rotate:
        cmdParams.update({"rotate": rotate})
    if interval:
        cmdParams.update({"interval": interval})

    #执行fop
    fop = qiniu.build_op(cmd, picFormat, **cmdParams)
    #默认为空,表示使用公共队列
    usePipeline = ""
    #fop处理结果通知url
    notifyUrl = None
    auth = qiniu.Auth(accessKey, secretKey)
    pfop = qiniu.PersistentFop(auth, bucket, usePipeline, notifyUrl)
    retData, respInfo = pfop.execute(key, [fop], force=None)
    if retData != None:
        print("PersistentId:" + retData["persistentId"])
    else:
        print("Error:")
        print("--StatusCode:" + str(respInfo.status_code))
        print("--Reqid:" + respInfo.req_id)
        print("--Message:" + respInfo.error)
Пример #2
0
def vframe(format,
           offset,
           width,
           height,
           rotate,
           fromBucket,
           fromKey,
           usePipeline="",
           notifyUrl=None,
           saveBucket=None,
           saveKey=None):
    #prepare fop
    params = {"offset": offset, "w": width, "h": height, "rotate": rotate}
    fop = qiniu.build_op("vframe", format, **params)
    if saveBucket != None and saveKey != None:
        fop = qiniu.op_save(fop, saveBucket, saveKey)

    #do pfop
    auth = qiniu.Auth(accessKey, secretKey)
    pfop = qiniu.PersistentFop(auth, fromBucket, usePipeline, notifyUrl)
    retData, respInfo = pfop.execute(fromKey, [fop], force=None)
    if retData != None:
        print("PersistentId:" + retData["persistentId"])
    else:
        print("Error:")
        print("--StatusCode:" + str(respInfo.status_code))
        print("--Reqid:" + respInfo.req_id)
        print("--Message:" + respInfo.error)
Пример #3
0
def watermark_with_image(srcBucket,
                         srcKey,
                         destFormat,
                         wmImage,
                         wmGravity="NorthEast",
                         saveBucket=None,
                         saveKey=None,
                         usePipeline=None,
                         notifyUrl=None):
    cmd = "avthumb"
    params = {
        "wmImage": qiniu.urlsafe_base64_encode(wmImage),
        "wmGravity": wmGravity,
    }

    fop = qiniu.build_op(cmd, destFormat, **params)
    #saveas
    if saveBucket != None and saveKey != None:
        fop = qiniu.op_save(fop, saveBucket, saveKey)

    #pfop
    auth = qiniu.Auth(accessKey, secretKey)
    pfop = qiniu.PersistentFop(auth,
                               srcBucket,
                               pipeline=usePipeline,
                               notify_url=notifyUrl)
    retData, respInfo = pfop.execute(srcKey, [fop], force=None)
    if retData != None:
        print("PersistentId:" + retData["persistentId"])
    else:
        print("Error:")
        print("--StatusCode:" + str(respInfo.status_code))
        print("--Reqid:" + respInfo.req_id)
        print("--Message:" + respInfo.error)
Пример #4
0
def amerge(ufopCmd,
           srcBucket,
           srcKey,
           dstFormat,
           dstMime,
           urlBucket,
           url,
           duration="first",
           usePipeline="",
           notifyUrl=None,
           saveBucket=None,
           saveKey=None):
    #prepare fop
    fop = "{0}/format/{1}/mime/{2}/bucket/{3}/url/{4}".format(
        ufopCmd, dstFormat, qiniu.urlsafe_base64_encode(dstMime),
        qiniu.urlsafe_base64_encode(urlBucket),
        qiniu.urlsafe_base64_encode(url))
    if saveBucket != None and saveKey != None:
        fop = qiniu.op_save(fop, saveBucket, saveKey)

    #do pfop
    auth = qiniu.Auth(accessKey, secretKey)
    pfop = qiniu.PersistentFop(auth, srcBucket, usePipeline, notifyUrl)
    retData, respInfo = pfop.execute(srcKey, [fop], force=None)
    if retData != None:
        print("PersistentId:" + retData["persistentId"])
    else:
        print("Error:")
        print("--StatusCode:" + str(respInfo.status_code))
        print("--Reqid:" + respInfo.req_id)
        print("--Message:" + respInfo.error)
Пример #5
0
 def min_url(self, filename):
     q = QiniuClass.Auth(self._access_key, self._secret_key)
     #要缩略的文件所在的空间和文件名。
     from_bucket_name = 'user-img'
     to_bucket_name = 'min-img'
     from_key = filename
     to_key = 'min_' + from_key
     self.min_delete(to_key)
     #pipeline是使用的队列名称,不设置代表不使用私有队列,使用公有队列。
     pipeline = ''
     #要进行缩略的操作。
     fops = 'imageView2/1/w/50/h/50/q/100|imageslim'
     saveas_key = QiniuClass.urlsafe_base64_encode(to_bucket_name + ':' +
                                                   to_key)
     fops = fops + '|saveas/' + saveas_key
     pfop = QiniuClass.PersistentFop(q, from_bucket_name, pipeline)
     ops = []
     ops.append(fops)
     ret, info = pfop.execute(from_key, ops, 1)
     print(info)
     new_src = 'http://opkrd0ovy.bkt.clouddn.com'
     new_url = urljoin(new_src, to_key)
     #map要缩略的文件所在的空间和文件名。
     from_bucket_name = 'min-img'
     to_bucket_name = 'min-img'
     map_from_key = 'st_out.png'
     map_to_key = 'map_' + from_key
     self.min_delete(map_to_key)
     #pipeline是使用的队列名称,不设置代表不使用私有队列,使用公有队列。
     pipeline = ''
     #要进行缩略的操作。
     bg_img = QiniuClass.urlsafe_base64_encode(new_url)
     fops = 'imageView2/2/w/65/h/90/q/75|watermark/1/image/' + bg_img + '/dissolve/100/gravity/North/dx/0/dy/5|imageslim'
     print(fops)
     saveas_key = QiniuClass.urlsafe_base64_encode(to_bucket_name + ':' +
                                                   map_to_key)
     fops = fops + '|saveas/' + saveas_key
     pfop = QiniuClass.PersistentFop(q, from_bucket_name, pipeline)
     ops = []
     ops.append(fops)
     ret, info = pfop.execute(map_from_key, ops, 1)
     print(info)
     return urljoin(new_src, map_to_key)
Пример #6
0
def avthumb_m3u8(type, dstFormat):
    #准备命令
    cmd = "avthumb/m3u8"

    if type == "wifi":
        segtime = "10"
        videoBitRate = "440k"
    elif type == "3g":
        segtime = "5"
        videoBitRate = "240k"

    resolution = "400x244"
    cmdParams = {
        "segtime": segtime,
        "vb": videoBitRate,
        "s": resolution,
        "vodec": "libx264",
    }

    #结果保存空间名称
    saveBucket = "qiniu-lab"
    if type == "wifi":
        saveKey = u"七牛云存储视频名片_wifi.m3u8".encode("utf-8")
    elif type == "3g":
        saveKey = u"七牛云存储视频名片_3g.m3u8".encode("utf-8")

    #构建fop指令
    fop = qiniu.build_op(cmd, dstFormat, **cmdParams)
    #指定保存的空间和key,否则将以结果的hash值作为文件名保存
    fop = qiniu.op_save(fop, saveBucket, saveKey)

    #执行fop操作
    fromBucket = "qiniu-lab"
    fromKey = u"七牛云存储视频名片.mp4".encode("utf-8")
    #默认为空,表示使用公共队列
    usePipeline = ""
    #私有队列,根据你实际情况设置
    usePipeline = "fff"
    #fop处理结果通知url
    notifyUrl = None
    auth = qiniu.Auth(accessKey, secretKey)
    pfop = qiniu.PersistentFop(auth, fromBucket, usePipeline, notifyUrl)
    retData, respInfo = pfop.execute(fromKey, [fop], force=None)
    if retData != None:
        print("PersistentId:" + retData["persistentId"])
    else:
        print("Error:")
        print("--StatusCode:" + str(respInfo.status_code))
        print("--Reqid:" + respInfo.req_id)
        print("--Message:" + respInfo.error)
Пример #7
0
def dealwith_img(request):
    q = qiniu_auth()
    key = request.GET.get('key')
    bucket_name = qiniu_config['bucket_name']
    # pipeline是使用的队列名称,不设置代表不使用私有队列,使用公有队列。
    # pipeline = 'your_pipeline'
    # 要进行的转换格式操作。
    fops = 'imageView2/0/format/webp/interlace/1'
    # 可以对缩略后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当前空间
    saveas_key = qiniu.urlsafe_base64_encode(bucket_name + ':' + key)
    fops = fops + '|saveas/' + saveas_key
    # pfop = qiniu.PersistentFop(q, bucket_name, pipeline)
    pfop = qiniu.PersistentFop(q, bucket_name)
    ops = []
    ops.append(fops)
    ret, info = pfop.execute(key, ops, 1)
    assert ret['persistentId'] is not None
    cdn_flush(key)
    return HttpResponse(json.dumps('ok'))