From 806bd76f877bf26edca66e44204bc721cd124dd3 Mon Sep 17 00:00:00 2001 From: Serene-Arc Date: Fri, 25 Mar 2022 10:50:52 +1000 Subject: [PATCH 1/2] Strip any newline characters from names --- bdfr/file_name_formatter.py | 3 +++ tests/test_file_name_formatter.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/bdfr/file_name_formatter.py b/bdfr/file_name_formatter.py index 3e8832b1..1dabd341 100644 --- a/bdfr/file_name_formatter.py +++ b/bdfr/file_name_formatter.py @@ -111,6 +111,9 @@ def format_path( if not resource.extension: raise BulkDownloaderException(f'Resource from {resource.url} has no extension') file_name = str(self._format_name(resource.source_submission, self.file_format_string)) + + file_name = re.sub(r'\n', ' ', file_name) + if not re.match(r'.*\.$', file_name) and not re.match(r'^\..*', resource.extension): ending = index + '.' + resource.extension else: diff --git a/tests/test_file_name_formatter.py b/tests/test_file_name_formatter.py index 30fac778..bd9d0581 100644 --- a/tests/test_file_name_formatter.py +++ b/tests/test_file_name_formatter.py @@ -16,6 +16,7 @@ from bdfr.resource import Resource from bdfr.site_downloaders.base_downloader import BaseDownloader from bdfr.site_downloaders.fallback_downloaders.ytdlp_fallback import YtdlpFallback +from bdfr.site_downloaders.self_post import SelfPost @pytest.fixture() @@ -406,6 +407,7 @@ def test_windows_max_path(tmp_path: Path): @pytest.mark.parametrize(('test_reddit_id', 'test_downloader', 'expected_names'), ( ('gphmnr', YtdlpFallback, {'He has a lot to say today.mp4'}), ('d0oir2', YtdlpFallback, {"Crunk's finest moment. Welcome to the new subreddit!.mp4"}), + ('jiecu', SelfPost, {'Reston, VA Some info regarding shelters in the area..txt'}) )) def test_name_submission( test_reddit_id: str, @@ -418,4 +420,4 @@ def test_name_submission( test_formatter = FileNameFormatter('{TITLE}', '', '') results = test_formatter.format_resource_paths(test_resources, Path('.')) results = set([r[0].name for r in results]) - assert expected_names == results + assert results == expected_names From 5a3ff887c41b90978ea840e8d1ddae7a18013e7b Mon Sep 17 00:00:00 2001 From: Serene-Arc Date: Fri, 25 Mar 2022 10:52:49 +1000 Subject: [PATCH 2/2] Add second test case --- tests/test_file_name_formatter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_file_name_formatter.py b/tests/test_file_name_formatter.py index bd9d0581..c9e049e9 100644 --- a/tests/test_file_name_formatter.py +++ b/tests/test_file_name_formatter.py @@ -407,7 +407,8 @@ def test_windows_max_path(tmp_path: Path): @pytest.mark.parametrize(('test_reddit_id', 'test_downloader', 'expected_names'), ( ('gphmnr', YtdlpFallback, {'He has a lot to say today.mp4'}), ('d0oir2', YtdlpFallback, {"Crunk's finest moment. Welcome to the new subreddit!.mp4"}), - ('jiecu', SelfPost, {'Reston, VA Some info regarding shelters in the area..txt'}) + ('jiecu', SelfPost, {'Reston, VA Some info regarding shelters in the area..txt'}), + ('gui1i', SelfPost, {'The "Beer and Ear offer for those who need help in the \'burbs of North Dallas....txt'}), )) def test_name_submission( test_reddit_id: str,