新增获取视频地址页面,雏形未修改

This commit is contained in:
zqc
2026-04-02 12:10:20 +08:00
parent 8598098d32
commit 1aecfba186
4 changed files with 721 additions and 28 deletions

View File

@@ -1,6 +1,5 @@
import requests
import urllib3
import yaml
from hikvision_openapi_signer import HikvisionOpenAPISigner
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
@@ -13,12 +12,12 @@ signer = HikvisionOpenAPISigner(
headers={'tagId': '0'} # 根据平台要求设置
)
def get_camera_preview_url(camera_index_code):
def get_organization_list(parentIndexCode):
# 签名一个请求
request = signer.sign(
'POST',
'/api/video/v1/cameras/previewURLs',
jsons={'cameraIndexCode': camera_index_code, 'protocol': 'rtsp', 'expand': 'streamform=rtp'},
'/api/resource/v1/regions/subRegions',
jsons={'parentIndexCode': parentIndexCode, 'treeCode': '0'},
accept='application/json'
)
method, url, headers, body = request
@@ -26,28 +25,28 @@ def get_camera_preview_url(camera_index_code):
response = requests.request(method, url, headers=headers, data=body, verify=False)
return response.json()
# 读取 config.yaml
with open('../config.yaml', 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
def get_final_list(regionIndexCode):
# 签名一个请求
request = signer.sign(
'POST',
'/api/resource/v1/regions/regionIndexCode/cameras',
jsons={'pageNo': 1, 'pageSize': 100, 'regionIndexCode': regionIndexCode, 'treeCode': '0'},
accept='application/json'
)
method, url, headers, body = request
# 发送请求注意离线环境下verify=False可能必要但需知安全风险
response = requests.request(method, url, headers=headers, data=body, verify=False)
return response.json()
# 遍历所有摄像头
for camera in config['cameras']:
if 'index' in camera:
index = camera['index']
print(f"正在获取摄像头 {camera['name']} (index: {index}) 的预览地址...")
result = get_camera_preview_url(index)
print(f"API返回结果: {result}")
# 提取 url 并更新到 config
if 'data' in result and 'url' in result['data']:
rtsp_url = result['data']['url']
camera['rtsp_url'] = rtsp_url
print(f"更新 rtsp_url: {rtsp_url}")
else:
print(f"未找到 url 在返回结果中")
# 保存更新后的 config.yaml
with open('../config.yaml', 'w', encoding='utf-8') as f:
yaml.dump(config, f, default_flow_style=False, allow_unicode=True)
print("config.yaml 已更新")
def get_camera_preview_url(camera_index_code, stream_type = 0):
# 签名一个请求
request = signer.sign(
'POST',
'/api/video/v1/cameras/previewURLs',
jsons={'cameraIndexCode': camera_index_code, 'protocol': 'hls', 'streamType': stream_type, 'expand': 'transcode=1'},
accept='application/json'
)
method, url, headers, body = request
# 发送请求
response = requests.request(method, url, headers=headers, data=body, verify=False)
return response.json()