import json import os import re #printTheSmallStuff = True printTheSmallStuff = False #folder for stoing 'character model -> json file and models files' modelsFolderDir = "models" #print(os.listdir(modelsFolderDir)) microModelsDictionary = {} masterModelsDictionary = {} mMDDirectory = '_MISSING_FILE_' mMDSpeakerName = '_MISSING_FILE_' mMDFolderName = '_MISSING_FILE_' mMDG_model = '_MISSING_FILE_' xxxx = """ masterModelsDictionary = { 'folder_name': { 'directory': mMDDirectory, 'speaker_name': mMDSpeakerName, 'G_model': mMDG_model } } """ def seekJsonSpk(jsonFile): if 'spk' in jsonFile: for key, value in data['spk'].items(): #the 'spk' 'key' has the sting value of the model speaker name #it needs to be converted+trimmed to str #print(key) realSpkKey = '' #if models has multiple keys in the 'spk', it will run a loop and pick the #last key whitch should be the model name for key in data['spk'].items(): #print(key) realSpkKey = str(key) collectSpkString = realSpkKey[2:-5] if (printTheSmallStuff): print(str(collectSpkString)) mMDSpeakerName = str(collectSpkString) grabTheSpeaker = mMDSpeakerName #print(mMDSpeakerName) #this is just 1 or 0 number, ignore it #print(value) return grabTheSpeaker #LOOP start for modelsSubfolderDir in os.listdir(modelsFolderDir): #print(modelsSubfolderDir) #make full directory 'models/modelsFolderName' root_folder = str(modelsFolderDir + '/' + modelsSubfolderDir) folder_name_str = str(modelsSubfolderDir) if (printTheSmallStuff): print(root_folder) for root, dirs, files in os.walk(root_folder): for file in files: if file.endswith('.json'): if (printTheSmallStuff): print(file) json_file = os.path.abspath(os.path.join(root, file)) #print(json_file) with open(json_file) as json_file: data = json.load(json_file) #generate the usable speaker as string thru runing funtion thu the value mMDSpeakerName = seekJsonSpk(data) if (printTheSmallStuff): print(modelsSubfolderDir + ' ___ ok') continue if file.startswith("G_"): if (printTheSmallStuff): print("G_model name is " + str(file)) mMDG_model = str(file) #build the models dictionary for the UI mMDDirectory = str(root_folder) mMDFolderName = str(modelsSubfolderDir).replace(" ", "_") new_dir_values = {'folder_dir': str(mMDDirectory), 'speaker_name': str(mMDSpeakerName), 'char_folder': str(modelsSubfolderDir), 'g_Model': str(mMDG_model)} #masterModelsDictionary[mMDFolderName].update(new_dir_values) #make small dictionary and feed it back into the bigger dictionary microModelsDictionary.update(new_dir_values) masterModelsDictionary[mMDFolderName] = microModelsDictionary #print(folder_name_str, " | ", mMDDirectory, " | ", mMDSpeakerName, " | ", mMDFolderName, " | ", mMDG_model) #print(mMDSpeakerName) print("___________________________") #print(microModelsDictionary) print(masterModelsDictionary)