Occasionally, I have duplicated directories of mp3 file - for example when loading a second mp3 player with music. Then, later when trying to free up disk space, I have been unsure as to which directory to keep. This is complicated because mp3 files can have their headers updated which makes conventional 'diff' useless in determining whether files are identical. However, as noted yesterday, avconv can report the CRC signature of just the music, and you can use this to determine if two directories are really identical so that one can deleted.
I used two scripts to achive this. The first uses avconv to report the CRC of the supplied file. This is called, mp3crc.sh. The second called mp3rdiff.sh uses the first script and simply collects the CRC values of the mp3 files below a supplied pair of directories. After collection the CRCs are diffed, and the user informed of the results.
Here are the scripts. First mp3crc.sh:
#!/bin/sh export PATH=/opt/local/bin:/opt/local/sbin:$PATH avconv -i "$1" -f crc - 2>/dev/null | grep CRC | awk '{print substr($1,5)}'
And mp3rdiff.sh:
#!/bin/sh export PATH=/opt/local/bin:/opt/local/sbin:$PATH #provide a simple recursive mp3 diff based on checksums echo "Directory 1: $1" echo "Directory 2: $2" find "$1" -exec ~/bin/mp3crc.sh {} \; > /tmp/dir1.txt find "$2" -exec ~/bin/mp3crc.sh {} \; > /tmp/dir2.txt diff /tmp/dir1.txt /tmp/dir2.txt ret=$? if [ $ret -eq 0 ] then echo "The directories are identical" else echo "The directories are different" diff /tmp/dir1.txt /tmp/dir2.txt fi
Installing avconv on OS X involved following the instructions here: http://superuser.com/questions/568464/how-to-install-libav-avconv-on-osx