From c69ad683dc8f84b217ef532a580a82801f19e20d Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sun, 12 Jun 2022 15:38:52 +0300 Subject: ipcam_server: add DVRScanInvalidTimecodes exception type, change handling logic --- src/home/camera/util.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/home/camera') diff --git a/src/home/camera/util.py b/src/home/camera/util.py index 5f18a1f..39bfcd3 100644 --- a/src/home/camera/util.py +++ b/src/home/camera/util.py @@ -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: -- cgit v1.2.3