SCATEBOARD
This commit is contained in:
44
wav/sp_db_maker.py
Normal file
44
wav/sp_db_maker.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
import json
|
||||
|
||||
def build_tree(root_dir):
|
||||
tree = {}
|
||||
|
||||
for root, dirs, files in os.walk(root_dir):
|
||||
# Skip hidden folders like .git, .idea, node_modules ghosts, etc.
|
||||
dirs[:] = [d for d in dirs if not d.startswith('.')]
|
||||
|
||||
rel_path = os.path.relpath(root, root_dir)
|
||||
folders = rel_path.split(os.sep) if rel_path != "." else []
|
||||
|
||||
current = tree
|
||||
|
||||
# Walk / create folder structure safely
|
||||
for folder in folders:
|
||||
# If this path key doesn't exist or got turned into something non-dict, fix it
|
||||
if folder not in current or not isinstance(current.get(folder), dict):
|
||||
current[folder] = {}
|
||||
current = current[folder]
|
||||
|
||||
# Register files
|
||||
for file in files:
|
||||
if file.lower().endswith(('.wav', '.wave', '.mp3', '.ogg')):
|
||||
file_name = os.path.splitext(file)[0]
|
||||
|
||||
# Only set to None if it doesn't already exist
|
||||
# (avoid overwriting a folder accidentally)
|
||||
if file_name not in current or not isinstance(current[file_name], dict):
|
||||
current[file_name] = None
|
||||
|
||||
return tree
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
root_directory = os.getcwd()
|
||||
tree = build_tree(root_directory)
|
||||
|
||||
output_filename = "sound_structure.json"
|
||||
with open(output_filename, "w") as f:
|
||||
json.dump(tree, f, indent=4)
|
||||
|
||||
print(f"Sound structure saved to {output_filename}")
|
||||
Reference in New Issue
Block a user