From eac2381a0aba3d40ddda84377042030212e73295 Mon Sep 17 00:00:00 2001 From: Serene-Arc Date: Sun, 14 Feb 2021 19:09:18 +1000 Subject: [PATCH] Re-implement --no-download flag --- bulkredditdownloader/downloader.py | 31 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/bulkredditdownloader/downloader.py b/bulkredditdownloader/downloader.py index 32e3e95..835ec99 100644 --- a/bulkredditdownloader/downloader.py +++ b/bulkredditdownloader/downloader.py @@ -177,20 +177,23 @@ class RedditDownloader: try: downloader_class = DownloadFactory.pull_lever(submission.url) downloader = downloader_class(self.download_directory, submission) - 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) - logger.debug('Written file to {}'.format(destination)) - self.master_hash_list.append(res.hash.hexdigest()) - logger.debug('Hash added to master list: {}'.format(res.hash.hexdigest())) + if self.args.no_download: + logger.info('Skipping download for submission {}'.format(submission.id)) + else: + 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) + logger.debug('Written file to {}'.format(destination)) + self.master_hash_list.append(res.hash.hexdigest()) + logger.debug('Hash added to master list: {}'.format(res.hash.hexdigest())) logger.info('Downloaded submission {}'.format(submission.name)) except NotADownloadableLinkError as e: