|
@@ -6,6 +6,7 @@
|
|
"""
|
|
"""
|
|
from Ansjer.config import LOGGER
|
|
from Ansjer.config import LOGGER
|
|
import time
|
|
import time
|
|
|
|
+import jwt
|
|
|
|
|
|
from django.db.models import Sum, Q
|
|
from django.db.models import Sum, Q
|
|
from django.http import HttpResponse
|
|
from django.http import HttpResponse
|
|
@@ -17,7 +18,8 @@ from Object.RedisObject import RedisObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
from Ansjer.config import ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION_NAME, SERVER_DOMAIN, AWS_ACCESS_KEY_ID, \
|
|
from Ansjer.config import ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION_NAME, SERVER_DOMAIN, AWS_ACCESS_KEY_ID, \
|
|
- AWS_SECRET_ACCESS_KEY, SERVER_DOMAIN_SSL
|
|
|
|
|
|
+ AWS_SECRET_ACCESS_KEY, SERVER_DOMAIN_SSL, OAUTH_ACCESS_TOKEN_SECRET
|
|
|
|
+from Object.m3u8generate import PlaylistGenerator
|
|
from Service.VodHlsService import SplitVodHlsObject
|
|
from Service.VodHlsService import SplitVodHlsObject
|
|
|
|
|
|
|
|
|
|
@@ -49,6 +51,8 @@ class IcloudServiceView(View):
|
|
return self.delete_icloud_record(request_dict, response, user_id)
|
|
return self.delete_icloud_record(request_dict, response, user_id)
|
|
elif operation == 'getIcloudList': # 获取云盘播放列表
|
|
elif operation == 'getIcloudList': # 获取云盘播放列表
|
|
return self.get_icloud_list(request_dict, response, user_id)
|
|
return self.get_icloud_list(request_dict, response, user_id)
|
|
|
|
+ elif operation == 'icloudPlay': # 云盘播放
|
|
|
|
+ return self.icloud_play(request_dict, response, user_id)
|
|
else:
|
|
else:
|
|
return response.json(404)
|
|
return response.json(404)
|
|
|
|
|
|
@@ -369,7 +373,7 @@ class IcloudServiceView(View):
|
|
use_details_qs.update(use_size=new_size)
|
|
use_details_qs.update(use_size=new_size)
|
|
return response.json(0)
|
|
return response.json(0)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- LOGGER.info('获取s3上传地址异常:{}'.format(repr(e)))
|
|
|
|
|
|
+ LOGGER.info('删除云盘记录异常:{}'.format(repr(e)))
|
|
return response.json(500)
|
|
return response.json(500)
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
@@ -463,7 +467,7 @@ class IcloudServiceView(View):
|
|
response_url = s3_obj.generate_file_obj_url(bucket_name, thumbs_png)
|
|
response_url = s3_obj.generate_file_obj_url(bucket_name, thumbs_png)
|
|
ts_num = int(item['fg']) & 0xf
|
|
ts_num = int(item['fg']) & 0xf
|
|
res_data['thumb'] = response_url
|
|
res_data['thumb'] = response_url
|
|
- icloud_url = '{server_domain}icloud/service/icloudPlayUrl?' \
|
|
|
|
|
|
+ icloud_url = '{server_domain}icloud/service/icloudPlay?' \
|
|
'uid={uid}&channel={channel}&time_stamp={time_stamp}&file_type=1&sign=tktktktk'. \
|
|
'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)
|
|
format(server_domain=SERVER_DOMAIN_SSL, uid=uid_token, channel=channel, time_stamp=time_stamp)
|
|
res_data['ts_num'] = ts_num
|
|
res_data['ts_num'] = ts_num
|
|
@@ -471,13 +475,78 @@ class IcloudServiceView(View):
|
|
res_data['sec'] = item['sec']
|
|
res_data['sec'] = item['sec']
|
|
icloud_list.append(res_data)
|
|
icloud_list.append(res_data)
|
|
elif file_type == 2: # mp4文件,返回播放地址
|
|
elif file_type == 2: # mp4文件,返回播放地址
|
|
- 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
|
|
|
|
|
|
+ mp4_file = '{user_id}/mp4_file/{uid}/channel{channel}/{time}/{time}.mp4'.format(
|
|
|
|
+ user_id=user_id,
|
|
|
|
+ uid=uid,
|
|
|
|
+ channel=channel,
|
|
|
|
+ time=time_stamp)
|
|
|
|
+ response_url = s3_obj.generate_file_obj_url(bucket_name, mp4_file)
|
|
|
|
+ res_data['icloud_url'] = response_url
|
|
res_data['sec'] = item['sec']
|
|
res_data['sec'] = item['sec']
|
|
icloud_list.append(res_data)
|
|
icloud_list.append(res_data)
|
|
return response.json(0, icloud_list)
|
|
return response.json(0, icloud_list)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- LOGGER.info('获取s3上传地址异常:{}'.format(repr(e)))
|
|
|
|
|
|
+ LOGGER.info('获取云盘播放列表异常:{}'.format(repr(e)))
|
|
|
|
+ return response.json(500)
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def icloud_play(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('播放云盘记录')
|
|
|
|
+ time_stamp = request_dict.get('time_stamp', None)
|
|
|
|
+ uid_token = request_dict.get('uid', None)
|
|
|
|
+ channel = request_dict.get('channel', None)
|
|
|
|
+ file_type = request_dict.get('file_type', None)
|
|
|
|
+ if not all([time_stamp, uid_token, channel, file_type]):
|
|
|
|
+ return response.json(444, {'error param': 'time_stamp, uid_token, channel, file_type'})
|
|
|
|
+ if file_type != '1':
|
|
|
|
+ return response.json(444, {'error param': 'file_type'})
|
|
|
|
+ uid = jwt.decode(uid_token, OAUTH_ACCESS_TOKEN_SECRET, algorithms='HS256').get('uid', '')
|
|
|
|
+ icloud_record_qs = IcloudStorageRecord.objects.filter(user_id=user_id, uid=uid, channel=channel,
|
|
|
|
+ file_type=file_type,
|
|
|
|
+ time_stamp=time_stamp).values('bucket_id', 'fg')
|
|
|
|
+ if not icloud_record_qs.exists():
|
|
|
|
+ return response.json(173)
|
|
|
|
+ bucket_id = icloud_record_qs[0]['bucket_id']
|
|
|
|
+ fg = int(icloud_record_qs[0]['fg'])
|
|
|
|
+ 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']
|
|
|
|
+ try:
|
|
|
|
+ s3_obj = AmazonS3Util(
|
|
|
|
+ AWS_ACCESS_KEY_ID[mold],
|
|
|
|
+ AWS_SECRET_ACCESS_KEY[mold],
|
|
|
|
+ bucket_region
|
|
|
|
+ )
|
|
|
|
+ playlist_entries = []
|
|
|
|
+ for i in range(15):
|
|
|
|
+ shift = (i + 1) * 4
|
|
|
|
+ duration = (fg >> shift) & 0xf
|
|
|
|
+ if duration > 0:
|
|
|
|
+ ts_file = '{user_id}/ts_file/{uid}/channel{channel}/{time_stamp}/ts{i}.ts'.format(
|
|
|
|
+ user_id=user_id, uid=uid, channel=channel, time_stamp=time_stamp, i=i)
|
|
|
|
+ response_url = s3_obj.generate_file_obj_url(bucket_name, ts_file)
|
|
|
|
+ playlist_entries.append({
|
|
|
|
+ 'name': response_url,
|
|
|
|
+ 'duration': duration,
|
|
|
|
+ })
|
|
|
|
+ playlist = PlaylistGenerator(playlist_entries).generate()
|
|
|
|
+ response = HttpResponse(playlist)
|
|
|
|
+ response['Content-Type'] = 'application/octet-stream'
|
|
|
|
+ response['Content-Disposition'] = 'attachment;filename="play.m3u8"'
|
|
|
|
+ return response
|
|
|
|
+ except Exception as e:
|
|
|
|
+ LOGGER.info('云盘播放异常:{}'.format(repr(e)))
|
|
return response.json(500)
|
|
return response.json(500)
|