feat: name cut clips by wall-clock time; fix recording filename format
Cut downloads were named by byte offsets (`..._cut_740s-750s.flac`). They are now named by the actual recording time the slice covers, e.g. `20260523_22-31-30_22-32-30.flac` for a 22:31:30->22:32:30 cut of a recording started at 22:00:00. To make this reliable, the recording filename is now a fixed `%Y%m%d_%H%M%S` start-time format (`FILENAME_FORMAT`) shared by isr.py and web.py, replacing the user-configurable `filename_pattern` (web.py never reads config.ini, so a custom pattern could not be parsed back). web.py parses the start time out of the filename via `_recording_start()` and builds cut names with `_cut_filename()`. The DATE column now also comes from the filename (falling back to mtime only for non-standard names), since mtime is the last write, not the start. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+31
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
import math
|
||||
|
||||
from web import _loud_sections, _noise_floor_db
|
||||
from web import _cut_filename, _loud_sections, _noise_floor_db, _recording_start
|
||||
|
||||
WINDOW_DUR = 0.1 # 100 ms windows, as produced by WINDOW_SAMPLES at 48 kHz
|
||||
|
||||
@@ -99,3 +99,33 @@ def test_noise_floor_tracks_blocks_and_ignores_short_events():
|
||||
floor = _noise_floor_db(db, WINDOW_DUR)
|
||||
assert len(floor) == len(db)
|
||||
assert all(abs(f - quiet_db) < 1.0 for f in floor)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Filename parsing / cut naming
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_recording_start_parses_standard_name():
|
||||
from datetime import datetime
|
||||
assert _recording_start("20260523_220000") == datetime(2026, 5, 23, 22, 0, 0)
|
||||
|
||||
|
||||
def test_recording_start_rejects_nonstandard_name():
|
||||
assert _recording_start("radio1_20260523") is None
|
||||
assert _recording_start("notes") is None
|
||||
|
||||
|
||||
def test_cut_filename_uses_wall_clock_span():
|
||||
# Recording started 22:00:00; cut covers 22:31:30 → 22:32:30.
|
||||
name = _cut_filename("20260523_220000", ".flac", 1890, 1950)
|
||||
assert name == "20260523_22-31-30_22-32-30.flac"
|
||||
|
||||
|
||||
def test_cut_filename_rolls_over_the_hour():
|
||||
name = _cut_filename("20260523_220000", ".wav", 3590, 3661)
|
||||
assert name == "20260523_22-59-50_23-01-01.wav"
|
||||
|
||||
|
||||
def test_cut_filename_falls_back_for_nonstandard_name():
|
||||
name = _cut_filename("mixtape", ".mp3", 740, 750.4)
|
||||
assert name == "mixtape_cut_740s-750s.mp3"
|
||||
|
||||
Reference in New Issue
Block a user