Searching for censored videos when refreshing a channel.

This commit is contained in:
Roland 2022-12-26 11:30:28 -07:00
parent 586ca7af79
commit 35145d0335
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
4 changed files with 46 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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)