#!/bin/bash # Function to check if config.json already exists in a subfolder and if an image file exists check_exists() { local folder="$1" local config_file="$folder/config.json" local icon_file=$(find "$folder" -maxdepth 1 -type f \( -iname "*.jpg" -o -iname "*.gif" -o -iname "*.png" \) -print -quit) if [ -f "$config_file" ]; then if [ -n "$icon_file" ]; then icon=$(basename "$icon_file") fi return 0 else return 1 fi } # Function to update config.json if there are missing fields update_config() { local folder="$1" local config_file="$folder/config.json" local model_file=$(find "$folder" -maxdepth 1 -type f -name "*.pth" -exec basename {} \; -quit) local feat_index_file=$(find "$folder" -maxdepth 1 -type f -name "*.index" -exec basename {} \; -quit) local feat_npy_file=$(find "$folder" -maxdepth 1 -type f -name "*.npy" -exec basename {} \; -quit) # Remove the .pth extension from the model file name local name=$(basename "$model_file" .pth) # Replace underscores with spaces, remove "RVC" or "(RVC)", "Epoch", square brackets, parentheses, and curly brackets from the folder name, # and replace any occurrences of consecutive spaces with a single space local note=$(basename "$folder" | sed 's/_/ /g; s/\(RVC\)//g; s/RVC//g; s/[(){}]//g; s/\[\]//g; s/Epoch//g; s/ */ /g; s/^ //; s/ $//') # Set other configuration values local speaker_id=0 local author="Rubin" local source="Rubin" local icon="" if check_exists "$folder"; then if [ -n "$icon" ]; then icon=$(basename "$icon_file") fi # Update the fields for the existing config.json # Creating a new json string with the updated fields local new_config=$(cat < "$config_file" echo "Updated config.json file in $folder" else # Create the config.json file cat > "$folder/config.json" <