Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Description: Scales up blur (and distance) from multiple SWF XML outputted by JPEXS
- # Author: Hey.youcp
- # Date: November 3, 2016
- # Note: Modified from original blur rescaler (http://pastebin.com/HwY4w90K)
- # Import glob (for finding files in directory) and regex (for finding certain strings in XML)
- import glob, re
- # This should be the same as your content scale in Kurst (you can change it back to a set value if you want)
- scale = float(input("Enter scale value: "))
- # For keeping count of the amount of XML files found
- filesFound = 0
- # Go through each XML file in the present working directory
- for inputFile in glob.glob("*.xml"):
- # Set name of output file ("<filename>-blur-rescaled.xml")
- outputFile = inputFile[:-4] + "-blur-rescaled.xml"
- # Open "<filename>.xml" as input file, "<filename>-blur-rescaled.xml" as output file
- with open(inputFile,"r",encoding="utf-8") as XML, open(outputFile,"w",encoding="utf-8") as output:
- print("\nOpened " + inputFile)
- # For keeping count of the amount of lines modified and processed
- linesModified, linesProcessed = 0, 0
- # Regex search pattern for the following formats: 5.0, 15.5, 100.15, etc.
- pattern = "\d+\.\d+"
- # Go through each line in the XML file
- for line in XML:
- if "blurX=" in line:
- # Get blur values from line Example with scale = 2:
- blurX = re.findall('blurX="' + pattern + '"', line)[0] # blurX="5.0"
- blurY = re.findall('blurY="' + pattern + '"', line)[0] # blurY="5.0"
- valueX = re.findall(pattern, blurX)[0] # 5.0
- valueY = re.findall(pattern, blurY)[0] # 5.0
- # Multiply blur values
- newX = str(float(valueX) * scale) # 5.0 * 2 = 10.0
- newY = str(float(valueY) * scale) # 5.0 * 2 = 10.0
- # Substitute old blur values with new values
- line = re.sub('blurX="' + pattern + '"', 'blurX="' + newX + '"', line)
- line = re.sub('blurY="' + pattern + '"', 'blurY="' + newY + '"', line)
- # Increment amount of lines modified
- linesModified += 1
- # Multiply distance value (same process as commented above)
- if "distance=" in line:
- distance = re.findall('distance="' + pattern + '"', line)[0]
- value = re.findall(pattern, distance)[0]
- newDistance = str(float(value) * scale)
- line = re.sub('distance="' + pattern + '"', 'distance="' + newDistance + '"', line)
- linesModified += 1
- # Increment amount of lines processed
- linesProcessed += 1
- # Write line to output file
- output.write(line)
- print(str(linesModified) + " lines were modified out of " + str(linesProcessed) + " lines in total.")
- # Increment amount of XML files found
- filesFound += 1
- # If files were found, print the amount found; else print no files found
- if filesFound != 0:
- print("\n" + str(filesFound) + " XML files were processed.")
- else:
- print("No XML files were found in the directory.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement