Skip to content

Instantly share code, notes, and snippets.

@beatlegeuse
Last active August 21, 2021 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beatlegeuse/ce48af2c63803cfe4226787e26e1cb5c to your computer and use it in GitHub Desktop.
Save beatlegeuse/ce48af2c63803cfe4226787e26e1cb5c to your computer and use it in GitHub Desktop.
metadataless mp3 & mp4 folder comparison
# Generate md5sum from mp3 file, excluding any ID3 tags
function mp3sum {
file="$(mktemp -p /dev/shm/)"
cp "$1" $file
eyeD3 --remove-all -Q $file >/dev/null 2>&1
hash=$(md5sum $file | cut -f 1 -d" ")
echo $hash "$1"
rm $file
}
# Generate md5sum from mp4/m4a file, excluding any metadata
function mp4sum {
file="$(mktemp -p /dev/shm/)"
mv $file $file.mp4
file=$file.mp4
cp "$1" $file
exiftool -ext mp4 -all= -overwrite_original -q $file
hash=$(md5sum $file | cut -f 1 -d" ")
echo $hash "$1"
rm $file
}
# All mp4 hashes in a directory - run this in each directory to compare
find -type f \( -name *.m4a -or -name *.mp4 \) -exec mp4sum {} \; > Internal-Music-mp4sum.txt
# All mp3 hashes in a directory - run this in each directory to compare
find -type f -name *.mp3 -exec mp3sum.sh {} \; > Internal-Music-mp3sum.txt
# Compare generated files
diff <(cat ~/Internal-Music-mp3sum.txt | sort | cut -f 1 -d" ") <(cat ~/External-Music-mp3sum.txt | sort | cut -f 1 -d" ") | grep '^>' | awk '{print $2}' | while read hash; do grep $hash External-Music-mp3sum.txt ; done | sort -k2 | less
diff <(cat ~/Internal-Music-mp4sum.txt | sort | cut -f 1 -d" ") <(cat ~/External-Music-mp4sum.txt | sort | cut -f 1 -d" ") | grep '^>' | awk '{print $2}' | while read hash; do grep $hash External-Music-mp4sum.txt ; done | sort -k2 | less
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment