浏览代码

更新播放列表

lang 4 年之前
父节点
当前提交
0cadafe749
共有 2 个文件被更改,包括 41 次插入20 次删除
  1. 40 19
      Controller/CloudStorage.py
  2. 1 1
      Model/models.py

+ 40 - 19
Controller/CloudStorage.py

@@ -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': sec,
-            })
+        # 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'
@@ -470,9 +491,9 @@ class CloudStorageView(View):
                 # 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'])
                 vod_play_list.append({
                     'name': vod['time'],
                     'sign_url': vod_url,

+ 1 - 1
Model/models.py

@@ -555,7 +555,7 @@ class VodHlsModel(models.Model):
     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.IntegerField(default=0,verbose_name='时间描述片段数') # 阿里为时间片段数
+    fg = models.IntegerField(default=0,verbose_name='时间描述片段数') # 阿里为时间片段数,亚马逊为一个32bit整型,前28bit代表ts文件的时长
 
 
     def __str__(self):