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:
@@ -224,8 +224,12 @@ def list_files(recordings_dir: str):
|
||||
continue
|
||||
stat = path.stat()
|
||||
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({
|
||||
'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'),
|
||||
'duration': duration,
|
||||
'ext': path.suffix.lower().lstrip('.'),
|
||||
'recording': rel in active_files,
|
||||
'recording': is_active,
|
||||
})
|
||||
|
||||
files.sort(key=lambda f: f['mtime'], reverse=True)
|
||||
|
||||
Reference in New Issue
Block a user