|
@@ -146,6 +146,8 @@ class testView(View):
|
|
return self.write_redis_list(response)
|
|
return self.write_redis_list(response)
|
|
elif operation == 'read_redis_list':
|
|
elif operation == 'read_redis_list':
|
|
return self.read_redis_list(response)
|
|
return self.read_redis_list(response)
|
|
|
|
+ elif operation == 'playM3u8':
|
|
|
|
+ return self.play_m3u8(request_dict, response)
|
|
else:
|
|
else:
|
|
return 123
|
|
return 123
|
|
|
|
|
|
@@ -1010,3 +1012,56 @@ class testView(View):
|
|
serial = redis_obj.lpop('serial_redis_list')
|
|
serial = redis_obj.lpop('serial_redis_list')
|
|
print(serial)
|
|
print(serial)
|
|
return response.json(0)
|
|
return response.json(0)
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def play_m3u8(request_dict, response): # 根据sts播放m3u8 视频流
|
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
|
+ channel = request_dict.get('channel', None)
|
|
|
|
+ storeTime = request_dict.get('time', None)
|
|
|
|
+ now_time = int(time.time())
|
|
|
|
+ try:
|
|
|
|
+ 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(173)
|
|
|
|
+ fg = vh_qs[0]['fg']
|
|
|
|
+ bucket__region = vh_qs[0]['bucket__region']
|
|
|
|
+ bucket_name = vh_qs[0]['bucket__bucket']
|
|
|
|
+
|
|
|
|
+ session = Session(
|
|
|
|
+ aws_access_key_id=AWS_ACCESS_KEY_ID[vh_qs[0]["bucket__mold"]],
|
|
|
|
+ aws_secret_access_key=AWS_SECRET_ACCESS_KEY[vh_qs[0]["bucket__mold"]],
|
|
|
|
+ region_name=bucket__region
|
|
|
|
+ )
|
|
|
|
+ conn = session.client('s3')
|
|
|
|
+ playlist_entries = []
|
|
|
|
+ fg = int(fg)
|
|
|
|
+ # ts_count = fg & 0xf
|
|
|
|
+ # fg 64位整型,低四位代表ts文件总数,然后进行位运算,一次移四位,每四位转为十进制即为当前ts文件的秒数
|
|
|
|
+ for i in range(15):
|
|
|
|
+ shift = (i + 1) * 4
|
|
|
|
+ duration = (fg >> shift) & 0xf
|
|
|
|
+ if duration > 0:
|
|
|
|
+ tsFile = '{uid}/vod{channel}/{time}/ts{i}.ts'. \
|
|
|
|
+ format(uid=uid, channel=channel, time=storeTime, i=i)
|
|
|
|
+ response_url = conn.generate_presigned_url(
|
|
|
|
+ 'get_object',
|
|
|
|
+ Params={
|
|
|
|
+ 'Bucket': bucket_name,
|
|
|
|
+ 'Key': tsFile
|
|
|
|
+ },
|
|
|
|
+ ExpiresIn=24*60*60
|
|
|
|
+ )
|
|
|
|
+ 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:
|
|
|
|
+ print(e)
|
|
|
|
+ return response.json(500, repr(e))
|