Skip to content

Commit

Permalink
Merge pull request #621 from Serene-Arc/bug_fix_616
Browse files Browse the repository at this point in the history
  • Loading branch information
Serene-Arc authored Mar 25, 2022
2 parents a2aa739 + 5a3ff88 commit 2c93537
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions bdfr/file_name_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_file_name_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -406,6 +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'}),
('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,
Expand All @@ -418,4 +421,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

0 comments on commit 2c93537

Please sign in to comment.