diff --git a/nhentai/command.py b/nhentai/command.py index 1ada93c..7feffcd 100644 --- a/nhentai/command.py +++ b/nhentai/command.py @@ -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) diff --git a/nhentai/doujinshi.py b/nhentai/doujinshi.py index 946f000..7bb0f53 100644 --- a/nhentai/doujinshi.py +++ b/nhentai/doujinshi.py @@ -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: diff --git a/nhentai/utils.py b/nhentai/utils.py index db09a1f..f22f8d7 100644 --- a/nhentai/utils.py +++ b/nhentai/utils.py @@ -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':