Handle empty recording days and stale playback queries
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user