|
@@ -45,6 +45,8 @@ from Object.UidTokenObject import UidTokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
from Service.ModelService import ModelService
|
|
|
from Object.m3u8generate import PlaylistGenerator
|
|
|
+from Model.models import Device_User, Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidPushModel
|
|
|
+
|
|
|
|
|
|
|
|
|
SERVER_DOMAIN = 'http://test.dvema.com/'
|
|
@@ -79,13 +81,17 @@ class testView(View):
|
|
|
elif operation == 'cbu':
|
|
|
return self.createBucket()
|
|
|
elif operation == 'vodList':
|
|
|
+ ip = CommonService.get_ip_address(request)
|
|
|
userID = '158943594633713800138000'
|
|
|
- return self.do_test_query_vod_list(userID, request_dict, response)
|
|
|
+ return self.do_test_query_vod_list(userID, ip, request_dict, response)
|
|
|
elif operation == 'signplaym3u8':
|
|
|
return self.do_sign_play_m3u8(request_dict, response)
|
|
|
elif operation == 'get_sign_sts':
|
|
|
ip = CommonService.get_ip_address(request)
|
|
|
return self.do_test_get_sign_sts(request_dict, ip, response)
|
|
|
+ elif operation == 'eqi_query':
|
|
|
+ userID = '158943594633713800138000'
|
|
|
+ return self.queryInterface(request_dict, userID, response)
|
|
|
else:
|
|
|
return 12344444
|
|
|
|
|
@@ -111,8 +117,81 @@ class testView(View):
|
|
|
with open('local.txt', 'wb') as f:
|
|
|
f.write(resp['Body'].read())
|
|
|
|
|
|
+ # 新查询设备字段
|
|
|
+ def queryInterface(self, request_dict, userID, response):
|
|
|
+ page = request_dict.get('page', None)
|
|
|
+ line = request_dict.get('line', None)
|
|
|
+ NickName = request_dict.get('NickName', None)
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ page = int(page)
|
|
|
+ line = int(line)
|
|
|
+ response.lang = 'cn'
|
|
|
+ userID = userID
|
|
|
+ dvqs = Device_Info.objects.filter(userID_id=userID)
|
|
|
+ # # 已重置的设备
|
|
|
+ # dvqs = dvqs.filter(~Q(isExist=2))
|
|
|
+ if NickName:
|
|
|
+ dvqs = dvqs.filter(NickName__icontains=NickName)
|
|
|
+ if uid:
|
|
|
+ dvqs = dvqs.filter(UID=uid)
|
|
|
+ # count = dvqs.count()
|
|
|
+ #分页
|
|
|
+ dvql = dvqs[(page - 1) * line:page * line].values('id', 'userID', 'NickName', 'UID', 'View_Account',
|
|
|
+ 'View_Password', 'ChannelIndex', 'Type', 'isShare',
|
|
|
+ 'primaryUserID', 'primaryMaster', 'data_joined',
|
|
|
+ 'version',
|
|
|
+ 'isVod', 'isExist', 'NotificationMode')
|
|
|
+ dvls = CommonService.qs_to_list(dvql)
|
|
|
+ uid_list = []
|
|
|
+ for dvl in dvls:
|
|
|
+ uid_list.append(dvl['UID'])
|
|
|
+ # if dvl['isShare'] is False:
|
|
|
+ # uid_list.append(dvl['UID'])
|
|
|
+ ubqs = UID_Bucket.objects.filter(uid__in=uid_list). \
|
|
|
+ values('bucket__content', 'status', 'channel', 'endTime', 'uid')
|
|
|
+ upqs = UID_Preview.objects.filter(uid__in=uid_list).order_by('channel').values('id', 'uid', 'channel')
|
|
|
+ auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
+ bucket = oss2.Bucket(auth, 'oss-cn-hongkong.aliyuncs.com', 'statres')
|
|
|
+ nowTime = int(time.time())
|
|
|
+ data = []
|
|
|
+ # 设备拓展信息表
|
|
|
+ us_qs = UidSetModel.objects.filter(uid__in=uid_list). \
|
|
|
+ values('uid', 'version', 'nickname', 'detect_interval')
|
|
|
+ uv_dict = {}
|
|
|
+ for us in us_qs:
|
|
|
+ uv_dict[us['uid']] = {'version': us['version'],
|
|
|
+ 'nickname': us['nickname'],
|
|
|
+ 'detect_interval': us['detect_interval']}
|
|
|
+ for p in dvls:
|
|
|
+ p['vod'] = []
|
|
|
+ for dm in ubqs:
|
|
|
+ if p['UID'] == dm['uid']:
|
|
|
+ if dm['endTime'] > nowTime:
|
|
|
+ p['vod'].append(dm)
|
|
|
+ p['preview'] = []
|
|
|
+ for up in upqs:
|
|
|
+ if p['UID'] == up['uid']:
|
|
|
+ obj = 'uid_preview/{uid}/channel_{channel}.png'. \
|
|
|
+ format(uid=up['uid'], channel=up['channel'])
|
|
|
+ img_sign = bucket.sign_url('GET', obj, 300)
|
|
|
+ p['preview'].append(img_sign)
|
|
|
+ p_uid = p['UID']
|
|
|
+ if p_uid in uv_dict:
|
|
|
+ # 设备版本号
|
|
|
+ p['uid_version'] = uv_dict[p_uid]['version']
|
|
|
+ p['detect_interval'] = uv_dict[p_uid]['detect_interval']
|
|
|
+ # 设备昵称 调用影子信息昵称,先阶段不可
|
|
|
+ if uv_dict[p_uid]['nickname']:
|
|
|
+ p['NickName'] = uv_dict[p_uid]['nickname']
|
|
|
+ else:
|
|
|
+ # 设备版本号
|
|
|
+ p['uid_version'] = ''
|
|
|
+ data.append(p)
|
|
|
+ return response.json(0, data)
|
|
|
+
|
|
|
|
|
|
- def do_test_query_vod_list(self, userID, request_dict, response):
|
|
|
+ #获取播放列表
|
|
|
+ def do_test_query_vod_list(self, userID, ip, request_dict, response):
|
|
|
uid = 'GZL2PEFJPLY7W6BG111A'
|
|
|
channel = 2
|
|
|
userID = '158943594633713800138000'
|
|
@@ -120,13 +199,13 @@ class testView(View):
|
|
|
if not dv_qs.exists():
|
|
|
return response.json(12)
|
|
|
vod_play_list = []
|
|
|
- bucket_name = 'awsusvod1'
|
|
|
+ bucket_name = 'azvod1'
|
|
|
aws_access_key_id = 'AKIA2E67UIMD45Y3HL53'
|
|
|
aws_secret_access_key = 'ckYLg4Lo9ZXJIcJEAKkzf2rWvs8Xth1FCjqiAqUw'
|
|
|
session = Session(
|
|
|
aws_access_key_id=aws_access_key_id,
|
|
|
aws_secret_access_key=aws_secret_access_key,
|
|
|
- region_name='us-west-1'
|
|
|
+ region_name='ap-northeast-1'
|
|
|
)
|
|
|
conn = session.client('s3')
|
|
|
thumbspng = '{uid}/vod{channel}/{time}/thumbs.png'. \
|
|
@@ -142,24 +221,24 @@ class testView(View):
|
|
|
# m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \
|
|
|
# format(uid=uid, channel=channel, time=vod['time'])
|
|
|
thumb_url = response_url
|
|
|
- vod_url = 'http://13.56.215.252:8077/testApi/signplaym3u8?' \
|
|
|
+ vod_url = 'http://192.168.136.191:8000/testApi/signplaym3u8?' \
|
|
|
'uid={uid}&channel={channel}&time={time}&sign=tktktktk'. \
|
|
|
- format(uid=uid, channel=channel, time=1590485548)
|
|
|
+ format(ip=ip, uid=uid, channel=channel, time=1590485548)
|
|
|
vod_play_list.append({
|
|
|
'name': 1590485548,
|
|
|
'sign_url': vod_url,
|
|
|
'thumb': thumb_url,
|
|
|
- 'sec': 11})
|
|
|
+ 'sec': 12})
|
|
|
return response.json(0, vod_play_list)
|
|
|
|
|
|
+ #生成m3u8列表
|
|
|
def do_sign_play_m3u8(self, request_dict, response):
|
|
|
uid = 'GZL2PEFJPLY7W6BG111A'
|
|
|
channel = 2
|
|
|
- storeTime = 1590485548
|
|
|
- sec = 11
|
|
|
- fg = 3
|
|
|
- bucket__region = 'us-west-1'
|
|
|
- bucket_name = 'awsusvod1'
|
|
|
+ storeTime = 1591344070
|
|
|
+ fg = 6
|
|
|
+ bucket__region = 'ap-northeast-1'
|
|
|
+ bucket_name = 'azvod1'
|
|
|
aws_access_key_id = 'AKIA2E67UIMD45Y3HL53'
|
|
|
aws_secret_access_key = 'ckYLg4Lo9ZXJIcJEAKkzf2rWvs8Xth1FCjqiAqUw'
|
|
|
session = Session(
|
|
@@ -182,7 +261,7 @@ class testView(View):
|
|
|
'Bucket': bucket_name,
|
|
|
'Key': thumbspng
|
|
|
},
|
|
|
- ExpiresIn=3600
|
|
|
+ ExpiresIn=86400
|
|
|
)
|
|
|
# m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \
|
|
|
# format(uid=uid, channel=channel, time=vod['time'])
|
|
@@ -190,16 +269,17 @@ class testView(View):
|
|
|
'name': response_url,
|
|
|
'duration': 10,
|
|
|
})
|
|
|
-
|
|
|
playlist = PlaylistGenerator(playlist_entries).generate()
|
|
|
- return HttpResponse(playlist)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- response = HttpResponse(playlist, content_type="application/vnd.apple.mpegurl")
|
|
|
- # response = HttpResponse(playlist, content_type="application/octet-stream")
|
|
|
+ response = HttpResponse(playlist)
|
|
|
+ response['Content-Type'] = 'application/octet-stream'
|
|
|
+ response['Content-Disposition'] = 'attachment;filename="play.m3u8"'
|
|
|
return response
|
|
|
- return HttpResponse(status=200, content=playlist)
|
|
|
+
|
|
|
+ # return HttpResponse(playlist)
|
|
|
+ # response = HttpResponse(playlist, content_type="application/vnd.apple.mpegurl")
|
|
|
+ # # response = HttpResponse(playlist, content_type="application/octet-stream")
|
|
|
+ # return response
|
|
|
+ # return HttpResponse(status=200, content=playlist)
|
|
|
|
|
|
def do_test_get_sign_sts(self, request_dict, ip, response):
|
|
|
# uid = 'GZL2PEFJPLY7W6BG111A'
|
|
@@ -564,8 +644,10 @@ class testView(View):
|
|
|
if not ubqs.exists():
|
|
|
return response.json(10, '设备未购买')
|
|
|
nowTime = int(time.time())
|
|
|
- vodqs = VodHlsModel.objects.filter(uid=uid, channel=channel, time__range=(startTime, endTime),
|
|
|
- endTime__gte=nowTime) \
|
|
|
+ # vodqs = VodHlsModel.objects.filter(uid=uid, channel=channel, time__range=(startTime, endTime),
|
|
|
+ # endTime__gte=nowTime) \
|
|
|
+ # .values("time", "sec", "bucket__bucket", "bucket__endpoint", "bucket__region")
|
|
|
+ vodqs = VodHlsModel.objects.filter(uid=uid, channel=channel) \
|
|
|
.values("time", "sec", "bucket__bucket", "bucket__endpoint", "bucket__region")
|
|
|
vod_play_list = []
|
|
|
print(vodqs)
|