From cb6cf6df1a2ba9327bee5eccb4642e3fbeef1bf1 Mon Sep 17 00:00:00 2001 From: normalizedwater546 Date: Sun, 22 Sep 2024 07:24:16 +0000 Subject: [PATCH] regression: pdf/cbz file already exists, but origin files are downloaded anyways. - call download with `--cbz --rm-origin-dir`, and run command twice. - user should pass `--regenerate` option to get back origin dir. --- nhentai/doujinshi.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/nhentai/doujinshi.py b/nhentai/doujinshi.py index 7bb0f53..6d5b84f 100644 --- a/nhentai/doujinshi.py +++ b/nhentai/doujinshi.py @@ -74,26 +74,28 @@ class Doujinshi(object): def check_if_need_download(self, options): base_path = os.path.join(self.downloader.path, self.filename) + file_ext = None - # 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 + # regenerate, re-download if options.regenerate: return True + # detect file extensions 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 + # pdf or cbz file exists, skip re-download + # doujinshi directory may not exist b/c of --rm-origin-dir option set. + # user should pass --regenerate option to get back origin dir. + if file_ext is not None: + if os.path.exists(f'{base_path}.{file_ext}') or os.path.exists(f'{base_path}/{self.filename}.{file_ext}'): + return False + + # doujinshi directory doesn't exist, re-download + if not (os.path.exists(base_path) and os.path.isdir(base_path)): + return True # fallback return True