Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Do not count embedded cover art (attached_pic) as a video stream, so an MP3 or M4A with a cover picture stays audio under VIDEO_RETENTION (#482)
Murtaza Nasir82122133fca9
diff --git a/src/utils/ffprobe.py b/src/utils/ffprobe.pyindex 28ad1a6c..c2b26e8f 100644--- a/src/utils/ffprobe.py+++ b/src/utils/ffprobe.py@@ -213,6 +213,10 @@ def get_codec_info(filename: str, timeout: Optional[int] = None) -> Dict[str, Anresult['channels'] = stream.get('channels')elif codec_type == 'video':+ # Cover art embedded in an audio file (MP3, M4A, FLAC) is a+ # one-frame video stream marked attached_pic; it is not video.+ if (stream.get('disposition') or {}).get('attached_pic'):+ continueresult['has_video'] = Trueif result['video_codec'] is None: # Use first video streamresult['video_codec'] = codec_namediff --git a/tests/test_upload_junk_video.py b/tests/test_upload_junk_video.pyindex ce0290dc..26c0bbd5 100644--- a/tests/test_upload_junk_video.py+++ b/tests/test_upload_junk_video.py@@ -187,6 +187,37 @@ def test_real_video_with_audio_has_its_audio_extracted_without_retention(user, tassert not storage.uploaded[0][0].endswith(".mp4") # the extracted audio++def _ffmpeg_mp3_with_cover(path):+ """Write a one-second MP3 with an embedded cover picture."""+ subprocess.run(["ffmpeg", "-v", "error", "-y",+ "-f", "lavfi", "-i", "sine=frequency=440:duration=1",+ "-f", "lavfi", "-i", "color=c=red:size=64x64",+ "-map", "0:a", "-map", "1:v", "-frames:v", "1", "-c:a", "libmp3lame",+ "-c:v", "mjpeg", "-disposition:v", "attached_pic", str(path)],+ check=True, capture_output=True)+ return path.read_bytes()+++@needs_ffmpeg+def test_cover_art_is_not_a_video_stream(tmp_path):+ from src.utils.ffprobe import get_codec_info+ _ffmpeg_mp3_with_cover(tmp_path / "song.mp3")+ info = get_codec_info(str(tmp_path / "song.mp3"))+ assert info["has_audio"] is True+ assert info["has_video"] is False and info["video_codec"] is None+++@needs_ffmpeg+def test_mp3_with_cover_art_is_kept_as_audio_under_retention(user, tmp_path):+ payload = _ffmpeg_mp3_with_cover(tmp_path / "song.mp3")+ resp, storage, enqueue, leftovers = _upload(user, payload, "song.mp3", retention=True)+ assert resp.status_code in (200, 202), resp.get_data(as_text=True)+ assert enqueue.call_count == 1+ with app.app_context():+ rec = Recording.query.filter_by(user_id=user).one()+ assert not (rec.mime_type or "").startswith("video/"), rec.mime_type+def test_a_probe_that_timed_out_still_trusts_the_video_extension(user):"""A large MP4 can be slow to probe: it is kept as a video, as before."""with patch("src.api.recordings.convert_if_needed") as convert, \