mirror of
				https://github.com/RicterZ/nhentai.git
				synced 2025-11-04 02:50:55 +01:00 
			
		
		
		
	improve download logic #343
This commit is contained in:
		@@ -88,10 +88,10 @@ def main():
 | 
				
			|||||||
            if not options.dryrun:
 | 
					            if not options.dryrun:
 | 
				
			||||||
                doujinshi.downloader = downloader
 | 
					                doujinshi.downloader = downloader
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                result = doujinshi.download(skip_exists=not options.regenerate)
 | 
					                if doujinshi.check_if_need_download(options):
 | 
				
			||||||
                # Already downloaded; continue on with the other doujins.
 | 
					                    doujinshi.download()
 | 
				
			||||||
                if not result:
 | 
					                else:
 | 
				
			||||||
                    continue
 | 
					                    logger.info(f'Skip download doujinshi because a PDF/CBZ file exists of doujinshi {doujinshi.name}')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if options.generate_metadata:
 | 
					            if options.generate_metadata:
 | 
				
			||||||
                generate_metadata_file(options.output_dir, doujinshi)
 | 
					                generate_metadata_file(options.output_dir, doujinshi)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,14 +72,34 @@ 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, skip_exists=True):
 | 
					    def check_if_need_download(self, options):
 | 
				
			||||||
        logger.info(f'Starting to download doujinshi: {self.name}')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        base_path = os.path.join(self.downloader.path, self.filename)
 | 
					        base_path = os.path.join(self.downloader.path, self.filename)
 | 
				
			||||||
        if (os.path.exists(base_path + '.pdf') or os.path.exists(base_path + '.cbz')) and skip_exists:
 | 
					
 | 
				
			||||||
            logger.info(f'Skip download doujinshi because a PDF/CBZ file exists of doujinshi {self.name}')
 | 
					        # 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
 | 
				
			||||||
 | 
					        if options.regenerate:
 | 
				
			||||||
 | 
					            return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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
 | 
					            return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # fallback
 | 
				
			||||||
 | 
					        return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def download(self):
 | 
				
			||||||
 | 
					        logger.info(f'Starting to download doujinshi: {self.name}')
 | 
				
			||||||
        if self.downloader:
 | 
					        if self.downloader:
 | 
				
			||||||
            download_queue = []
 | 
					            download_queue = []
 | 
				
			||||||
            if len(self.ext) != self.pages:
 | 
					            if len(self.ext) != self.pages:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -191,7 +191,7 @@ def generate_doc(file_type='', output_dir='.', doujinshi_obj=None, rm_origin_dir
 | 
				
			|||||||
    doujinshi_dir, filename = parse_doujinshi_obj(output_dir, doujinshi_obj, file_type)
 | 
					    doujinshi_dir, filename = parse_doujinshi_obj(output_dir, doujinshi_obj, file_type)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if os.path.exists(f'{doujinshi_dir}.{file_type}') and not regenerate:
 | 
					    if os.path.exists(f'{doujinshi_dir}.{file_type}') and not regenerate:
 | 
				
			||||||
        logger.info(f'Skipped download: {doujinshi_dir}.{file_type} already exists')
 | 
					        logger.info(f'Skipped {file_type} file generation: {doujinshi_dir}.{file_type} already exists')
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if file_type == 'cbz':
 | 
					    if file_type == 'cbz':
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user