fix: skip duration read for active recordings to prevent garbage values

WAV nframes and FLAC total_samples are both unfinalized while the
recorder has the file open, producing wildly wrong durations
(e.g. 53375995583:39:01). Return None (shown as —) instead.
This commit is contained in:
2026-04-29 19:54:38 +02:00
parent 476a8d2752
commit 7db0e0870f
+6 -2
View File
@@ -224,8 +224,12 @@ def list_files(recordings_dir: str):
continue continue
stat = path.stat() stat = path.stat()
rel = str(path.relative_to(base)).replace('\\', '/') rel = str(path.relative_to(base)).replace('\\', '/')
is_active = rel in active_files
duration = _get_audio_duration(path) # Skip reading partial headers for in-progress files — the WAV nframes
# field and FLAC total_samples are both unfinalized while recording,
# producing wildly incorrect values (e.g. 53375995583:39:01).
duration = None if is_active else _get_audio_duration(path)
files.append({ files.append({
'name': rel, 'name': rel,
@@ -234,7 +238,7 @@ def list_files(recordings_dir: str):
'date': datetime.fromtimestamp(stat.st_mtime).strftime('%Y-%m-%d %H:%M:%S'), 'date': datetime.fromtimestamp(stat.st_mtime).strftime('%Y-%m-%d %H:%M:%S'),
'duration': duration, 'duration': duration,
'ext': path.suffix.lower().lstrip('.'), 'ext': path.suffix.lower().lstrip('.'),
'recording': rel in active_files, 'recording': is_active,
}) })
files.sort(key=lambda f: f['mtime'], reverse=True) files.sort(key=lambda f: f['mtime'], reverse=True)