Hash audio profile paths

This commit is contained in:
Abel Luck 2026-03-31 15:14:17 +02:00
parent 2ad0536bb0
commit 23d03cd9d5
4 changed files with 59 additions and 41 deletions

View file

@ -338,7 +338,7 @@ def test_audio_pipeline_media_downloaded_returns_canonical_file_info_and_variant
return str(output_path)
def fake_probe_media(file_path: str):
if file_path.endswith(".mp3-vbr7.mp3"):
if file_path.endswith(".mp3-vbr7-3b2b0f13.mp3"):
return {
"format": {
"duration": "61.2",
@ -423,18 +423,20 @@ def test_audio_pipeline_media_downloaded_returns_canonical_file_info_and_variant
assert isinstance(result["checksum"], str)
assert result == {
"url": source_url,
"path": f"{audio_base_path}-vbr7.mp3",
"path": f"{audio_base_path}-vbr7-3b2b0f13.mp3",
"published_url": (
f"https://mirror.example/feeds/nasa/audio/{audio_base_path}-vbr7.mp3"
"https://mirror.example/feeds/nasa/audio/"
f"{audio_base_path}-vbr7-3b2b0f13.mp3"
),
"checksum": result["checksum"],
"status": "downloaded",
"variants": [
{
"url": (
f"https://mirror.example/feeds/nasa/audio/{audio_base_path}-vbr7.mp3"
"https://mirror.example/feeds/nasa/audio/"
f"{audio_base_path}-vbr7-3b2b0f13.mp3"
),
"path": f"{audio_base_path}-vbr7.mp3",
"path": f"{audio_base_path}-vbr7-3b2b0f13.mp3",
"type": "audio/mp3",
"medium": "audio",
"isDefault": "true",
@ -446,9 +448,10 @@ def test_audio_pipeline_media_downloaded_returns_canonical_file_info_and_variant
},
{
"url": (
f"https://mirror.example/feeds/nasa/audio/{audio_base_path}-vbr3.aac"
"https://mirror.example/feeds/nasa/audio/"
f"{audio_base_path}-vbr3-4a2a58d5.aac"
),
"path": f"{audio_base_path}-vbr3.aac",
"path": f"{audio_base_path}-vbr3-4a2a58d5.aac",
"type": "audio/aac",
"medium": "audio",
"isDefault": "false",
@ -474,8 +477,8 @@ def test_audio_pipeline_media_downloaded_returns_canonical_file_info_and_variant
}
assert persisted == [
(audio_base_path, "audio/mpeg"),
(f"{audio_base_path}-vbr7.mp3", "audio/mp3"),
(f"{audio_base_path}-vbr3.aac", "audio/aac"),
(f"{audio_base_path}-vbr7-3b2b0f13.mp3", "audio/mp3"),
(f"{audio_base_path}-vbr3-4a2a58d5.aac", "audio/aac"),
]
completed_item = pipeline.item_completed(
@ -647,8 +650,8 @@ def test_audio_pipeline_media_to_download_checks_canonical_path(
source_url = "https://example.com/podcast.mp3"
audio_base_path = local_audio_path(source_url)
original_path = store_dir(pipeline) / audio_base_path
canonical_path = store_dir(pipeline) / f"{audio_base_path}-vbr7.mp3"
secondary_path = store_dir(pipeline) / f"{audio_base_path}-vbr3.aac"
canonical_path = store_dir(pipeline) / f"{audio_base_path}-vbr7-3b2b0f13.mp3"
secondary_path = store_dir(pipeline) / f"{audio_base_path}-vbr3-4a2a58d5.aac"
original_path.parent.mkdir(parents=True, exist_ok=True)
original_path.write_bytes(b"original")
canonical_path.parent.mkdir(parents=True, exist_ok=True)
@ -680,19 +683,27 @@ def test_audio_pipeline_media_to_download_checks_canonical_path(
lambda file_path: {
"format": {
"duration": "61.2",
"size": "4567" if file_path.endswith("vbr7.mp3") else "3456",
"bit_rate": "96000" if file_path.endswith("vbr7.mp3") else "88000",
"format_name": "mp3" if file_path.endswith("vbr7.mp3") else "aac",
"size": ("4567" if file_path.endswith("vbr7-3b2b0f13.mp3") else "3456"),
"bit_rate": (
"96000" if file_path.endswith("vbr7-3b2b0f13.mp3") else "88000"
),
"format_name": (
"mp3" if file_path.endswith("vbr7-3b2b0f13.mp3") else "aac"
),
"format_long_name": "Audio",
},
"streams": [
{
"codec_type": "audio",
"codec_name": "mp3" if file_path.endswith("vbr7.mp3") else "aac",
"bit_rate": "96000" if file_path.endswith("vbr7.mp3") else "88000",
"codec_name": (
"mp3" if file_path.endswith("vbr7-3b2b0f13.mp3") else "aac"
),
"bit_rate": (
"96000" if file_path.endswith("vbr7-3b2b0f13.mp3") else "88000"
),
"duration_ts": "61200",
"sample_rate": (
"44100" if file_path.endswith("vbr7.mp3") else "48000"
"44100" if file_path.endswith("vbr7-3b2b0f13.mp3") else "48000"
),
"channels": 2,
}
@ -706,12 +717,12 @@ def test_audio_pipeline_media_to_download_checks_canonical_path(
item=item,
)
assert result is not None
assert result["path"] == f"{audio_base_path}-vbr7.mp3"
assert result["path"] == f"{audio_base_path}-vbr7-3b2b0f13.mp3"
assert result["status"] == "uptodate"
assert [variant.get("path") for variant in result["variants"]] == [
f"{audio_base_path}-vbr7.mp3",
f"{audio_base_path}-vbr3.aac",
f"{audio_base_path}-vbr7-3b2b0f13.mp3",
f"{audio_base_path}-vbr3-4a2a58d5.aac",
audio_base_path,
]
assert f"{audio_base_path}.mp3" not in stat_paths
assert stat_paths[0] == f"{audio_base_path}-vbr7.mp3"
assert stat_paths[0] == f"{audio_base_path}-vbr7-3b2b0f13.mp3"