mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-20 11:01:17 +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:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
file_type = ''
|
||||||
|
if options.is_cbz: file_type = '.cbz'
|
||||||
|
elif options.is_pdf: file_type = '.pdf'
|
||||||
|
|
||||||
if not options.dryrun:
|
if not options.dryrun:
|
||||||
doujinshi.downloader = downloader
|
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.
|
# Already downloaded; continue on with the other doujins.
|
||||||
if not result: continue
|
if not result: continue
|
||||||
|
|
||||||
if options.generate_metadata:
|
if options.generate_metadata:
|
||||||
table = doujinshi.table
|
table = doujinshi.table
|
||||||
|
result = generate_metadata_file(options.output_dir, table, doujinshi, file_type)
|
||||||
# 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)
|
|
||||||
# Already downloaded; continue on with the other doujins.
|
# Already downloaded; continue on with the other doujins.
|
||||||
if not result: continue
|
if not result: continue
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ class Doujinshi(object):
|
|||||||
def show(self):
|
def show(self):
|
||||||
logger.info(f'Print doujinshi information of {self.id}\n{tabulate(self.table)}')
|
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}')
|
logger.info(f'Starting to download doujinshi: {self.name}')
|
||||||
if self.downloader:
|
if self.downloader:
|
||||||
download_queue = []
|
download_queue = []
|
||||||
@ -82,9 +82,10 @@ class Doujinshi(object):
|
|||||||
for i in range(1, min(self.pages, len(self.ext)) + 1):
|
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]}')
|
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:
|
else:
|
||||||
logger.critical('Downloader has not been loaded')
|
logger.critical('Downloader has not been loaded')
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -57,7 +57,7 @@ class Downloader(Singleton):
|
|||||||
save_file_path = os.path.join(folder, base_filename.zfill(3) + extension)
|
save_file_path = os.path.join(folder, base_filename.zfill(3) + extension)
|
||||||
try:
|
try:
|
||||||
if os.path.exists(save_file_path):
|
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
|
return 1, url
|
||||||
|
|
||||||
response = None
|
response = None
|
||||||
@ -116,17 +116,16 @@ class Downloader(Singleton):
|
|||||||
return 1, url
|
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, )):
|
if not isinstance(folder, (str, )):
|
||||||
folder = str(folder)
|
folder = str(folder)
|
||||||
|
|
||||||
if self.path:
|
if self.path:
|
||||||
folder = os.path.join(self.path, folder)
|
folder = os.path.join(self.path, folder)
|
||||||
|
|
||||||
if os.path.exists(folder + '.cbz'):
|
if file_type != '' and os.path.exists(folder + file_type) and not regenerate_cbz:
|
||||||
if not regenerate_cbz:
|
logger.warning(f'Skipped download: "{folder}{file_type}" already exists')
|
||||||
logger.warning(f'CBZ file "{folder}.cbz" exists, ignored download request')
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
logger.info(f'Doujinshi will be saved at "{folder}"')
|
logger.info(f'Doujinshi will be saved at "{folder}"')
|
||||||
if not os.path.exists(folder):
|
if not os.path.exists(folder):
|
||||||
@ -136,7 +135,7 @@ class Downloader(Singleton):
|
|||||||
logger.critical(str(e))
|
logger.critical(str(e))
|
||||||
|
|
||||||
if os.getenv('DEBUG', None) == 'NODOWNLOAD':
|
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
|
return True
|
||||||
queue = [(self, url, folder, constant.CONFIG['proxy']) for url in queue]
|
queue = [(self, url, folder, constant.CONFIG['proxy']) for url in queue]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user