浏览代码

update field

lang 4 年之前
父节点
当前提交
53e1c3f401
共有 2 个文件被更改,包括 54 次插入36 次删除
  1. 52 34
      Controller/CloudStorage.py
  2. 2 2
      Model/models.py

+ 52 - 34
Controller/CloudStorage.py

@@ -207,7 +207,7 @@ class CloudStorageView(View):
         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(11,'不存在')
+            return response.json(11,'不存在.')
         sec = vh_qs[0]['sec']
         fg = vh_qs[0]['fg']
         bucket__region = vh_qs[0]['bucket__region']
@@ -226,23 +226,44 @@ class CloudStorageView(View):
         '''
         conn = session.client('s3')
         playlist_entries = []
-        for i in range(fg):
-            thumbspng = '{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': thumbspng
-                },
-                ExpiresIn=3600
-            )
-            # m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \
-            #     format(uid=uid, channel=channel, time=vod['time'])
-            playlist_entries.append({
-                'name': response_url,
-                'duration': 10,
-            })
+        # for i in range(fg):
+        #     thumbspng = '{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': thumbspng
+        #         },
+        #         ExpiresIn=3600
+        #     )
+        #     # m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \
+        #     #     format(uid=uid, channel=channel, time=vod['time'])
+        #     playlist_entries.append({
+        #         'name': response_url,
+        #         'duration': sec,
+        #     })
+        for i in range(7):
+            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=3600
+                )
+                # m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \
+                #     format(uid=uid, channel=channel, time=vod['time'])
+                playlist_entries.append({
+                    'name': response_url,
+                    'duration': duration,
+                })
+
         playlist = PlaylistGenerator(playlist_entries).generate()
         response = HttpResponse(playlist)
         response['Content-Type'] = 'application/octet-stream'
@@ -411,18 +432,15 @@ class CloudStorageView(View):
         endTime = int(request_dict.get('endTime', None))
         uid = request_dict.get('uid', None)
         channel = request_dict.get('channel', None)
+
         dv_qs = Device_Info.objects.filter(UID=uid, userID_id=userID, isShare=False)
         if not dv_qs.exists():
             return response.json(12)
         now_time = int(time.time())
-        vh_qs = VodHlsModel.objects.filter\
-            (uid=uid, channel=channel, time__range=(startTime, endTime), endTime__gte=now_time). \
-            values("time", "sec", "bucket__bucket", "bucket__endpoint", "bucket__region", "bucket__mold")
+        vh_qs = VodHlsModel.objects.filter \
+            ( uid=uid, channel=channel, time__range=(startTime, endTime), endTime__gte=now_time). \
+            values("time", "sec", "bucket__bucket", "fg", "bucket__endpoint", "bucket__region", "bucket__mold")
         vod_play_list = []
-        print("-------------vh_qs")
-        print(vh_qs)
-        auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
-        print('--------------bigin')
         print(int(time.time()))
         for vod in vh_qs:
             bucket__mold = vod["bucket__mold"]
@@ -430,6 +448,7 @@ class CloudStorageView(View):
             endpoint = vod["bucket__endpoint"]
             bucket__region = vod["bucket__region"]
             if bucket__mold == 0:
+                auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
                 bucket = oss2.Bucket(auth, endpoint, bucket_name)
                 m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \
                     format(uid=uid, channel=channel, time=vod['time'])
@@ -453,7 +472,7 @@ class CloudStorageView(View):
                 #     region_name=bucket__region
                 # )
                 # conn = session.client('s3')
-                # thumbspng = '{uid}/vod{channel}/{time}/thumbs.jpg'. \
+                # thumbspng = '{uid}/vod{channel}/{time}/Thumb.jpeg'. \
                 #     format(uid=uid, channel=channel, time=vod['time'])
                 # response_url = conn.generate_presigned_url(
                 #     'get_object',
@@ -464,18 +483,17 @@ class CloudStorageView(View):
                 #     ExpiresIn=3600
                 # )
                 # thumb_url = response_url
-                # m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \
-                #     format(uid=uid, channel=channel, time=vod['time'])
-                vod_url = 'http://test.dvema.com/cloudstorage/signplaym3u8?' \
+
+                vod_url = '{server_domain}/cloudstorage/signplaym3u8?' \
                           'uid={uid}&channel={channel}&time={time}&sign=tktktktk'. \
-                    format(uid=uid, channel=channel, time=vod['time'])
+                    format(server_domain=SERVER_DOMAIN,uid=uid, channel=channel, time=vod['time'])
+                ts_num = vod['fg'] & 0xf
                 vod_play_list.append({
                     'name': vod['time'],
                     'sign_url': vod_url,
                     # 'thumb': thumb_url,
-                    'sec': vod['sec']})
-        print('--------------end')
-        print(int(time.time()))
+                    'sec': vod['sec'],
+                    'ts_num' : ts_num}),
         return response.json(0, vod_play_list)
 
     def do_store_playlist(self, request_dict, response):
@@ -875,7 +893,7 @@ class CloudStorageView(View):
         pay_type = int(request_dict.get('pay_type', None))
         rank = request_dict.get('rank', None)
 
-        if uid == None or channel == None or commodity_code == None or pay_type == None or rank == None:
+        if not uid or not channel or not commodity_code or not rank:
             return response.json(13, '参数有误.')
         dv_qs = Device_Info.objects.filter(userID_id=userID, UID=uid, isShare=False, isExist=1)
         if not dv_qs.exists():

+ 2 - 2
Model/models.py

@@ -549,14 +549,14 @@ class Order_Model(models.Model):
 
 class VodHlsModel(models.Model):
     id = models.AutoField(primary_key=True, verbose_name='回放列表主键')
-    uid = models.CharField(max_length=20, verbose_name='设备UID')
+    uid = models.CharField(max_length=20, verbose_name='设备UID', db_index=True)
     channel = models.SmallIntegerField(default=0, verbose_name='通道')
     time = models.IntegerField(verbose_name='播放列表名字时间戳', default=0, db_index=True)
     endTime = models.IntegerField(verbose_name='删除时间', default=0)
     sec = models.IntegerField(verbose_name='秒数', default=0)
     bucket = models.ForeignKey(VodBucketModel, blank=True, to_field='id', on_delete=models.CASCADE, default=1,
                                verbose_name='存储空间')
-    fg = models.SmallIntegerField(default=0,verbose_name='时间片段数') # 0为阿里云存储方案 >0为亚马逊方案
+    fg = models.IntegerField(default=0,verbose_name='时间描述片段数') # 阿里为时间片段数,亚马逊为一个32bit整型,前28bit代表ts文件的时长
 
 
     def __str__(self):