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:
@@ -222,10 +222,14 @@ def list_files(recordings_dir: str):
|
|||||||
for path in base.rglob('*'):
|
for path in base.rglob('*'):
|
||||||
if path.suffix.lower() not in AUDIO_EXTENSIONS:
|
if path.suffix.lower() not in AUDIO_EXTENSIONS:
|
||||||
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user