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) self._download_submission(submission)
def _download_submission(self, submission: praw.models.Submission): def _download_submission(self, submission: praw.models.Submission):
# TODO: check existence here
if self.download_filter.check_url(submission.url): if self.download_filter.check_url(submission.url):
try: try:
downloader_class = DownloadFactory.pull_lever(submission.url) downloader_class = DownloadFactory.pull_lever(submission.url)
@@ -184,7 +183,11 @@ class RedditDownloader:
content = downloader.download() content = downloader.download()
for res in content: for res in content:
destination = self.file_name_formatter.format_path(res, self.download_directory) 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: 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) destination.parent.mkdir(parents=True, exist_ok=True)
with open(destination, 'wb') as file: with open(destination, 'wb') as file:
file.write(res.content) file.write(res.content)