Skip to content

fix: find a combined mp4/mkv download in audio mode - #142

Merged
prekabreki merged 1 commit into
mainfrom
fm/ff-audio-mp4-141
Nov 19, 2026
Merged

prekabreki merged 1 commit into
mainfrom
fm/ff-audio-mp4-141

Conversation

@prekabreki

Copy link
Copy Markdown
Owner

Closes #141

What was wrong

If a video has no audio-only format, the audio selector's ba/b fallback downloads a combined file (format 18, a .mp4).
Audio mode only accepted audio-only suffixes (_AUDIO_EXTS), so it threw away the parsed Destination: path and the cache fallback never globbed *.mp4.
The job then failed with No .mkv found after download. even though the file was in the cache.
The new tests reproduced that exact error before the fix.

Change

  • fetchforge/ytdlp.py: new _COMBINED_EXTS = {.mp4, .mkv, .webm} and _AUDIO_MODE_EXTS = _AUDIO_EXTS | _COMBINED_EXTS. _cache_snapshot_patterns(True) uses it.
  • fetchforge/items.py: audio mode's allowed_suffixes is _AUDIO_MODE_EXTS. If nothing is found in audio mode, the error lists the suffixes it looked for. Video mode is unchanged: .mkv only, same message.
  • The ba/b fallback itself is unchanged.

Danger zone (shared cache)

Matching is still suffix-exact globbing (*.mp4 etc.), so x.mp4.part, x.f18.mp4.part, x.webm.part and x.mp4.ytdl never match.
Older files are still excluded by the pre-download snapshot, which now also covers .mp4/.mkv in audio mode.
AudioModeCacheLookupTest.test_ignores_part_files_and_older_unrelated_videos checks this: with only an older .mp4/.mkv and four leftovers in the cache, the lookup returns None, then it picks this job's new file.
test_audio_mode_nothing_downloaded_names_what_was_looked_for checks it end to end: only a .part lands, the older .mkv is not used, and nothing is written to the output dir.

Tests (tests/test_download_fallback.py)

  • AudioModeCacheLookupTest: the audio path's lookup against a real temp cache dir, no network, for .mp4/.mkv/.webm, plus the danger-zone case.
  • test_audio_mode_extracts_from_a_combined_file (ffmpeg-gated): the fake yt-dlp drops a real combined .mp4/.mkv/.webm, with and without a Destination: line, for WAV and MP3. It checks via ffprobe that the output has a single audio stream with the expected codec (pcm_s16le / mp3).
  • test_video_mode_still_rejects_a_combined_mp4: video mode still says No .mkv found.
  • The existing snapshot-pattern test now compares against _AUDIO_MODE_EXTS (the widened set), and the fake yt-dlp gained optional copy_from / dest config.

Verify

.venv/bin/python -m unittest tests.test_download_fallback -v:

test_finds_a_combined_file (tests.test_download_fallback.AudioModeCacheLookupTest.test_finds_a_combined_file) ... ok
test_ignores_part_files_and_older_unrelated_videos (tests.test_download_fallback.AudioModeCacheLookupTest.test_ignores_part_files_and_older_unrelated_videos) ... ok
test_audio_mode_accepts_audio_only_and_combined_files (tests.test_download_fallback.CacheSnapshotPatternsTest.test_audio_mode_accepts_audio_only_and_combined_files) ... ok
test_audio_patterns_cover_every_audio_mode_suffix (tests.test_download_fallback.CacheSnapshotPatternsTest.test_audio_patterns_cover_every_audio_mode_suffix) ... ok
test_video_pattern_is_mkv_only (tests.test_download_fallback.CacheSnapshotPatternsTest.test_video_pattern_is_mkv_only) ... ok
test_audio_mode_extracts_from_a_combined_file (tests.test_download_fallback.SequentialDownloadFallbackTest.test_audio_mode_extracts_from_a_combined_file) ... Executing <Task pending name='Task-2' coro=<SequentialDownloadFallbackTest.test_audio_mode_extracts_from_a_combined_file() running at /home/prekabreki/.treehouse/FetchForge-1d21d4/1/FetchForge/tests/test_download_fallback.py:217> wait_for=<Future pending cb=[Task.task_wakeup()] created at /home/prekabreki/.local/share/uv/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py:459> cb=[_run_until_complete_cb() at /home/prekabreki/.local/share/uv/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py:181] created at /home/prekabreki/.local/share/uv/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py:101> took 0.168 seconds
Executing <Task pending name='Task-2' coro=<SequentialDownloadFallbackTest.test_audio_mode_extracts_from_a_combined_file() running at /home/prekabreki/.treehouse/FetchForge-1d21d4/1/FetchForge/tests/test_download_fallback.py:217> wait_for=<Future pending cb=[Task.task_wakeup()] created at /home/prekabreki/.local/share/uv/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py:459> cb=[_run_until_complete_cb() at /home/prekabreki/.local/share/uv/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py:181] created at /home/prekabreki/.local/share/uv/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py:101> took 0.178 seconds
ok
test_audio_mode_nothing_downloaded_names_what_was_looked_for (tests.test_download_fallback.SequentialDownloadFallbackTest.test_audio_mode_nothing_downloaded_names_what_was_looked_for) ... ok
test_failed_download_with_unrelated_cache_file_errors_and_keeps_it (tests.test_download_fallback.SequentialDownloadFallbackTest.test_failed_download_with_unrelated_cache_file_errors_and_keeps_it) ... ok
test_success_without_parsed_output_line_finds_only_the_new_file (tests.test_download_fallback.SequentialDownloadFallbackTest.test_success_without_parsed_output_line_finds_only_the_new_file) ... ok
test_video_mode_still_rejects_a_combined_mp4 (tests.test_download_fallback.SequentialDownloadFallbackTest.test_video_mode_still_rejects_a_combined_mp4) ... ok

----------------------------------------------------------------------
Ran 10 tests in 3.579s

OK

Full gate, run the way test.yml runs it: unittest discover -s tests 383 OK, -s tools/tests 14 OK, ruff check clean, frontend 47/47 pass, 16/16 mutations caught.

When a video offers no audio-only format, the audio selector's `ba/b`
fallback downloads a combined file. Audio mode only accepted audio-only
suffixes, so a combined .mp4 or .mkv was never found and the job failed
with "No .mkv found after download." while the file sat in the cache.

Audio mode now accepts `_AUDIO_MODE_EXTS` (the audio-only suffixes plus
.mp4/.mkv/.webm), both from the parsed Destination line and in the
cache snapshot fallback. Matching stays suffix-exact, so .part and .ytdl
leftovers are never picked, and the pre-download snapshot still excludes
older files. Video mode still accepts only .mkv. An audio-mode miss now
names the suffixes it looked for instead of saying ".mkv".

Closes #141
@prekabreki
prekabreki merged commit 8215893 into main Nov 19, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audio mode fails with "No .mkv found" when the download falls back to a combined mp4

1 participant