|
@@ -32,6 +32,7 @@ from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Object.UidTokenObject import UidTokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
+from Object.m3u8generate import PlaylistGenerator
|
|
|
|
|
|
SERVER_DOMAIN = 'http://cloudstroage.dvema.com/'
|
|
|
|
|
@@ -62,8 +63,8 @@ class CloudStorageView(View):
|
|
|
return self.do_get_sign_sts(request_dict, ip, response)
|
|
|
elif operation == 'storeplaylist':
|
|
|
return self.do_store_playlist(request_dict, response)
|
|
|
- elif operation == 'getsignurl/play.m3u8':
|
|
|
- return self.do_get_sign_url_m3u8(request_dict, response)
|
|
|
+ elif operation == 'signplaym3u8':
|
|
|
+ return self.do_sign_play_m3u8(request_dict, response)
|
|
|
else:
|
|
|
token = request_dict.get('token', None)
|
|
|
# 设备主键uid
|
|
@@ -81,8 +82,49 @@ class CloudStorageView(View):
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
|
- def do_get_sign_url_m3u8(self, request_dict, response):
|
|
|
- return
|
|
|
+ def do_sign_play_m3u8(self, request_dict, response):
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ channel = request_dict.get('channel', None)
|
|
|
+ storeTime = request_dict.get('time', None)
|
|
|
+ now_time = int(time.time())
|
|
|
+ vh_qs = VodHlsModel.objects.filter(uid=uid, channel=channel, time=storeTime, endTime__gte=now_time). \
|
|
|
+ values("sec", "fg", "bucket__bucket", "bucket__endpoint", "bucket__region", "bucket__mold")
|
|
|
+ if not vh_qs.exists():
|
|
|
+ return response.json()
|
|
|
+ sec = vh_qs[0]['sec']
|
|
|
+ fg = vh_qs[0]['fg']
|
|
|
+ bucket__region = vh_qs[0]['bucket__region']
|
|
|
+ bucket_name = vh_qs[0]['bucket__bucket']
|
|
|
+ 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=bucket__region
|
|
|
+ )
|
|
|
+ conn = session.client('s3')
|
|
|
+ playlist_entries = []
|
|
|
+ for i in range(fg):
|
|
|
+ thumbspng = '{uid}/vod{channel}/{time}/thumbs.png'. \
|
|
|
+ format(uid=uid, channel=channel, time=storeTime)
|
|
|
+ response_url = conn.generate_presigned_url(
|
|
|
+ 'get_object',
|
|
|
+ Params={
|
|
|
+ 'Bucket': bucket_name,
|
|
|
+ 'Key': thumbspng
|
|
|
+ },
|
|
|
+ ExpiresIn=3600
|
|
|
+ )
|
|
|
+ # m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \
|
|
|
+ # format(uid=uid, channel=channel, time=vod['time'])
|
|
|
+ playlist_entries = [
|
|
|
+ {
|
|
|
+ 'name': response_url,
|
|
|
+ 'duration': 10,
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ playlist = PlaylistGenerator(playlist_entries).generate()
|
|
|
+ return HttpResponse(status=200, content=playlist)
|
|
|
|
|
|
def do_get_sign_sts(self, request_dict, ip, response):
|
|
|
uidToken = request_dict.get('uidToken', None)
|
|
@@ -287,7 +329,7 @@ class CloudStorageView(View):
|
|
|
# m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \
|
|
|
# format(uid=uid, channel=channel, time=vod['time'])
|
|
|
thumb_url = response_url
|
|
|
- vod_url = 'http://cloudstroage.dvema.com/getsignurl/play.m3u8?uid={uid}&channel={channel}&time={time}&sign=tktktktk'. \
|
|
|
+ vod_url = 'http://cloudstroage.dvema.com/cloudstorage/signplaym3u8?uid={uid}&channel={channel}&time={time}&sign=tktktktk'. \
|
|
|
format(uid=uid, channel=channel, time=time)
|
|
|
vod_play_list.append({
|
|
|
'name': vod['time'],
|
|
@@ -296,7 +338,6 @@ class CloudStorageView(View):
|
|
|
'sec': vod['sec']})
|
|
|
return response.json(0, vod_play_list)
|
|
|
|
|
|
-
|
|
|
def do_store_playlist(self, request_dict, response):
|
|
|
uidToken = request_dict.get('uidToken', None)
|
|
|
storeTime = request_dict.get('time', None)
|