wrolpi/modules/videos/test
lrnselfreliance 0b61d3ab08
Some checks failed
CodeQL / Analyze (push) Has been cancelled
Controller Tests / controller-tests (push) Has been cancelled
Jest Tests / jest-tests (push) Has been cancelled
videos: codec download preferences with transcode and strict-fail options (#701)
* videos: codec download preferences with transcode and strict-fail options

Add video_codecs/audio_codecs ordered preference lists to the video,
channel, and RSS downloaders, alongside the existing resolution
selector.  Codec preference is codec-major: a preferred codec at a
lower resolution beats another codec at a higher resolution.

When 'transcode' is enabled, a downloaded file whose streams do not
match the preferences is re-encoded with ffmpeg after download (only
the mismatching stream; targets are extensible maps, currently h264
and aac/opus/mp3).  When 'strict_codecs' is enabled and transcode is
not, a download with no matching format fails permanently instead of
falling back.

Empty codec lists produce a byte-identical yt-dlp command to before.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* videos: honor strict_codecs when transcode cannot produce the preference

Review fixes:
- strict_codecs is now suppressed only when transcoding can produce a
  preferred codec for every non-empty preference list (new
  transcode_can_satisfy_codecs); av1-only preferences with transcode
  enabled fail under strict instead of silently keeping the file.
- No partial transcode: an unfixable video mismatch blocks an
  audio-only conversion (and vice versa); the mismatch falls through
  to strict/keep.
- fsync the transcode output before rename, and the directory after,
  so power loss on a Pi cannot leave a truncated final file.
- mp3 yt-dlp pattern matches mp4a.6B as well as mp4a.6b.
- ffmpeg maps use 0:V:0 (excludes attached pictures) and 0🅰️0?
  (tolerates missing audio).
- Strict toggle is no longer disabled by transcode in the UI; popup
  wording corrected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* videos: serialize transcodes machine-wide via shared_ctx lock

Sanic runs multiple worker processes, so an asyncio primitive cannot
serialize transcodes across download workers.  A multiprocessing.Lock
in shared_ctx now guarantees only one ffmpeg transcode runs at a time
on the machine; waiting workers poll the lock asynchronously so the
event loop stays responsive while a transcode holds it for hours.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* videos: transcode-lock review fixes

- Document that a crashed lock holder requires an API restart; this is
  accepted rather than adding owner-death recovery.
- Move the 'Transcoding' user notification to after the lock is
  acquired, so it fires when work begins rather than before a
  potentially hours-long wait.
- Soften the lock test docstring to what it measures (in-process
  wait/release); trim the acquire docstring to the polling rationale.
- Give transcode_lock its own section header in contexts.py.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-09-07 09:12:00 -06:00
..
__init__.py A new start 2021-11-01 16:43:09 -06:00
test_api.py videos: deflake event-loop-blocking search test (#699) 2026-09-03 16:24:09 -06:00
test_audio_modeling.py videos: parse the published date out of audio file names too (#676) 2026-08-24 12:14:07 -06:00
test_channel_directory_scenarios.py db: write intent is the opt-in, not a second session helper 2026-08-07 20:15:50 -06:00
test_channel_refresh_events.py videos: silence the automatic channel refresh before downloads (#671) 2026-08-20 15:15:18 -06:00
test_channel_refresh_external_files.py Displaying download progress (speed, eta) for file and video downloads. 2026-03-12 19:31:35 -06:00
test_channels_config.py FileGroups in Collections can be reorganized in the Collection's directory. 2026-01-31 18:08:41 -07:00
test_common.py review: ffprobe out of the write transaction, and three tests that were watching nothing 2026-08-07 20:15:50 -06:00
test_cookies.py Using shared context to sync cookies between processes. 2026-02-22 14:32:27 -07:00
test_downloader.py videos: codec download preferences with transcode and strict-fail options (#701) 2026-09-07 09:12:00 -06:00
test_lib.py videos: codec download preferences with transcode and strict-fail options (#701) 2026-09-07 09:12:00 -06:00
test_models.py Handling when skip_urls is a None. Logging a warning (and ignoring) when duplicate json files are in a Video FileGroup. 2026-03-13 15:27:43 -06:00
test_transcode.py videos: codec download preferences with transcode and strict-fail options (#701) 2026-09-07 09:12:00 -06:00
test_video.py review: flush before the rename, not just after one delete 2026-08-07 15:08:40 -06:00
test_video_modeler_loop.py Fixing bug where not all archives were modeled. 2025-12-18 17:19:57 -07:00
test_video_url_resolver.py Trying to get existing channel using more variations of Youtube URLs. 2026-03-20 17:26:51 -06:00