diff --git a/nhentai/command.py b/nhentai/command.py index fe7a2c9..50abd8d 100644 --- a/nhentai/command.py +++ b/nhentai/command.py @@ -85,21 +85,19 @@ def main(): else: continue + file_type = '' + if options.is_cbz: file_type = '.cbz' + elif options.is_pdf: file_type = '.pdf' + if not options.dryrun: doujinshi.downloader = downloader - result = doujinshi.download(regenerate_cbz=options.regenerate_cbz) + result = doujinshi.download(regenerate_cbz=options.regenerate_cbz, file_type=file_type) # Already downloaded; continue on with the other doujins. if not result: continue if options.generate_metadata: table = doujinshi.table - - # Skip downloading metadata if archived file is already generated. - check_file_type = '' - if options.is_cbz: check_file_type = '.cbz' - elif options.is_pdf: check_file_type = '.pdf' - - result = generate_metadata_file(options.output_dir, table, doujinshi, check_file_type) + result = generate_metadata_file(options.output_dir, table, doujinshi, file_type) # Already downloaded; continue on with the other doujins. if not result: continue diff --git a/nhentai/doujinshi.py b/nhentai/doujinshi.py index a9dda25..28f6786 100644 --- a/nhentai/doujinshi.py +++ b/nhentai/doujinshi.py @@ -72,7 +72,7 @@ class Doujinshi(object): def show(self): logger.info(f'Print doujinshi information of {self.id}\n{tabulate(self.table)}') - def download(self, regenerate_cbz=False): + def download(self, regenerate_cbz=False, file_type=''): logger.info(f'Starting to download doujinshi: {self.name}') if self.downloader: download_queue = [] @@ -82,9 +82,10 @@ class Doujinshi(object): for i in range(1, min(self.pages, len(self.ext)) + 1): download_queue.append(f'{IMAGE_URL}/{self.img_id}/{i}.{self.ext[i-1]}') - self.downloader.start_download(download_queue, self.filename, regenerate_cbz=regenerate_cbz) + return self.downloader.start_download(download_queue, self.filename, regenerate_cbz=regenerate_cbz, file_type=file_type) else: logger.critical('Downloader has not been loaded') + return False if __name__ == '__main__': diff --git a/nhentai/downloader.py b/nhentai/downloader.py index 6eb463d..cc1814c 100644 --- a/nhentai/downloader.py +++ b/nhentai/downloader.py @@ -57,7 +57,7 @@ class Downloader(Singleton): save_file_path = os.path.join(folder, base_filename.zfill(3) + extension) try: if os.path.exists(save_file_path): - logger.warning(f'Ignored exists file: {save_file_path}') + logger.warning(f'Skipped download: {save_file_path} already exists') return 1, url response = None @@ -116,17 +116,16 @@ class Downloader(Singleton): return 1, url - def start_download(self, queue, folder='', regenerate_cbz=False) -> bool: + def start_download(self, queue, folder='', regenerate_cbz=False, file_type='') -> bool: if not isinstance(folder, (str, )): folder = str(folder) if self.path: folder = os.path.join(self.path, folder) - if os.path.exists(folder + '.cbz'): - if not regenerate_cbz: - logger.warning(f'CBZ file "{folder}.cbz" exists, ignored download request') - return False + if file_type != '' and os.path.exists(folder + file_type) and not regenerate_cbz: + logger.warning(f'Skipped download: "{folder}{file_type}" already exists') + return False logger.info(f'Doujinshi will be saved at "{folder}"') if not os.path.exists(folder): @@ -136,7 +135,7 @@ class Downloader(Singleton): logger.critical(str(e)) if os.getenv('DEBUG', None) == 'NODOWNLOAD': - # Assuming we want to continue with rest of process? + # Assuming we want to continue with rest of process. return True queue = [(self, url, folder, constant.CONFIG['proxy']) for url in queue]