浏览代码

fix:增加filtervod接口,根据时间戳获取

chenjunkai 6 年之前
父节点
当前提交
b9be4d47f9
共有 1 个文件被更改,包括 44 次插入0 次删除
  1. 44 0
      Controller/CloudVod.py

+ 44 - 0
Controller/CloudVod.py

@@ -113,6 +113,8 @@ class CloudVodView(View):
                 return self.do_get_details(request_dict, response)
             elif operation == 'queryVod':
                 return self.do_query_vod(request_dict, userID, response)
+            elif operation == 'filterVod':
+                return self.do_filter_playlist(request_dict, userID, response)
             else:
                 return response.json(414)
 
@@ -558,6 +560,48 @@ class CloudVodView(View):
             vod_play_list.append({'name': vod['time'], 'sign_url': vod_play_url, 'thumb': thumb, 'sec': vod['sec']})
         return response.json(0, vod_play_list)
 
+    def do_filter_playlist(self, request_dict, userID, response):
+        startTime = int(request_dict.get('startTime', None))
+        endTime = int(request_dict.get('endTime', None))
+        did = request_dict.get('did', None)
+        channel = request_dict.get('channel', None)
+        dvqs = Device_Info.objects.filter(id=did, userID_id=userID, isShare=False).values("UID")
+        if not dvqs.exists():
+            return response.json(12)
+        UID = dvqs[0]["UID"]
+        ubqs = UID_Bucket.objects.filter(uid=UID, channel=channel).values('status')
+        if not ubqs.exists():
+            return response.json(10, '设备未购买')
+        nowTime = CommonService.get_utc()
+        vodqs = VodHlsModel.objects.filter(uid=UID, channel=channel, time__range=(startTime, endTime),
+                                           endTime__gte=nowTime) \
+            .values("time", "sec", "bucket__bucket", "bucket__endpoint", "bucket__region")
+        vod_play_list = []
+        print(vodqs)
+        for vod in vodqs:
+            bucket_name = vod["bucket__bucket"]
+            endpoint = vod["bucket__endpoint"]
+            auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
+            bucket = oss2.Bucket(auth, endpoint, bucket_name)
+            # m3u8 = '{uid}/vod{channel}/{daytime}/{time}/{time}.m3u8'. \
+            #     format(uid=UID, channel=channel, daytime=daytime, time=vod['time'])
+            # ts = '{uid}/vod{channel}/{daytime}/{time}/ts0.ts'. \
+            #     format(uid=UID, channel=channel, daytime=daytime, time=vod['time'])
+            m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \
+                format(uid=UID, channel=channel, time=vod['time'])
+            ts = '{uid}/vod{channel}/{time}/ts0.ts'. \
+                format(uid=UID, channel=channel, time=vod['time'])
+            url = bucket.sign_url('GET', m3u8, 3600, params={'x-oss-process': 'hls/sign'})
+            urllst = url.split('?')
+            url_start = urllib.parse.unquote(urllst[0])
+            url_end = urllst[1]
+            vod_play_url = '{url_start}?{url_end}'. \
+                format(url_start=url_start, url_end=url_end)
+            thumb = bucket.sign_url('GET', ts, 3600,
+                                    params={'x-oss-process': 'video/snapshot,t_10000,m_fast,w_300'})
+            vod_play_list.append({'name': vod['time'], 'sign_url': vod_play_url, 'thumb': thumb, 'sec': vod['sec']})
+        return response.json(0, vod_play_list)
+
     def do_query_vod(self, request_dict, userID, response):
         page = request_dict.get('page', None)
         line = request_dict.get('line', None)