Handle empty recording days and stale playback queries

This commit is contained in:
Codex
2026-10-03 17:15:09 +08:00
parent 969dcabe99
commit d21170b41d
4 changed files with 30 additions and 8 deletions
+12 -3
View File
@@ -310,6 +310,15 @@ def media_json(path, playback=False):
req = urllib.request.Request(target, headers={'Authorization': MEDIA_AUTH})
with urllib.request.urlopen(req, timeout=5) as r:
return json.load(r)
except urllib.error.HTTPError as exc:
if playback and path.startswith('/list?') and exc.code == 404:
try:
detail = json.loads(exc.read(4096))
if detail.get('error') == 'no recording segments found':
return []
except (ValueError, AttributeError):
pass
raise Problem('视频服务暂不可用,或该时段尚无可回放录像', 503)
except Exception:
raise Problem('视频服务暂不可用,或该时段尚无可回放录像', 503)
@@ -402,9 +411,9 @@ def storage_watch():
def discover(network):
def probe(ip):
try:
with socket.create_connection((str(ip), 554), timeout=0.7) as s:
s.settimeout(1)
s.sendall(('OPTIONS rtsp://' + str(ip) + '/ RTSP/1.0\r\nCSeq: 1\r\n\r\n').encode())
with socket.create_connection((str(ip), 554), timeout=1.5) as s:
s.settimeout(3)
s.sendall(('OPTIONS rtsp://' + str(ip) + ':554/ RTSP/1.0\r\nCSeq: 1\r\nUser-Agent: ZhaoVision\r\n\r\n').encode())
response = s.recv(1024).decode(errors='replace').split('\r\n')[0]
if response.startswith('RTSP/'):
return {'host': str(ip), 'port': 554, 'response': response, 'authenticated': False}