获取大华视频rtsp流
This commit is contained in:
parent
e172f9b67a
commit
8ac24740db
|
@ -46,7 +46,8 @@ class DhClient:
|
||||||
'client_id': self.client_id,
|
'client_id': self.client_id,
|
||||||
'client_secret': self.client_secret
|
'client_secret': self.client_secret
|
||||||
}
|
}
|
||||||
is_ok, res = self.request(**dhapis['token_login'], params=params, raise_exception=False, timeout=10)
|
is_ok, res = self.request(
|
||||||
|
**dhapis['token_login'], params=params, raise_exception=False, timeout=10)
|
||||||
if is_ok == 'success':
|
if is_ok == 'success':
|
||||||
cache.set('dh_token', res['access_token'], timeout=None)
|
cache.set('dh_token', res['access_token'], timeout=None)
|
||||||
self.isGetingToken = False
|
self.isGetingToken = False
|
||||||
|
@ -78,7 +79,8 @@ class DhClient:
|
||||||
detail = '大华错误:' + \
|
detail = '大华错误:' + \
|
||||||
'{}|{}{}{}'.format(str(ret['code']), ret.get('errMsg', ''),
|
'{}|{}{}{}'.format(str(ret['code']), ret.get('errMsg', ''),
|
||||||
ret.get('desc', ''), str(ret.get('data', '')))
|
ret.get('desc', ''), str(ret.get('data', '')))
|
||||||
err_detail = dict(detail=detail, code='dh_'+str(ret['code']))
|
err_detail = dict(
|
||||||
|
detail=detail, code='dh_'+str(ret['code']))
|
||||||
self.handle_log(result='fail', response=ret)
|
self.handle_log(result='fail', response=ret)
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise ParseError(**err_detail)
|
raise ParseError(**err_detail)
|
||||||
|
@ -134,7 +136,8 @@ class DhClient:
|
||||||
num = d_code_list[-1]
|
num = d_code_list[-1]
|
||||||
json_data['deviceCode'] = d_code
|
json_data['deviceCode'] = d_code
|
||||||
json_data['params'] = '{\"method\":\"dev.snap\",\"id\":123,\"params\":{\"DevID\":\"' + \
|
json_data['params'] = '{\"method\":\"dev.snap\",\"id\":123,\"params\":{\"DevID\":\"' + \
|
||||||
str(d_code) + '\",\"DevChannel\":' + str(num) + ',\"PicNum\":1,\"SnapType\":1,\"CmdSrc\":0}}'
|
str(d_code) + '\",\"DevChannel\":' + str(num) + \
|
||||||
|
',\"PicNum\":1,\"SnapType\":1,\"CmdSrc\":0}}'
|
||||||
is_ok, res = self.request(**dhapis['dev_snap'], json=json_data)
|
is_ok, res = self.request(**dhapis['dev_snap'], json=json_data)
|
||||||
if is_ok == 'success':
|
if is_ok == 'success':
|
||||||
res = json.loads(res)
|
res = json.loads(res)
|
||||||
|
@ -286,5 +289,22 @@ class DhClient:
|
||||||
}
|
}
|
||||||
self.request(**dhapis['face_deploy'], json=json_data)
|
self.request(**dhapis['face_deploy'], json=json_data)
|
||||||
|
|
||||||
|
def get_rtsp(self, code: str):
|
||||||
|
"""获取rtsp流
|
||||||
|
|
||||||
|
Args:
|
||||||
|
code (str): 通道编号
|
||||||
|
"""
|
||||||
|
is_ok, res = self.request(**dhapis['video_rtsp'], json={"data": {"channelId": code,"dataType": "1","streamType": "1"}})
|
||||||
|
if is_ok == 'success':
|
||||||
|
if '|' in res['url']:
|
||||||
|
urls = res['url'].split('|')
|
||||||
|
for i in urls:
|
||||||
|
if settings.DAHUA_HOST in i:
|
||||||
|
return f"{i}?token={res['token']}"
|
||||||
|
else:
|
||||||
|
return f"{res['url']}?token={res['token']}"
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
dhClient = DhClient()
|
dhClient = DhClient()
|
||||||
|
|
|
@ -34,7 +34,8 @@ class DahuaTestView(MyLoggingMixin, APIView):
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
# res = dhClient.face_search(path='/media/2022/07/13/three.jpg')
|
# res = dhClient.face_search(path='/media/2022/07/13/three.jpg')
|
||||||
res = dhClient.snap(code='1000038$1$0$31')
|
# res = dhClient.snap(code='1000163$1$0$0')
|
||||||
|
res = dhClient.get_rtsp(code='1000163$1$0$0')
|
||||||
return Response(res)
|
return Response(res)
|
||||||
|
|
||||||
|
|
||||||
|
@ -266,7 +267,12 @@ class DhCommonViewSet(CreateModelMixin, CustomGenericViewSet):
|
||||||
|
|
||||||
获取token
|
获取token
|
||||||
"""
|
"""
|
||||||
return Response({'token': cache.get('dh_token', '')})
|
ret = {
|
||||||
|
"current": cache.get('dh_token', ''),
|
||||||
|
}
|
||||||
|
dhClient._get_token()
|
||||||
|
ret["new"] = cache.get('dh_token', '')
|
||||||
|
return Response(ret)
|
||||||
|
|
||||||
@action(methods=['post'], detail=False,
|
@action(methods=['post'], detail=False,
|
||||||
permission_classes=[IsAuthenticated],
|
permission_classes=[IsAuthenticated],
|
||||||
|
|
|
@ -357,6 +357,7 @@ BASE_URL_OUT = conf.BASE_URL_OUT
|
||||||
# 大华ICC平台
|
# 大华ICC平台
|
||||||
DAHUA_ENABLED = conf.DAHUA_ENABLED
|
DAHUA_ENABLED = conf.DAHUA_ENABLED
|
||||||
DAHUA_BASE_URL = conf.DAHUA_BASE_URL
|
DAHUA_BASE_URL = conf.DAHUA_BASE_URL
|
||||||
|
DAHUA_HOST = conf.DAHUA_BASE_URL.replace('https://', '').replace('http://', '')
|
||||||
DAHUA_USERNAME = conf.DAHUA_USERNAME
|
DAHUA_USERNAME = conf.DAHUA_USERNAME
|
||||||
DAHUA_PASSWORD = conf.DAHUA_PASSWORD
|
DAHUA_PASSWORD = conf.DAHUA_PASSWORD
|
||||||
DAHUA_CLIENTID = conf.DAHUA_CLIENTID
|
DAHUA_CLIENTID = conf.DAHUA_CLIENTID
|
||||||
|
|
Loading…
Reference in New Issue