mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-20 02:41:19 +02:00
fix: add file_type check to downloader
If you wanted to generate both .cbz and .pdf, the .pdf will be skipped if .cbz was generated first.
This commit is contained in:
parent
497eb6fe50
commit
5a29eaf775
@ -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
|
||||
|
||||
|
@ -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__':
|
||||
|
@ -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,16 +116,15 @@ 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')
|
||||
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}"')
|
||||
@ -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]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user