Re-implement --no-download flag
This commit is contained in:
parent
70a992d299
commit
eac2381a0a
1 changed files with 17 additions and 14 deletions
|
@ -177,20 +177,23 @@ class RedditDownloader:
|
||||||
try:
|
try:
|
||||||
downloader_class = DownloadFactory.pull_lever(submission.url)
|
downloader_class = DownloadFactory.pull_lever(submission.url)
|
||||||
downloader = downloader_class(self.download_directory, submission)
|
downloader = downloader_class(self.download_directory, submission)
|
||||||
content = downloader.download()
|
if self.args.no_download:
|
||||||
for res in content:
|
logger.info('Skipping download for submission {}'.format(submission.id))
|
||||||
destination = self.file_name_formatter.format_path(res, self.download_directory)
|
else:
|
||||||
if destination.exists():
|
content = downloader.download()
|
||||||
logger.debug('File already exists: {}'.format(destination))
|
for res in content:
|
||||||
else:
|
destination = self.file_name_formatter.format_path(res, self.download_directory)
|
||||||
if res.hash.hexdigest() not in self.master_hash_list:
|
if destination.exists():
|
||||||
# TODO: consider making a hard link/symlink here
|
logger.debug('File already exists: {}'.format(destination))
|
||||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
else:
|
||||||
with open(destination, 'wb') as file:
|
if res.hash.hexdigest() not in self.master_hash_list:
|
||||||
file.write(res.content)
|
# TODO: consider making a hard link/symlink here
|
||||||
logger.debug('Written file to {}'.format(destination))
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||||
self.master_hash_list.append(res.hash.hexdigest())
|
with open(destination, 'wb') as file:
|
||||||
logger.debug('Hash added to master list: {}'.format(res.hash.hexdigest()))
|
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))
|
logger.info('Downloaded submission {}'.format(submission.name))
|
||||||
except NotADownloadableLinkError as e:
|
except NotADownloadableLinkError as e:
|
||||||
|
|
Loading…
Reference in a new issue