diff --git a/nhentai/doujinshi.py b/nhentai/doujinshi.py index 6d5b84f..dcd3dc2 100644 --- a/nhentai/doujinshi.py +++ b/nhentai/doujinshi.py @@ -74,24 +74,23 @@ class Doujinshi(object): def check_if_need_download(self, options): base_path = os.path.join(self.downloader.path, self.filename) - file_ext = None # 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' - # 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 + ret_pdf = ret_cbz = None + if options.is_pdf: + ret_pdf = os.path.exists(f'{base_path}.pdf') or os.path.exists(f'{base_path}/{self.filename}.pdf') + + if options.is_cbz: + ret_cbz = os.path.exists(f'{base_path}.cbz') or os.path.exists(f'{base_path}/{self.filename}.cbz') + + if all(filter(lambda s: s is not None, [ret_cbz, ret_pdf])): + return False # doujinshi directory doesn't exist, re-download if not (os.path.exists(base_path) and os.path.isdir(base_path)):