From ef4656aa65b3518e45028e64ea4c739f1c4e8cf0 Mon Sep 17 00:00:00 2001 From: Roland Date: Mon, 14 Oct 2019 16:59:53 -0600 Subject: [PATCH] Removing for loop. Adding orphan meta file. --- wrolpi/plugins/videos/api.py | 9 ++++----- wrolpi/plugins/videos/test/test_api.py | 16 +++++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/wrolpi/plugins/videos/api.py b/wrolpi/plugins/videos/api.py index 1a93d628..c87d4a86 100644 --- a/wrolpi/plugins/videos/api.py +++ b/wrolpi/plugins/videos/api.py @@ -214,11 +214,10 @@ def refresh_channel_videos(db, channel): # A set of absolute paths that exist in the file system possible_new_paths = list(generate_video_paths(directory)) - # make them relative to this channel - new_videos = [] - for possible_new_path in possible_new_paths: - if possible_new_path.relative_to(directory) not in existing_paths: - new_videos.append(possible_new_path) + + # Get the absolute paths who's path relative to the channel does't yet exist + # (paths in DB are relative, but we need to pass an absolute path) + new_videos = {p for p in possible_new_paths if p.relative_to(directory) not in existing_paths} for video_path in new_videos: logger.debug(f'{channel["name"]}: Added {video_path}') diff --git a/wrolpi/plugins/videos/test/test_api.py b/wrolpi/plugins/videos/test/test_api.py index d5a95e5b..10fb4f72 100644 --- a/wrolpi/plugins/videos/test/test_api.py +++ b/wrolpi/plugins/videos/test/test_api.py @@ -130,7 +130,7 @@ class TestAPI(unittest.TestCase): vid2 = pathlib.Path(channel_path / 'channel name_20000102_bcdefghijkl_title.webm') vid2.touch() - # These files are associated with the video files above, and should be found second + # These files are associated with the video files above, and should be found "near" them poster1 = pathlib.Path(channel_path / 'channel name_20000101_abcdefghijk_title.jpg') poster1.touch() poster2 = pathlib.Path(channel_path / 'channel name_20000102_bcdefghijkl_title.jpg') @@ -158,16 +158,22 @@ class TestAPI(unittest.TestCase): description3 = pathlib.Path(channel_path / 'channel name_20000103_cdefghijklm_title.description') description3.touch() + # A orphan meta-file should be ignored. This shouldn't show up anywhere. + poster3 = pathlib.Path(channel_path / 'channel name_20000104_defghijklmn_title.jpg') + poster3.touch() + + # Finally, call the refresh. Again, it should remove the "foo" video, then discover this 3rd video + # file and it's description. refresh_videos(db) # Bogus file was removed self.assertNotIn('foo', {i['video_path'] for i in channel['videos']}) - # Final structure we built + # Final channel video list we built expected = { - (vid1.name, poster1.name, None), - (vid2.name, poster2.name, None), - (vid3.name, None, description3.name), + (vid1.name, poster1.name, None), # no description + (vid2.name, poster2.name, None), # no description + (vid3.name, None, description3.name), # no poster } self.assertEqual( {(i['video_path'], i['poster_path'], i['description_path']) for i in channel['videos']},