mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-19 10:21:19 +02:00
improve download logic #343
This commit is contained in:
parent
984ae4262c
commit
9c1c2ea069
@ -88,10 +88,10 @@ def main():
|
||||
if not options.dryrun:
|
||||
doujinshi.downloader = downloader
|
||||
|
||||
result = doujinshi.download(skip_exists=not options.regenerate)
|
||||
# Already downloaded; continue on with the other doujins.
|
||||
if not result:
|
||||
continue
|
||||
if doujinshi.check_if_need_download(options):
|
||||
doujinshi.download()
|
||||
else:
|
||||
logger.info(f'Skip download doujinshi because a PDF/CBZ file exists of doujinshi {doujinshi.name}')
|
||||
|
||||
if options.generate_metadata:
|
||||
generate_metadata_file(options.output_dir, doujinshi)
|
||||
|
@ -72,14 +72,34 @@ class Doujinshi(object):
|
||||
def show(self):
|
||||
logger.info(f'Print doujinshi information of {self.id}\n{tabulate(self.table)}')
|
||||
|
||||
def download(self, skip_exists=True):
|
||||
logger.info(f'Starting to download doujinshi: {self.name}')
|
||||
|
||||
def check_if_need_download(self, options):
|
||||
base_path = os.path.join(self.downloader.path, self.filename)
|
||||
if (os.path.exists(base_path + '.pdf') or os.path.exists(base_path + '.cbz')) and skip_exists:
|
||||
logger.info(f'Skip download doujinshi because a PDF/CBZ file exists of doujinshi {self.name}')
|
||||
|
||||
# doujinshi directory is not exist, we need to download definitely
|
||||
if not (os.path.exists(base_path) and os.path.isdir(base_path)):
|
||||
return True
|
||||
|
||||
# regenerate, we need to re-download from nhentai
|
||||
if options.regenerate:
|
||||
return True
|
||||
|
||||
if options.is_pdf:
|
||||
file_ext = 'pdf'
|
||||
elif options.is_cbz:
|
||||
file_ext = 'cbz'
|
||||
else:
|
||||
# re-download
|
||||
return True
|
||||
|
||||
# pdf or cbz file exists, we needn't to re-download it
|
||||
if os.path.exists(f'{base_path}.{file_ext}') or os.path.exists(f'{base_path}/{self.filename}.{file_ext}'):
|
||||
return False
|
||||
|
||||
# fallback
|
||||
return True
|
||||
|
||||
def download(self):
|
||||
logger.info(f'Starting to download doujinshi: {self.name}')
|
||||
if self.downloader:
|
||||
download_queue = []
|
||||
if len(self.ext) != self.pages:
|
||||
|
@ -191,7 +191,7 @@ def generate_doc(file_type='', output_dir='.', doujinshi_obj=None, rm_origin_dir
|
||||
doujinshi_dir, filename = parse_doujinshi_obj(output_dir, doujinshi_obj, file_type)
|
||||
|
||||
if os.path.exists(f'{doujinshi_dir}.{file_type}') and not regenerate:
|
||||
logger.info(f'Skipped download: {doujinshi_dir}.{file_type} already exists')
|
||||
logger.info(f'Skipped {file_type} file generation: {doujinshi_dir}.{file_type} already exists')
|
||||
return
|
||||
|
||||
if file_type == 'cbz':
|
||||
|
Loading…
x
Reference in New Issue
Block a user