ipcam_server: add DVRScanInvalidTimecodes exception type, change handling logic
This commit is contained in:
parent
2f8556eb45
commit
c69ad683dc
@ -63,9 +63,11 @@ async def ffmpeg_cut(input: str,
|
||||
|
||||
|
||||
def dvr_scan_timecodes(timecodes: str) -> list[tuple[int, int]]:
|
||||
tc_backup = timecodes
|
||||
|
||||
timecodes = timecodes.split(',')
|
||||
if len(timecodes) % 2 != 0:
|
||||
raise ValueError('invalid number of timecodes')
|
||||
raise DVRScanInvalidTimecodes(f'invalid number of timecodes. input: {tc_backup}')
|
||||
|
||||
timecodes = list(map(time2seconds, timecodes))
|
||||
timecodes = list(chunks(timecodes, 2))
|
||||
@ -73,7 +75,7 @@ def dvr_scan_timecodes(timecodes: str) -> list[tuple[int, int]]:
|
||||
# sort out invalid fragments (dvr-scan returns them sometimes, idk why...)
|
||||
timecodes = list(filter(lambda f: f[0] < f[1], timecodes))
|
||||
if not timecodes:
|
||||
raise ValueError('no valid timecodes')
|
||||
raise DVRScanInvalidTimecodes(f'no valid timecodes. input: {tc_backup}')
|
||||
|
||||
# https://stackoverflow.com/a/43600953
|
||||
timecodes.sort(key=lambda interval: interval[0])
|
||||
@ -88,6 +90,10 @@ def dvr_scan_timecodes(timecodes: str) -> list[tuple[int, int]]:
|
||||
return merged
|
||||
|
||||
|
||||
class DVRScanInvalidTimecodes(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def has_handle(fpath):
|
||||
for proc in psutil.process_iter():
|
||||
try:
|
||||
|
@ -176,9 +176,10 @@ class IPCamWebServer(http.HTTPServer):
|
||||
db.set_timestamp(camera, TimeFilterType.MOTION, time)
|
||||
return self.ok()
|
||||
|
||||
except ValueError as e:
|
||||
except camutil.DVRScanInvalidTimecodes as e:
|
||||
db.add_motion_failure(camera, filename, str(e))
|
||||
db.set_timestamp(camera, TimeFilterType.MOTION, time)
|
||||
raise e
|
||||
return self.ok('invalid timecodes')
|
||||
|
||||
async def submit_motion_failure(self, req: http.Request):
|
||||
camera = int(req.match_info['name'])
|
||||
|
Loading…
x
Reference in New Issue
Block a user