Skip to content

Instantly share code, notes, and snippets.

@kristianfreeman
Last active December 13, 2023 16:45
Show Gist options
  • Save kristianfreeman/86bef61f6dceed5f1fc28c1b98e9a70d to your computer and use it in GitHub Desktop.
Save kristianfreeman/86bef61f6dceed5f1fc28c1b98e9a70d to your computer and use it in GitHub Desktop.
Restore metadata for files created using Ultimate Vocal Remover GUI - more details here: https://github.com/Anjok07/ultimatevocalremovergui/issues/394#issuecomment-1854286668
#!/bin/bash
# Loop over all files in the current directory with the format "{number}_{filename}_(Instrumental).flac"
for file in *.flac; do
# Extract the filename without the number and '(Instrumental)' part
filename=$(echo "$file" | sed -E 's/^[0-9]+_(.*)_\(Instrumental\)\.flac/\1/')
# Construct the path of the matching file in the parent directory
parent_file="../${filename}.flac"
# Check if the parent file exists
if [ -f "$parent_file" ]; then
# Copy the metadata from the parent file to the current file
# Requires 'ffmpeg' to be installed
ffmpeg -i "$file" -i "$parent_file" -map 0 -map_metadata 1 -c copy "temp_$file"
mv "temp_$file" "$file"
else
echo "Matching file for '$file' not found in parent directory."
fi
done
filebot -rename *.flac --format "{artist} - {album} - {pi.pad(2)} - {t}" --db ID3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment