diff --git a/modules/videos/channel/test/test_models.py b/modules/videos/channel/test/test_models.py index e5b8653e..00ffecb4 100644 --- a/modules/videos/channel/test/test_models.py +++ b/modules/videos/channel/test/test_models.py @@ -1,3 +1,6 @@ +import pytest + + def test_delete_channel_no_url(test_session, test_client, channel_factory): """ A Channel can be deleted even if it has no URL. @@ -7,3 +10,31 @@ def test_delete_channel_no_url(test_session, test_client, channel_factory): test_session.commit() channel.delete_with_videos() + + +@pytest.mark.asyncio +async def test_channel_refresh_censored(test_session, channel_factory, video_factory): + """Censored videos are discovered when refreshing a channel's directory.""" + channel = channel_factory() + channel.info_json = { + 'entries': [ + {'id': 'one', 'view_count': 100}, + {'id': 'two', 'view_count': 200}, + # Three was deleted, it should be marked as censored. + # {'id': 'three', 'view_count': 300}, + ] + } + vid1 = video_factory(channel_id=channel.id, source_id='one') + vid2 = video_factory(channel_id=channel.id, source_id='two') + vid3 = video_factory(channel_id=channel.id, source_id='three') + test_session.commit() + + assert vid1.censored is False and vid1.view_count is None + assert vid2.censored is False and vid1.view_count is None + assert vid3.censored is False and vid1.view_count is None + + await channel.refresh_files() + + assert vid1.censored is False and vid1.view_count == 100 + assert vid2.censored is False and vid2.view_count == 200 + assert vid3.censored is True and vid3.view_count is None diff --git a/modules/videos/models.py b/modules/videos/models.py index e078de70..de1d74be 100644 --- a/modules/videos/models.py +++ b/modules/videos/models.py @@ -480,5 +480,7 @@ class Channel(ModelHelper, Base): async def refresh_files(self): """Refresh all files within this Channel's directory. Mark this channel as refreshed.""" + from modules.videos.common import apply_info_json await refresh_directory_files_recursively(self.directory) + apply_info_json(self.id) self.refreshed = True diff --git a/wrolpi/events.py b/wrolpi/events.py index f41e00c3..9fa079df 100644 --- a/wrolpi/events.py +++ b/wrolpi/events.py @@ -50,6 +50,17 @@ class Events: send_event('directory_refresh_completed', message, subject='refresh_directory') +def log_event(event: str, message: str = None, action: str = None, subject: str = None): + log = f'{event=}' + if subject: + log = f'{log} {subject=}' + if action: + log = f'{log} {action=}' + if message: + log = f'{log} {message=}' + logger.debug(log) + + def send_event(event: str, message: str = None, action: str = None, subject: str = None): EVENTS_LOCK.acquire() try: @@ -71,7 +82,7 @@ def send_event(event: str, message: str = None, action: str = None, subject: str finally: EVENTS_LOCK.release() - logger.debug(f'Sent event {event}') + log_event(event, message, action, subject) @iterify(list) diff --git a/wrolpi/files/lib.py b/wrolpi/files/lib.py index e764b51b..1bac6200 100644 --- a/wrolpi/files/lib.py +++ b/wrolpi/files/lib.py @@ -372,7 +372,7 @@ async def refresh_directory_files_recursively(directory: Union[pathlib.Path, str # All Files older than this will be removed. idempotency = now() - refresh_logger.warning(f'Recursively refreshing all files in {directory}') + refresh_logger.info(f'Recursively refreshing all files in {directory}') await _refresh_directory_files_recursively(directory, idempotency)