diff --git a/modules/videos/__init__.py b/modules/videos/__init__.py index caee9857..13cca563 100644 --- a/modules/videos/__init__.py +++ b/modules/videos/__init__.py @@ -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) diff --git a/modules/videos/test/test_api.py b/modules/videos/test/test_api.py index 4141556a..03f05c8e 100644 --- a/modules/videos/test/test_api.py +++ b/modules/videos/test/test_api.py @@ -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'