예제 #1
0
 def vframe(self, save_bucket_name, saveas, src_bucket_name, src,
            offset=0, width=None, height=None, rotate=None,
            pipeline='vframe', notify_url=None, format='png'):
     pfop = qiniu.PersistentFop(
         auth=self._auth,
         bucket=src_bucket_name,
         pipeline=pipeline,
         notify_url=notify_url
     )
     opargs = {
         'offset': offset
     }
     if width is not None:
         opargs['w'] = width
     if height is not None:
         opargs['h'] = height
     if rotate is not None:
         opargs['rotate'] = rotate
     op = qiniu.build_op('vframe', format,
                         **opargs)
     op = qiniu.op_save(op, save_bucket_name, saveas)
     logging.debug('[op] {}'.format(op))
     ops = [op]
     ret, info = pfop.execute(src, ops, 1)
     return ret, info
예제 #2
0
 def test_pfop(self):
     q = Auth(access_key, secret_key)
     pfop = PersistentFop(q, 'testres', 'sdktest')
     op = op_save('avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240', 'pythonsdk', 'pfoptest')
     ret, info = pfop.execute('sintel_trailer.mp4', op, 1)
     print(info)
     assert ret['persistentId'] is not None
예제 #3
0
 def test_pfop(self):
     q = Auth(access_key, secret_key)
     pfop = PersistentFop(q, "testres", "sdktest")
     op = op_save("avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240", "pythonsdk", "pfoptest")
     ops = []
     ops.append(op)
     ret, info = pfop.execute("sintel_trailer.mp4", ops, 1)
     print(info)
     assert ret["persistentId"] is not None
예제 #4
0
파일: tasks.py 프로젝트: fengpsky/convert
def convert_to_pdf(source_key, convert_task_id=None):
    dest_key = source_key + '.pdf'
    op = op_save('yifangyun_preview', QINIU_BUCKET_NAME, dest_key)
    pfop = PersistentFop(
        qiniu_auth, QINIU_BUCKET_NAME,
        notify_url=urlparse.urljoin(
            QINIU_CALLBACK_URL,
            '/api/qiniu_persist_callback?convert_task_id={}'.format(convert_task_id)))
    ret, info = pfop.execute(source_key, [op, ])
    return ret, info
예제 #5
0
 def test_pfop(self):
     q = Auth(access_key, secret_key)
     pfop = PersistentFop(q, 'testres', 'sdktest')
     op = op_save('avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240',
                  'pythonsdk', 'pfoptest')
     ops = []
     ops.append(op)
     ret, info = pfop.execute('sintel_trailer.mp4', ops, 1)
     print(info)
     assert ret['persistentId'] is not None
예제 #6
0
파일: models.py 프로젝트: GTxx/youjiao
 def convert_pdf(self):
     src_bucket_name = current_app.qiniu.PRIVATE_BUCKET_NAME
     dest_bucket_name = src_bucket_name
     QINIU_DOCUMENT_CALLBACK_URL = urljoin(
         current_app.qiniu.CALLBACK_URL, self.QINIU_DOCUMENT_CALLBACK_ROUTE)
     pfop = PersistentFop(current_app.qiniu.qiniu_auth, src_bucket_name,
                          notify_url=QINIU_DOCUMENT_CALLBACK_URL)
     saved_key = self.qiniu_key + '.pdf'
     op = op_save('yifangyun_preview', dest_bucket_name, saved_key.encode('utf-8'))
     ret, info = pfop.execute(self.qiniu_key, [op, ], force=1)
     if info.status_code != 200:
         raise Exception('error {}'.format(info))
예제 #7
0
파일: models.py 프로젝트: GTxx/youjiao
 def convert_mp3(self):
     src_bucket_name = current_app.qiniu.PRIVATE_BUCKET_NAME
     dest_bucket_name = src_bucket_name
     QINIU_AUDIO_CALLBACK_URL = urljoin(
         current_app.qiniu.CALLBACK_URL, self.QINIU_AUDIO_CALLBACK_ROUTE)
     pfop = PersistentFop(current_app.qiniu.qiniu_auth, src_bucket_name,
                          notify_url=QINIU_AUDIO_CALLBACK_URL)
     saved_key = self.qiniu_key + '.mp3'
     op = op_save('avthumb/mp3', dest_bucket_name, saved_key.encode('utf-8'))
     ret, info = pfop.execute(self.qiniu_key, [op], force=1)
     if info.status_code != 200:
         raise Exception('error {}'.format(info))
     return True
예제 #8
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)
예제 #9
0
파일: models.py 프로젝트: GTxx/youjiao
 def video_cut(self):
     src_bucket_name = current_app.qiniu.PRIVATE_BUCKET_NAME
     dest_bucket_name = src_bucket_name
     pipeline = current_app.qiniu.PIPELINE
     QINIU_VIDEO_CALLBACK_URL = urljoin(
             current_app.qiniu.CALLBACK_URL, self.QINIU_CUT_VIDEO_CALLBACK)
     pfop = PersistentFop(current_app.qiniu.qiniu_auth,
                          src_bucket_name, pipeline,
                          QINIU_VIDEO_CALLBACK_URL)
     saved_key = self.qiniu_key + '.short.mp4'
     # import ipdb; ipdb.set_trace()
     op = op_save('avthumb/mp4/t/180', dest_bucket_name, saved_key.encode('utf-8'))
     ret, info = pfop.execute(self.qiniu_key, [op, ], force=1)
     if info.status_code != 200:
         raise Exception(u'error {}'.format(info))
예제 #10
0
 def convert_mp3(self):
     src_bucket_name = current_app.qiniu.PRIVATE_BUCKET_NAME
     dest_bucket_name = src_bucket_name
     QINIU_AUDIO_CALLBACK_URL = urljoin(current_app.qiniu.CALLBACK_URL,
                                        self.QINIU_AUDIO_CALLBACK_ROUTE)
     pfop = PersistentFop(current_app.qiniu.qiniu_auth,
                          src_bucket_name,
                          notify_url=QINIU_AUDIO_CALLBACK_URL)
     saved_key = self.qiniu_key + '.mp3'
     op = op_save('avthumb/mp3', dest_bucket_name,
                  saved_key.encode('utf-8'))
     ret, info = pfop.execute(self.qiniu_key, [op], force=1)
     if info.status_code != 200:
         raise Exception('error {}'.format(info))
     return True
예제 #11
0
    def perform_pfop(self, origin):
        access_key = settings.QINIU['ACCESS_KEY']
        secret_key = settings.QINIU['SECRET_KEY']
        path = reverse('greetings-pfop-notify')
        notify_url = urlparse.urljoin(origin, path)

        auth = Auth(access_key, secret_key)
        pfop = PersistentFop(auth, 'tatmusic', 'wechataudio', notify_url)
        op = op_save('avthumb/mp3', 'tatmusic', self.key + '.mp3')
        ret, info = pfop.execute(self.key, [op])
        if self.data is None:
            self.data = ret
        else:
            self.data.update(ret)
        self.save(update_fields=['data'])
예제 #12
0
def watermark_with_image_and_text(srcBucket,
                                  srcKey,
                                  destFormat,
                                  wmText,
                                  wmImage,
                                  wmGravity="NorthWest",
                                  wmGravityText="NorthEast",
                                  wmFont=None,
                                  wmFontColor=None,
                                  wmFontSize=None,
                                  saveBucket=None,
                                  saveKey=None,
                                  usePipeline=None,
                                  notifyUrl=None):
    cmd = "avthumb"
    params = {
        "wmText": qiniu.urlsafe_base64_encode(wmText),
        "wmGravityText": wmGravityText,
        "wmImage": qiniu.urlsafe_base64_encode(wmImage),
        "wmGravity": wmGravity,
    }
    if wmFont != None:
        params.update({"wmFont": qiniu.urlsafe_base64_encode(wmFont)})
    if wmFontColor != None:
        params.update(
            {"wmFontColor": qiniu.urlsafe_base64_encode(wmFontColor)})
    if wmFontSize != None:
        params.update({"wmFontSize": wmFontSize})

    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)
예제 #13
0
 def convert_pdf(self):
     src_bucket_name = current_app.qiniu.PRIVATE_BUCKET_NAME
     dest_bucket_name = src_bucket_name
     QINIU_DOCUMENT_CALLBACK_URL = urljoin(
         current_app.qiniu.CALLBACK_URL, self.QINIU_DOCUMENT_CALLBACK_ROUTE)
     pfop = PersistentFop(current_app.qiniu.qiniu_auth,
                          src_bucket_name,
                          notify_url=QINIU_DOCUMENT_CALLBACK_URL)
     saved_key = self.qiniu_key + '.pdf'
     op = op_save('yifangyun_preview', dest_bucket_name,
                  saved_key.encode('utf-8'))
     ret, info = pfop.execute(self.qiniu_key, [
         op,
     ], force=1)
     if info.status_code != 200:
         raise Exception('error {}'.format(info))
예제 #14
0
 def video_cut(self):
     src_bucket_name = current_app.qiniu.PRIVATE_BUCKET_NAME
     dest_bucket_name = src_bucket_name
     pipeline = current_app.qiniu.PIPELINE
     QINIU_VIDEO_CALLBACK_URL = urljoin(current_app.qiniu.CALLBACK_URL,
                                        self.QINIU_CUT_VIDEO_CALLBACK)
     pfop = PersistentFop(current_app.qiniu.qiniu_auth, src_bucket_name,
                          pipeline, QINIU_VIDEO_CALLBACK_URL)
     saved_key = self.qiniu_key + '.short.mp4'
     # import ipdb; ipdb.set_trace()
     op = op_save('avthumb/mp4/t/180', dest_bucket_name,
                  saved_key.encode('utf-8'))
     ret, info = pfop.execute(self.qiniu_key, [
         op,
     ], force=1)
     if info.status_code != 200:
         raise Exception(u'error {}'.format(info))
예제 #15
0
 def avconcat(self, save_bucket_name, saveas, base_bucket_name, base,
              urls, mode='2', format='mp4',
              pipeline='concatevideo', notify_url=None):
     pfop = qiniu.PersistentFop(
         auth=self._auth,
         bucket=base_bucket_name,
         pipeline=pipeline,
         notify_url=notify_url
     )
     op = qiniu.build_op('avconcat', mode, format=format)
     if len(urls) > 5:
         raise ValueError('cannot append more then 5 videos')
     encoded_keys = [qiniu.urlsafe_base64_encode(url) for url in urls]
     encoded_keys.insert(0, op)
     op = '/'.join(encoded_keys)
     op = qiniu.op_save(op, save_bucket_name, saveas)
     logging.debug('[op] {}'.format(op))
     ops = [op]
     ret, info = pfop.execute(base, ops, 1)
     return ret, info
예제 #16
0
	def transcode_h264(self,bucket_name,key):

		file_tail = ['ori.mp4','.mp4']
	
		for type in file_tail:
		
			des_filename = key.replace(type,'h264.mp4')

			if des_filename is not None:
				break

		op=op_save('avthumb/mp4/ab/32k/aq/10/ar/44100/acodec/libfaac/r/25/vb/260k/vcodec/libx264/s/640x360/autoscale/1/stripmeta/0',bucket_name,des_filename)

		ops = []
		ops.append(op)
		self.pfop=PersistentFop(self.q,bucket_name,'videoconverth264')
		ret,info = self.pfop.execute(key,ops,1)

		if 200 == info.status_code:
			return 0
		else:
				
			return info.text_body[10:-2]
예제 #17
0
def add_post(request):
    if not request.user.is_anonymous():
        if request.method == 'POST':
            post_form = PostForm(request.POST)
            tag = TagForm(request.POST)
            if post_form.is_valid() and tag.is_valid():
                cd_tag = tag.cleaned_data
                tag_name = cd_tag['tag_name']
                for tag_list in tag_name.split(','):
                    Tag.objects.get_or_create(tag_name=tag_list.strip())
                title = post_form.cleaned_data['caption']
                user = request.user
                content = post_form.cleaned_data['content']
                post = Post(caption=title, user=user, content=content, vedio_xml_link="/home/yusn/liteforum/liteforum/static/ressvr/video.xml")
                post.save()
                #tags
                for tag_list in tag_name.split(','):
                    post.tags.add(Tag.objects.get(tag_name=tag_list.strip()))
                    post.save()
                post_id = Post.objects.order_by('-publish_time')[0].id
                #qiniu
                if 'file' in request.FILES:
                    post.vedio_count = 1
                    post.save()
                    bucket_src = 'sns-picture'
                    q = qiniu.Auth('iaB9zwTfCcWzZgIoHKmxexJee1mY_301y5fnsSSZ', '4c75Nb8qypfYrwOhOwOY_rLdYAiH0937sKYh6yWh')
                    data = request.FILES['file']
                    token = q.upload_token(bucket_src)
                    key = request.FILES['file'].name+".mp4"
                    ret, info = qiniu.put_data(token, key, data)
                    pfop = PersistentFop(q, bucket_src)
                    op = op_save('avthumb/mp4/vcodec/libx264/s/', bucket_src, key)
                    ops = []
                    ops.append(op)
                    ret, info = pfop.execute(key, ops, 1)
                    print(info)
                    assert ret['persistentId'] is not None
                    if ret is not None:
                        print('All is OK')
                    else:
                        print(info) # error message in info
                    #create a new video xml
                    os.chdir("/home/yusn/liteforum/liteforum/static/ressvr")
                    template_object = open('video.xml')
                    try:
                         all_the_text = template_object.read()
                         all_the_text = all_the_text.replace("#replace#", request.FILES['file'].name.encode("utf-8"))
                         new_xml = open(request.FILES['file'].name.encode("utf-8")+'.xml', 'w')
                         new_xml.write(all_the_text)
                         new_xml.close()
                         post.vedio_xml_link = request.FILES['file'].name.encode("utf-8")+'.xml'
                         post.save()
                    finally:
                         template_object.close( )
                return HttpResponseRedirect('/forum/%s' % post.id)
        else:
            post_form = PostForm()
            tag = TagForm(initial={'tag_name': 'others'})
        return render_to_response('forum/add_post.html',
                                  {'form': post_form, 'tag': tag}, RequestContext(request))
    else:
        return render(request, 'forum/login.html', {})