-
-
Save SirFlobo/23f4b04db1e26d71185f55aa40a78a5a to your computer and use it in GitHub Desktop.
Looks recursively through a folder with funscripts and fixes the range value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import json | |
dryRun = True #Looks trough all the files but does not change anything | |
logChanges = True #Write a line to output when a file with mismatching range is found | Always prints when dryRun == True | |
makeBackup = True #Make a copy of the original script with .orig extenstion | |
newRange = 100 #New range to set in script file, -1 means use the maximum pos found in the script | |
def fixRangeFolder(path): | |
for entry in os.scandir(path): | |
if(entry.is_dir()): | |
fixRangeFolder(entry.path) | |
elif(entry.is_file() and os.path.splitext(entry.name)[1] == ".funscript"): | |
og_funscriptFile = open(entry.path, 'r', encoding="utf-8") | |
og_funscriptData = json.load(og_funscriptFile) | |
og_funscriptFile.close() | |
if "range" in og_funscriptData and og_funscriptData["range"] < 100: | |
if not dryRun and makeBackup: | |
backupFile = open(entry.path+".orig", 'w') | |
json.dump(og_funscriptData, backupFile) | |
backupFile.close() | |
maxAction = 0 | |
origRange =og_funscriptData["range"] | |
for action in og_funscriptData["actions"]: | |
if action["pos"] > maxAction: | |
maxAction = action["pos"] | |
if not dryRun: | |
new_funscriptFile = open(entry.path, 'w', encoding="utf-8") | |
og_funscriptData["range"] = maxAction if newRange == -1 else newRange | |
json.dump(og_funscriptData, new_funscriptFile) | |
new_funscriptFile.close() | |
if logChanges or dryRun: | |
print(f"Modified range in file {og_funscriptFile.name}\nRange in file({entry.path}): {origRange}, max pos in data {maxAction}, new range: {og_funscriptData['range'] if not dryRun else 'not set'}") | |
if __name__ == "__main__": | |
if dryRun: | |
print("Dry run enable, not changes will be made") | |
fixRangeFolder(os.path.curdir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment