Example #1
0
File: video.py Project: why2012/QSZ
    def __delete(self, bucket, path):
        if path == '' or path == '/':
            return {
                'httpcode': 0,
                'code': self.VIDEO_PARAMS_ERROR,
                'message': 'path cannot be empty',
                'data': {}
            }
        expired = int(time.time()) + self.EXPIRED_SECONDS
        url = self.generate_res_url(bucket, path)
        auth = Auth(self._secret_id, self._secret_key)
        sign = auth.sign_once(
            bucket, '/' + str(conf.get_app_info()['appid']) + '/' + bucket +
            '/' + path)

        headers = {
            'Authorization': sign,
            'Content-Type': 'application/json',
            'User-Agent': conf.get_ua(),
        }

        data = {'op': 'delete'}

        return self.sendRequest('POST',
                                url,
                                headers=headers,
                                data=json.dumps(data),
                                timeout=(self.connect_timeout,
                                         self.read_timeout))
Example #2
0
File: auth.py Project: why2012/QSZ
 def get_info_from_url(self, url):
     app_info = conf.get_app_info()
     end_point = app_info['end_point']
     info = urlparse(url)
     end_point_info = urlparse(end_point)
     if (info.hostname == urlparse(conf.API_VIDEO_END_POINT).hostname):
         # 非下载url
         if info.path:
             parts = info.path.split('/')
             if len(parts) >= 5:
                 cate = parts[1]
                 ver = parts[2]
                 appid = parts[3]
                 bucket = parts[4]
             fileid = ''
             for i in range(3, len(parts)):
                 fileid += parts[i]
             else:
                 return {}
             return {
                 'cate': cate,
                 'ver': ver,
                 'appid': appid,
                 'bucket': bucket,
                 'fileid': fileid
             }
         else:
             return {}
     else:
         return {}
Example #3
0
File: video.py Project: why2012/QSZ
    def __update(self, bucket, path, videoCover, title, desc, bizattr, flag):
        expired = int(time.time()) + self.EXPIRED_SECONDS
        url = self.generate_res_url(bucket, path)
        auth = Auth(self._secret_id, self._secret_key)
        sign = auth.sign_once(
            bucket, '/' + str(conf.get_app_info()['appid']) + '/' + bucket +
            '/' + path)

        headers = {
            'Authorization': sign,
            'Content-Type': 'application/json',
            'User-Agent': conf.get_ua(),
        }

        data = {'op': 'update'}
        if videoCover != None:
            data['video_cover'] = videoCover
        if bizattr != None:
            data['biz_attr'] = bizattr
        if title != None:
            data['video_title'] = title
        if desc != None:
            data['video_desc'] = desc
        if flag != None:
            data['flag'] = flag

        return self.sendRequest('POST',
                                url,
                                headers=headers,
                                data=json.dumps(data),
                                timeout=(self.connect_timeout,
                                         self.read_timeout))
Example #4
0
	def __update(self, bucket, path, videoCover, title, desc, bizattr, flag):
		expired = int(time.time()) + self.EXPIRED_SECONDS
		url = self.generate_res_url(bucket, path)
		auth = Auth(self._secret_id, self._secret_key)
		sign = auth.sign_once(bucket, '/'+str(conf.get_app_info()['appid'])+'/'+bucket+'/'+path)

		headers = {
			'Authorization':sign,
			'Content-Type':'application/json',
			'User-Agent':conf.get_ua(),
		}

		data = {'op':'update'}
		if videoCover != None:
			data['video_cover'] = videoCover
		if bizattr != None:
			data['biz_attr'] = bizattr
		if title != None:
			data['video_title'] = title
		if desc != None:
			data['video_desc'] = desc
		if flag != None:
			data['flag'] = flag

		return self.sendRequest('POST', url, headers=headers, data=json.dumps(data), timeout=(self.connect_timeout, self.read_timeout))
Example #5
0
    def app_sign(self, bucket, fileid, expired):
        app_info = conf.get_app_info()
        if not self._secret_id or not self._secret_key or not app_info['appid']:
            return self.AUTH_SECRET_ID_KEY_ERROR

        now = int(time.time())
        rdm = random.randint(0, 999999999)
        plain_text = 'a=' + app_info['appid'] + '&k=' + self._secret_id + '&e=' + str(expired) + '&t=' + str(now) + '&r=' + str(rdm) + '&f=' + fileid + '&b=' + bucket 
        bin = hmac.new(self._secret_key, plain_text, hashlib.sha1)
        s = bin.hexdigest()
        s = binascii.unhexlify(s)
        s = s + plain_text
        signature = base64.b64encode(s).rstrip()    #生成签名
        return signature
Example #6
0
File: auth.py Project: why2012/QSZ
    def app_sign(self, bucket, fileid, expired):
        app_info = conf.get_app_info()
        if not self._secret_id or not self._secret_key or not app_info['appid']:
            return self.AUTH_SECRET_ID_KEY_ERROR

        now = int(time.time())
        rdm = random.randint(0, 999999999)
        plain_text = 'a=' + app_info[
            'appid'] + '&k=' + self._secret_id + '&e=' + str(
                expired) + '&t=' + str(now) + '&r=' + str(
                    rdm) + '&f=' + fileid + '&b=' + bucket
        bin = hmac.new(self._secret_key, plain_text, hashlib.sha1)
        s = bin.hexdigest()
        s = binascii.unhexlify(s)
        s = s + plain_text
        signature = base64.b64encode(s).rstrip()  #生成签名
        return signature
Example #7
0
	def __delete(self, bucket, path):
		if path == '' or path == '/':
			return {'httpcode':0, 'code':self.VIDEO_PARAMS_ERROR, 'message':'path cannot be empty', 'data':{}}
		expired = int(time.time()) + self.EXPIRED_SECONDS
		url = self.generate_res_url(bucket, path)
		auth = Auth(self._secret_id, self._secret_key)
		sign = auth.sign_once(bucket, '/'+str(conf.get_app_info()['appid'])+'/'+bucket+'/'+path)

		headers = {
			'Authorization':sign,
			'Content-Type':'application/json',
			'User-Agent':conf.get_ua(),
		}

		data = {'op':'delete'}

		return self.sendRequest('POST', url, headers=headers, data=json.dumps(data), timeout=(self.connect_timeout, self.read_timeout))
Example #8
0
    def get_info_from_url(self, url):
        app_info = conf.get_app_info()
        end_point = app_info['end_point']
        info = urlparse(url)
        end_point_info = urlparse(end_point)
        if (info.hostname == urlparse(conf.API_VIDEO_END_POINT).hostname) :
            # 非下载url
            if info.path :
                parts = info.path.split('/')
                if len(parts) >= 5:
                    cate = parts[1]
                    ver = parts[2]
                    appid = parts[3]
                    bucket = parts[4]
		    fileid = ''
		    for i in range(3, len(parts)) :
			fileid += parts[i]
                    return {'cate':cate, 'ver':ver, 'appid':appid, 'bucket':bucket, 'fileid':fileid}
                else:
                    return {}
            else:
                return {}
        else :
            return {}
Example #9
0
File: video.py Project: why2012/QSZ
 def generate_res_url(self, bucket, dstpath):
     app_info = conf.get_app_info()
     return app_info['end_point'] + str(
         app_info['appid']) + '/' + bucket + '/' + dstpath
Example #10
0
	def generate_res_url(self, bucket, dstpath):
		app_info = conf.get_app_info()
		return app_info['end_point'] + str(app_info['appid']) + '/' + bucket + '/' + dstpath