|
@@ -17,7 +17,7 @@ from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Ansjer.config import ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION_NAME, SERVER_DOMAIN, AWS_ACCESS_KEY_ID, \
|
|
|
- AWS_SECRET_ACCESS_KEY
|
|
|
+ AWS_SECRET_ACCESS_KEY, SERVER_DOMAIN_SSL
|
|
|
from Service.VodHlsService import SplitVodHlsObject
|
|
|
|
|
|
|
|
@@ -47,6 +47,8 @@ class IcloudServiceView(View):
|
|
|
return self.local_upload(request_dict, response, user_id)
|
|
|
elif operation == 'deleteIcloudRecord': # 删除云盘记录
|
|
|
return self.delete_icloud_record(request_dict, response, user_id)
|
|
|
+ elif operation == 'getIcloudList': # 获取云盘播放列表
|
|
|
+ return self.get_icloud_list(request_dict, response, user_id)
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
|
|
@@ -116,6 +118,12 @@ class IcloudServiceView(View):
|
|
|
AWS_SECRET_ACCESS_KEY[mold],
|
|
|
bucket_region
|
|
|
)
|
|
|
+ # 获取视频封面
|
|
|
+ thumbs_png = '{uid}/vod{channel}/{time}/Thumb.jpeg'.format(uid=uid, channel=channel, time=time_stamp)
|
|
|
+ thumbs_png_size = s3_obj.get_object_size(source_bucket_name, thumbs_png)
|
|
|
+ if thumbs_png_size:
|
|
|
+ ts_size += thumbs_png_size
|
|
|
+ ts_list.append(thumbs_png)
|
|
|
# 获取s3对象,并计算总字节
|
|
|
for i in range(15):
|
|
|
shift = (i + 1) * 4
|
|
@@ -137,11 +145,11 @@ class IcloudServiceView(View):
|
|
|
if not icloud_record_qs.exists(): # 转移云盘,并记录上传记录,更新使用容量
|
|
|
for source_key in ts_list:
|
|
|
ts_name = source_key.split('/')[-1]
|
|
|
- target_key = '{user_id}/ts_file/{uid}/vod{channel}/{time}/{ts_name}'.format(user_id=user_id,
|
|
|
- uid=uid,
|
|
|
- channel=channel,
|
|
|
- time=time_stamp,
|
|
|
- ts_name=ts_name)
|
|
|
+ target_key = '{user_id}/ts_file/{uid}/channel{channel}/{time}/{ts_name}'.format(user_id=user_id,
|
|
|
+ uid=uid,
|
|
|
+ channel=channel,
|
|
|
+ time=time_stamp,
|
|
|
+ ts_name=ts_name)
|
|
|
s3_obj.copy_single_obj(source_bucket_name, source_key, target_bucket_name, target_key)
|
|
|
|
|
|
IcloudStorageRecord.objects.create(user_id=user_id, uid=uid, channel=channel, time_stamp=time_stamp,
|
|
@@ -274,13 +282,15 @@ class IcloudServiceView(View):
|
|
|
bucket_region
|
|
|
)
|
|
|
if file_type == '0': # 图片
|
|
|
- key_name = '{user_id}/image_file/{uid}/{channel}/{time}/{time}.jpg'.format(user_id=user_id, uid=uid,
|
|
|
- channel=channel,
|
|
|
- time=time_stamp)
|
|
|
+ key_name = '{user_id}/image_file/{uid}/channel{channel}/{time}/{time}.jpeg'.format(user_id=user_id,
|
|
|
+ uid=uid,
|
|
|
+ channel=channel,
|
|
|
+ time=time_stamp)
|
|
|
elif file_type == '2':
|
|
|
- key_name = '{user_id}/mp4_file/{uid}/{channel}/{time}/{time}.mp4'.format(user_id=user_id, uid=uid,
|
|
|
- channel=channel,
|
|
|
- time=time_stamp)
|
|
|
+ key_name = '{user_id}/mp4_file/{uid}/channel{channel}/{time}/{time}.mp4'.format(user_id=user_id,
|
|
|
+ uid=uid,
|
|
|
+ channel=channel,
|
|
|
+ time=time_stamp)
|
|
|
else:
|
|
|
return response.json(444, {'error param': 'file_type'})
|
|
|
upload_url = s3_obj.generate_put_obj_url(bucket_name, key_name)
|
|
@@ -298,6 +308,7 @@ class IcloudServiceView(View):
|
|
|
@request_dict time_stamp: 时间戳
|
|
|
@request_dict uid: 设备uid
|
|
|
@request_dict channel: 设备通道
|
|
|
+ @request_dict file_type: 文件类型
|
|
|
@param response: 响应对象
|
|
|
@return: response
|
|
|
"""
|
|
@@ -360,3 +371,112 @@ class IcloudServiceView(View):
|
|
|
except Exception as e:
|
|
|
LOGGER.info('获取s3上传地址异常:{}'.format(repr(e)))
|
|
|
return response.json(500)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def get_icloud_list(request_dict, response, user_id):
|
|
|
+ """
|
|
|
+ 获取云盘播放列表
|
|
|
+ @param request_dict: 请求参数
|
|
|
+ @param user_id: 用户id
|
|
|
+ @request_dict time_stamp: 时间戳
|
|
|
+ @request_dict uid: 设备uid
|
|
|
+ @request_dict channel: 设备通道
|
|
|
+ @param response: 响应对象
|
|
|
+ @return: response
|
|
|
+ """
|
|
|
+ LOGGER.info('删除云盘记录')
|
|
|
+ start_time = request_dict.get('start_time', None)
|
|
|
+ end_time = request_dict.get('end_time', None)
|
|
|
+ nick_name = request_dict.get('nick_name', None)
|
|
|
+ file_type = request_dict.get('file_type', None)
|
|
|
+ page = request_dict.get('page', None)
|
|
|
+ line = request_dict.get('line', None)
|
|
|
+ if not all([page, line]):
|
|
|
+ return response.json(444, {'error param': 'page, line'})
|
|
|
+ page = int(page)
|
|
|
+ line = int(line)
|
|
|
+ now_time = int(time.time())
|
|
|
+ icloud_list = []
|
|
|
+ use_details_qs = IcloudUseDetails.objects.filter(user_id=user_id).values('id')
|
|
|
+ if not use_details_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ use_details_id = use_details_qs[0]['id']
|
|
|
+ all_size = IcloudService.objects.filter(Q(use_details_id=use_details_id), Q(use_status=0),
|
|
|
+ Q(end_time__gt=now_time) | Q(end_time=0)).values(
|
|
|
+ 'size').aggregate(total_size=Sum('size'))['total_size']
|
|
|
+ all_size = all_size * 1024 if all_size else 0 # 转换单位为MB
|
|
|
+ icloud_record_qs = IcloudStorageRecord.objects.filter(user_id=user_id)
|
|
|
+ if start_time and end_time: # 按时间段查询
|
|
|
+ icloud_record_qs = icloud_record_qs.filter(time_stamp__gte=start_time, time_stamp__lt=end_time)
|
|
|
+ if nick_name: # 按设备昵称查询
|
|
|
+ icloud_record_qs = icloud_record_qs.filter(nickname=nick_name)
|
|
|
+ if file_type: # 按文件类型查询
|
|
|
+ icloud_record_qs = icloud_record_qs.filter(file_type=file_type)
|
|
|
+ icloud_record_qs = icloud_record_qs.values('bucket_id', 'sec', 'fg', 'nickname', 'uid', 'channel', 'size', 'id',
|
|
|
+ 'time_stamp').order_by('-time_stamp')[(page - 1) * line:page * line]
|
|
|
+ if not icloud_record_qs.exists():
|
|
|
+ return response.json(0, icloud_list)
|
|
|
+ bucket_id = icloud_record_qs[0]['bucket_id']
|
|
|
+ bucket_qs = VodBucketModel.objects.filter(id=bucket_id).values('bucket', 'region', 'mold')
|
|
|
+ if not bucket_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ bucket_name = bucket_qs[0]['bucket']
|
|
|
+ bucket_region = bucket_qs[0]['region']
|
|
|
+ mold = bucket_qs[0]['mold']
|
|
|
+ total_size = 0
|
|
|
+ try:
|
|
|
+ s3_obj = AmazonS3Util(
|
|
|
+ AWS_ACCESS_KEY_ID[mold],
|
|
|
+ AWS_SECRET_ACCESS_KEY[mold],
|
|
|
+ bucket_region
|
|
|
+ )
|
|
|
+ for item in icloud_record_qs:
|
|
|
+ uid = item['uid']
|
|
|
+ channel = item['channel']
|
|
|
+ time_stamp = item['time_stamp']
|
|
|
+ total_size += float(item['size'])
|
|
|
+ uid_token = TokenObject().encryption(data={'uid': uid})
|
|
|
+ res_data = {
|
|
|
+ 'is_show': 1 if total_size < all_size else 0,
|
|
|
+ 'time_stamp': time_stamp,
|
|
|
+ 'icloud_id': item['id'],
|
|
|
+ }
|
|
|
+ if file_type == '0': # 图片
|
|
|
+ res_data['file_type'] = 0
|
|
|
+ thumbs_png = '{user_id}/image_file/{uid}/channel{channel}/{time}/{time}.jpeg'.format(
|
|
|
+ user_id=user_id,
|
|
|
+ uid=uid,
|
|
|
+ channel=channel,
|
|
|
+ time=time_stamp)
|
|
|
+ response_url = s3_obj.generate_file_obj_url(bucket_name, thumbs_png)
|
|
|
+ res_data['thumb'] = response_url
|
|
|
+ icloud_list.append(res_data)
|
|
|
+ elif file_type == '1': # ts文件
|
|
|
+ res_data['file_type'] = 1
|
|
|
+ thumbs_png = '{user_id}/image_file/{uid}/channel{channel}/{time}/{time}.jpeg'.format(
|
|
|
+ user_id=user_id,
|
|
|
+ uid=uid,
|
|
|
+ channel=channel,
|
|
|
+ time=time_stamp)
|
|
|
+ response_url = s3_obj.generate_file_obj_url(bucket_name, thumbs_png)
|
|
|
+ ts_num = int(item['fg']) & 0xf
|
|
|
+ res_data['thumb'] = response_url
|
|
|
+ icloud_url = '{server_domain}icloud/service/icloudPlayUrl?' \
|
|
|
+ 'uid={uid}&channel={channel}&time_stamp={time_stamp}&file_type=1&sign=tktktktk'. \
|
|
|
+ format(server_domain=SERVER_DOMAIN_SSL, uid=uid_token, channel=channel, time_stamp=time_stamp)
|
|
|
+ res_data['ts_num'] = ts_num
|
|
|
+ res_data['icloud_url'] = icloud_url
|
|
|
+ res_data['sec'] = item['sec']
|
|
|
+ icloud_list.append(res_data)
|
|
|
+ elif file_type == '2': # mp4文件
|
|
|
+ res_data['file_type'] = 2
|
|
|
+ icloud_url = '{server_domain}icloud/service/icloudPlayUrl?' \
|
|
|
+ 'uid={uid}&channel={channel}&time_stamp={time_stamp}&file_type=1&sign=tktktktk'. \
|
|
|
+ format(server_domain=SERVER_DOMAIN_SSL, uid=uid_token, channel=channel, time_stamp=time_stamp)
|
|
|
+ res_data['icloud_url'] = icloud_url
|
|
|
+ res_data['sec'] = item['sec']
|
|
|
+ icloud_list.append(res_data)
|
|
|
+ return response.json(0, icloud_list)
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.info('获取s3上传地址异常:{}'.format(repr(e)))
|
|
|
+ return response.json(500)
|