Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Port: fix auto-merge duplicate audio_duration_seconds kwarg and adapt keep_audio_only e2e test to the storage move

Murtaza Nasir69aa94f1c0eb
diff --git a/src/api/recordings.py b/src/api/recordings.py
index 93456e01..c2ec6325 100644
--- a/src/api/recordings.py
+++ b/src/api/recordings.py
@@ -2679,17 +2679,6 @@ def upload_file():
meeting_date = now
current_app.logger.debug("No file date available, using current time")
- # Cache audio duration up front from the codec probe so list and
- # detail API endpoints don't have to ffprobe per row. Falls back
- # to None if the probe failed; the post-transcription path will
- # populate it later.
- cached_duration = None
- try:
- if codec_info and isinstance(codec_info.get('duration'), (int, float)):
- cached_duration = float(codec_info['duration'])
- except Exception:
- cached_duration = None
-
recording = Recording(
audio_path=None,
original_filename=original_filename,
@@ -2710,7 +2699,6 @@ def upload_file():
# regardless of the server's VIDEO_RETENTION setting. True when
# the user explicitly toggled it or when VIDEO_RETENTION is off.
keep_audio_only=effective_audio_only,
- audio_duration_seconds=cached_duration,
)
db.session.add(recording)
db.session.flush() # Assign recording.id without committing transaction yet
diff --git a/tests/test_keep_audio_only_e2e.py b/tests/test_keep_audio_only_e2e.py
index 4daf87af..a65b8732 100644
--- a/tests/test_keep_audio_only_e2e.py
+++ b/tests/test_keep_audio_only_e2e.py
@@ -62,28 +62,29 @@ def test_upload_with_keep_audio_only_persists_flag_on_recording():
'video_codec': 'h264',
'duration': 30.0,
}
+ # The storage layer now MOVES the converted file into the storage
+ # root, so the mocked conversion must produce a real file on disk
+ # (a fake path would FileNotFoundError on shutil.move). A real
+ # production conversion always yields a real file, so this keeps the
+ # test faithful to the post-storage upload flow.
+ import tempfile
+ conv_fd, conv_path = tempfile.mkstemp(suffix='.mp3')
+ os.write(conv_fd, b'\x00' * (1024 * 1024))
+ os.close(conv_fd)
convert_result = MagicMock()
- convert_result.output_path = '/tmp/converted-audio.mp3'
+ convert_result.output_path = conv_path
convert_result.was_converted = True
convert_result.was_compressed = False
convert_result.original_codec = 'aac'
convert_result.final_codec = 'mp3'
mock_convert.return_value = convert_result
- # Patch os.path.getsize so the post-conversion size check
- # doesn't blow up on the fake output path.
- real_getsize = os.path.getsize
- def fake_getsize(p):
- if p == '/tmp/converted-audio.mp3':
- return 1024 * 1024
- return real_getsize(p)
- with patch('src.api.recordings.os.path.getsize', side_effect=fake_getsize):
- data = {
- 'keep_audio_only': 'true',
- 'title': 'e2e-test',
- }
- data['file'] = (io.BytesIO(b'\x00' * 16384), 'sample.mp4')
- resp = client.post('/upload', data=data, content_type='multipart/form-data')
+ data = {
+ 'keep_audio_only': 'true',
+ 'title': 'e2e-test',
+ }
+ data['file'] = (io.BytesIO(b'\x00' * 16384), 'sample.mp4')
+ resp = client.post('/upload', data=data, content_type='multipart/form-data')
# Upload handler returns 202 on success; some failure modes
# return other 2xx. Tolerate either as long as a Recording row