1
0
Fork 0
mirror of synced 2024-09-28 07:12:07 +12:00

Add existence checking

This commit is contained in:
Serene-Arc 2021-02-14 18:52:04 +10:00 committed by Ali Parlakci
parent 722e6cb73a
commit e646ae4a84

View file

@ -176,7 +176,6 @@ class RedditDownloader:
self._download_submission(submission)
def _download_submission(self, submission: praw.models.Submission):
# TODO: check existence here
if self.download_filter.check_url(submission.url):
try:
downloader_class = DownloadFactory.pull_lever(submission.url)
@ -184,7 +183,11 @@ class RedditDownloader:
content = downloader.download()
for res in content:
destination = self.file_name_formatter.format_path(res, self.download_directory)
if destination.exists():
logger.debug('File already exists: {}'.format(destination))
else:
if res.hash.hexdigest() not in self.master_hash_list:
# TODO: consider making a hard link/symlink here
destination.parent.mkdir(parents=True, exist_ok=True)
with open(destination, 'wb') as file:
file.write(res.content)