Video page: edit the description in Edit > Edit

PUT /api/videos/<file_group_id> now takes optional title and description
and changes only the fields given; an empty description clears it.  The
modal sends only what changed and refetches the description after saving.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-09-14 18:56:46 -06:00
parent cc25e342d4
commit ca1dc82aa9
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
9 changed files with 111 additions and 29 deletions

View file

@ -188,7 +188,9 @@ class VideoSearchRequest:
@dataclass
class VideoUpdateRequest:
title: str
# Only the fields given are changed.
title: Optional[str] = None
description: Optional[str] = None
@dataclass

View file

@ -44,6 +44,36 @@ def test_update_video_title_creates_info_json(test_session, test_directory, vide
assert video.info_json_path.name in [i['path'] for i in video.file_group.files], 'The new file is tracked'
def test_update_video_description(test_session, test_directory, video_factory):
"""The description is written to the info json and indexed; the title is untouched when not
given. An empty description clears it."""
video = video_factory(with_info_json={'title': 'Kept', 'description': 'old words'})
test_session.commit()
assert video.file_group.c_text == 'old words'
update_video(video.file_group_id, description='new words\nsecond line')
test_session.expire_all()
video = Video.find_by_file_group_id(test_session, video.file_group_id)
assert video.file_group.title == 'Kept'
assert video.file_group.c_text == 'new words\nsecond line'
assert video.get_description() == 'new words\nsecond line'
assert json.loads(video.info_json_path.read_text())['description'] == 'new words\nsecond line'
update_video(video.file_group_id, description='')
test_session.expire_all()
video = Video.find_by_file_group_id(test_session, video.file_group_id)
assert video.get_description() is None
assert video.file_group.title == 'Kept'
def test_update_video_nothing(test_session, video_factory):
video = video_factory(with_info_json={'title': 'Old'})
test_session.commit()
with pytest.raises(ValidationError):
update_video(video.file_group_id)
def test_update_video_title_empty(test_session, video_factory):
video = video_factory(with_info_json={'title': 'Old'})
test_session.commit()
@ -67,6 +97,16 @@ async def test_video_update_api(async_client, test_session, video_factory, wrol_
request, response = await async_client.put(f'/api/videos/{video.file_group_id}', content=json.dumps({'title': ''}))
assert response.status == 400
request, response = await async_client.put(f'/api/videos/{video.file_group_id}', content=json.dumps({}))
assert response.status == 400
request, response = await async_client.put(f'/api/videos/{video.file_group_id}',
content=json.dumps({'description': 'about it'}))
assert response.status == 200, response.json
assert response.json['file_group']['title'] == 'Edited', 'Title untouched'
request, response = await async_client.get(f'/api/videos/{video.file_group_id}/description')
assert response.json['description'] == 'about it'
request, response = await async_client.put('/api/videos/999999', content=json.dumps({'title': 'x'}))
assert response.status == 404

View file

@ -38,7 +38,7 @@ def video_get(request: Request, file_group_id: int):
@validate(schema.VideoUpdateRequest)
@wrol_mode_check
async def video_update(_: Request, file_group_id: int, body: schema.VideoUpdateRequest):
lib.update_video(file_group_id, body.title)
lib.update_video(file_group_id, title=body.title, description=body.description)
video, previous_video, next_video = lib.get_video_for_app(file_group_id)
return json_response({'file_group': video, 'prev': previous_video, 'next': next_video})

View file

@ -50,28 +50,35 @@ def get_video(file_group_id: int) -> Video:
return video
def update_video(file_group_id: int, title: str) -> Video:
def update_video(file_group_id: int, title: str = None, description: str = None) -> Video:
"""Edit a Video's details. The files are the source of truth, so the change is written to the
Video's .info.json (created if missing) and the Video is validated again from it.
Video's .info.json (created if missing) and the Video is validated again from it. Only the
fields given (not None) are changed; an empty description clears it.
A later re-download of the Video's metadata will overwrite the info json, and this edit with
it.
@raise UnknownVideo: if the Video can not be found
@raise ValidationError: when the title is empty
@raise ValidationError: when nothing is given, or the title is empty
"""
from wrolpi.errors import ValidationError
title = (title or '').strip()
if not title:
raise ValidationError('Video title cannot be empty')
if title is None and description is None:
raise ValidationError('Nothing to change')
if title is not None:
title = title.strip()
if not title:
raise ValidationError('Video title cannot be empty')
with get_db_session(commit=True) as session:
video = Video.find_by_file_group_id(session, file_group_id)
info_json = video.get_info_json() or dict()
# `extract_video_info_json` prefers fulltitle over title; keep the two in agreement.
info_json['title'] = title
info_json['fulltitle'] = title
# Keep the file as it was, other than the title.
if title is not None:
# `extract_video_info_json` prefers fulltitle over title; keep the two in agreement.
info_json['title'] = title
info_json['fulltitle'] = title
if description is not None:
info_json['description'] = description
# Keep the file as it was, other than the edited fields.
video.replace_info_json(info_json, clean=False)
# Re-derive the title (and search text) from the file just written.
video.validate(session)