A transcode or remux refreshes the sha256 sums a download recorded (#906)

The Job replaces the video file (and its ffprobe json), so the sums in the info json's
wrolpi section described files that were gone.  Once the refresh has re-modeled the
Video, its files are hashed again, without a session held, and the sums replaced.
A Video without recorded sums gains none.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-10-30 19:41:19 -06:00 • committed by Roland
parent 4c8e9fb68c
commit 78e2741db8
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
2 changed files with 58 additions and 0 deletions

View file

@ -9,6 +9,7 @@ from wrolpi.captions import FFMPEG_BIN
from wrolpi.cmd import run_command
from wrolpi.common import logger, get_relative_to_media_directory, wrol_mode_enabled
from wrolpi.db import get_db_session
from wrolpi.files.lib import sha256_files, sha256_by_suffix
from wrolpi.jobs import register_job, get_current_job
from wrolpi.vars import DEFAULT_FILE_PERMISSIONS, PYTEST
@ -505,6 +506,22 @@ def retarget_file_group(file_group_id: int, old_path: pathlib.Path, new_path: pa
file_group.indexed = False
async def refresh_recorded_sha256(file_group_id: int):
"""Hash a FileGroup's files again if a download recorded their sums; the recorded sums describe files which
may have been replaced. The files are read without a session held."""
from wrolpi.files.models import FileGroup
with get_db_session() as session:
file_group = session.get(FileGroup, file_group_id)
if 'sha256' not in file_group.get_wrolpi_json():
return
paths = file_group.my_paths()
sums = await asyncio.to_thread(sha256_files, paths)
with get_db_session(commit=True) as session:
session.get(FileGroup, file_group_id).update_wrolpi_json({'sha256': sha256_by_suffix(sums)})
@register_job('transcode_video')
async def transcode_video_job(file_group_id: int, video_codec: Optional[str] = None,
audio_codec: Optional[str] = None, container: str = 'mp4',
@ -543,4 +560,6 @@ async def transcode_video_job(file_group_id: int, video_codec: Optional[str] = N
job_id = file_worker.queue_refresh([final_path], send_events=False)
await file_worker.wait_for_job(job_id)
await refresh_recorded_sha256(file_group_id)
return {'path': str(get_relative_to_media_directory(final_path))}