Re-indexing video if its files change.

This commit is contained in:
Roland 2022-11-30 18:36:22 -07:00
parent d3bb94e339
commit 8360e4fb82
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
2 changed files with 20 additions and 1 deletions

View file

@ -50,10 +50,20 @@ def video_modeler(groups: Dict[str, List[File]], session: Session):
if not video:
video = Video(video_file=video_file)
session.add(video)
size = video_file.path.stat().st_size
if poster_file != video.poster_file or \
caption_file != video.caption_file or \
info_json_file != video.info_json_file or \
video.size != size:
# Files were changed. Re-index.
video.video_file.indexed = False
video.poster_file = poster_file
video.caption_file = caption_file
video.info_json_file = info_json_file
video.size = video_file.path.stat().st_size
video.size = size
video_file.model = Video.__tablename__
videos.append(video)

View file

@ -37,6 +37,15 @@ async def test_refresh_videos_index(test_session, test_directory, video_factory)
assert not video.caption_file.indexed
assert not video.info_json_file.indexed
# Delete caption file, the video should be indexed again.
video: Video = test_session.query(Video).one()
video.caption_path.unlink()
await refresh_files()
assert video.video_file.indexed is True, 'Video was not indexed'
assert video.video_file.a_text, 'Video title was not indexed'
assert not video.video_file.d_text, 'Video captions were not removed'
def test_refresh_videos(test_client, test_session, test_directory, simple_channel, video_factory):
subdir = test_directory / 'subdir'