From 37ff1ab2cdea0b25043c902238fcf750f8b5b35c Mon Sep 17 00:00:00 2001 From: Roland Date: Sun, 14 Jul 2024 09:44:18 -0600 Subject: [PATCH] Changing title_match to title_include for clarity. --- app/src/api.js | 8 ++++---- app/src/components/Channels.js | 10 +++++----- modules/videos/downloader.py | 11 +++++------ modules/videos/test/test_downloader.py | 4 ++-- modules/videos/test/test_lib.py | 1 + wrolpi/common.py | 4 ++-- wrolpi/test/test_common.py | 5 +++++ 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/app/src/api.js b/app/src/api.js index 89d36d84..e879468a 100644 --- a/app/src/api.js +++ b/app/src/api.js @@ -251,12 +251,12 @@ export async function getVideosStatistics() { } } -export async function createChannelDownload(channelId, url, frequency, title_match, title_exclude, tag_names) { +export async function createChannelDownload(channelId, url, frequency, title_include, title_exclude, tag_names) { const body = { url: url, frequency: frequency, settings: { - title_match: title_match, + title_include: title_include, title_exclude: title_exclude, tag_names: tag_names, }, @@ -284,12 +284,12 @@ export async function createChannelDownload(channelId, url, frequency, title_mat return response; } -export async function updateChannelDownload(channelId, downloadId, url, frequency, title_match, title_exclude, tag_names) { +export async function updateChannelDownload(channelId, downloadId, url, frequency, title_include, title_exclude, tag_names) { const body = { url: url, frequency: frequency, settings: { - title_match: title_match, + title_include: title_include, title_exclude: title_exclude, tag_names: tag_names, }, diff --git a/app/src/components/Channels.js b/app/src/components/Channels.js index 19b76316..a2b5670f 100644 --- a/app/src/components/Channels.js +++ b/app/src/components/Channels.js @@ -418,7 +418,7 @@ export function ChannelDownloadForm({channel_id, afterSave, closeModal, download const [state, setState] = React.useState({ frequency: download.frequency ? download.frequency : 604800, title_exclude: settings.title_exclude ? settings.title_exclude : '', - title_match: settings.title_match ? settings.title_match : '', + title_include: settings.title_include ? settings.title_include : '', url: download ? download.url : '', }) const [disabled, setDisabled] = React.useState(useWROLMode()); @@ -447,7 +447,7 @@ export function ChannelDownloadForm({channel_id, afterSave, closeModal, download download.id, state.url, state.frequency, - state.title_match, + state.title_include, state.title_exclude, tagNames, ); @@ -456,7 +456,7 @@ export function ChannelDownloadForm({channel_id, afterSave, closeModal, download channel_id, state.url, state.frequency, - state.title_match, + state.title_include, state.title_exclude, tagNames, ); @@ -544,11 +544,11 @@ export function ChannelDownloadForm({channel_id, afterSave, closeModal, download popupPosition='bottom center' /> diff --git a/modules/videos/downloader.py b/modules/videos/downloader.py index f8444709..53c89505 100755 --- a/modules/videos/downloader.py +++ b/modules/videos/downloader.py @@ -169,14 +169,14 @@ class ChannelDownloader(Downloader, ABC): downloads = download.info_json['entries'] total_downloads = len(downloads) - title_match = download.settings.get('title_match') if download.settings else None - if title_match: + title_include = download.settings.get('title_include') if download.settings else None + if title_include: # Only download Videos that have title match words in title. - title_match = [i.strip() for i in title_match.split(',')] + title_include = [i.strip() for i in title_include.split(',')] new_downloads = [] for i in downloads: - if (title := i.get('title', '')) and any(j for j in title_match if j in title): - logger.debug(f'Video with title {title} matches {title_match}') + if (title := i.get('title', '')) and any(j for j in title_include if j in title): + logger.debug(f'Video with title {title} matches {title_include}') new_downloads.append(i) downloads = new_downloads @@ -188,7 +188,6 @@ class ChannelDownloader(Downloader, ABC): for i in downloads: if (title := i.get('title', '')) and any(j for j in title_exclude if j in title): logger.debug(f'Video with title {title} matches EXCLUDE {title_exclude}') - continue else: new_downloads.append(i) downloads = new_downloads diff --git a/modules/videos/test/test_downloader.py b/modules/videos/test/test_downloader.py index f06325c0..19ffdbe8 100644 --- a/modules/videos/test/test_downloader.py +++ b/modules/videos/test/test_downloader.py @@ -157,13 +157,13 @@ async def test_download_channel(test_session, simple_channel, video_download_man reset_downloads() - # A channel with `title_match` only returns matching video URLs. + # A channel with `title_include` only returns matching video URLs. test_session.commit() with mock.patch('modules.videos.downloader.get_channel') as mock_get_channel: mock_get_channel.return_value = simple_channel cd = simple_channel.get_or_create_download(url, test_session) cd.download.frequency = 100 - cd.download.settings = {'title_match': '2'} + cd.download.settings = {'title_include': '2'} await video_download_manager.wait_for_all_downloads() downloads = video_download_manager.get_once_downloads(test_session) assert {i.url for i in downloads} == {'https://youtube.com/watch?v=video_2_url'} diff --git a/modules/videos/test/test_lib.py b/modules/videos/test/test_lib.py index 1a2b7cb8..61baccba 100644 --- a/modules/videos/test/test_lib.py +++ b/modules/videos/test/test_lib.py @@ -164,6 +164,7 @@ def test_link_channel_and_downloads(test_session, channel_factory): assert test_session.query(Download).count() == 2 assert test_session.query(ChannelDownload).count() == 0 + # `link_channel_and_downloads` creates missing ChannelDownloads. lib.link_channel_and_downloads(session=test_session) assert test_session.query(Download).count() == 2 assert test_session.query(ChannelDownload).count() == 2 diff --git a/wrolpi/common.py b/wrolpi/common.py index b520d84d..bff37547 100644 --- a/wrolpi/common.py +++ b/wrolpi/common.py @@ -1766,7 +1766,7 @@ def format_html_file(file: pathlib.Path): replace_file(file, pretty) -def html_screenshot(html: bytes) -> bytes: +def html_screenshot(html: bytes | str) -> bytes: """Return a PNG screenshot of the provided HTML.""" # Set Chromium to headless. Use a wide window size so that screenshot will be the "desktop" version of the page. options = webdriver.ChromeOptions() @@ -1775,7 +1775,7 @@ def html_screenshot(html: bytes) -> bytes: options.add_argument('window-size=1280x720') with tempfile.NamedTemporaryFile('wb', suffix='.html') as fh: - fh.write(html) + fh.write(html.encode() if isinstance(html, str) else html) fh.flush() with webdriver.Chrome(chrome_options=options) as driver: diff --git a/wrolpi/test/test_common.py b/wrolpi/test/test_common.py index 5355df7e..d5b20857 100644 --- a/wrolpi/test/test_common.py +++ b/wrolpi/test/test_common.py @@ -864,3 +864,8 @@ async def test_log_level(test_async_client, test_config): request, response = await test_async_client.patch('/api/settings', json=body) assert response.status_code == HTTPStatus.NO_CONTENT, response.json assert api_app.shared_ctx.log_level.value == 10 + + +@skip_circleci +def test_html_screenshot(singlefile_contents_factory): + assert common.html_screenshot(singlefile_contents_factory())