def ProcessConversionList(conversionOptions):
        i = 0
        if conversionOptions.conversion_FLAG:
            if not isImageLibAvailable():
                print "PIL (Python Image Library) not available."
            else:
                from ConvertPackage.ConvertFile import convertFile

                convertFileObj = convertFile()
                compressedFile, outputPath = ConversionQueue.pop()
                while compressedFile != None and outputPath != None:
                    i = i + 1
                    convertFileObj.convert(
                        compressedFile, outputPath, conversionOptions.Device, conversionOptions.verbose_FLAG
                    )
                    compressedFile, outputPath = ConversionQueue.pop()

        return i
Exemplo n.º 2
0
	def compress(self, manga_chapter_prefix, max_pages):
		"""
		Looks inside the temporary directory and zips up all the image files.
		"""
		if self.verbose_FLAG:
			print('Compressing...')
		
		compressedFile = os.path.join(self.mangadl_tmp_path, manga_chapter_prefix) + self.download_format
			
		z = zipfile.ZipFile( compressedFile, 'w')
		
		for page in range(1, max_pages + 1):	
			temp_path = os.path.join(self.mangadl_tmp_path, manga_chapter_prefix + '_' + str(page).zfill(3))
			# we got an image file
			if imghdr.what(temp_path) != None:
				z.write( temp_path, manga_chapter_prefix + '_' + str(page).zfill(3) + '.' + imghdr.what(temp_path))
			# site has thrown a 404 because image unavailable or using anti-leeching
			else:
				if manga_chapter_prefix not in self.garbageImages:
					self.garbageImages[manga_chapter_prefix] = [page]
				else:
					self.garbageImages[manga_chapter_prefix].append(page)
				
		z.close()
		
		if self.overwrite_FLAG == True:
			priorPath = os.path.join(self.download_path, manga_chapter_prefix) + self.download_format
			if os.path.exists(priorPath):
				os.remove(priorPath)
		
 		shutil.move( compressedFile, self.download_path)
 		
 		# The object conversionQueue (singleton) stores the path to every compressed file that  
 		# has been downloaded. This object is used by the conversion code to convert the downloaded images
 		# to the format specified by the Device parameter
 		
		compressedFile = os.path.basename(compressedFile)
		compressedFile = os.path.join(self.download_path, compressedFile)
		ConversionQueue.append(compressedFile, self.OutputDir)