Finding Corrupt MP3s in Library
A while ago, I had a harddrive failure which resulted in me having to rebuild/reinstall the ReiserFS. As a result, some of my MP3 collection was corrupted. I'd say 90%ish of my Mp3s are fine, but there are a few that either won't play, or will gum up Amarok. In either case, there are enough corrupted files that Amarok can't finish building a collection (dies at 98% complete).
Since I have over 6000 songs, and I'd really rather not go through and just re-rip/encode everything, is there some sort of script or other doo-dad that will go through my collection and identify corrupt files for me? Thanks for your help! |
Well you could file them (see $(man file)); any file that doesn't identify as MP3 will most probably be corrupt.
|
This worked for me:
Code:
file * | grep -v 'MP3 file with' | less -S |
Thanks. That does help with finding the more corrupt ones. Is there a way to pipe a rm command to remove anything that isn't a valid MP3 file?
Also, is there a way to find those MP3s that checkout ok, but are either cut short or are scrambled on playback? |
You could try mp3info. For instance, the following 'find' construct will find all the mp3 files in the current directory (and below), and check them for errors. It prints a message if any corrupt ones are found.
Code:
find . -iname '*.mp3' -exec sh -c \ Hope this is what you want, but be aware that it will pick up mp3's with even a little corruption. These would probably play okay, so you might want to increase the error check value. Also, it'd probably be better to just move the corrupt ones to a temporary directory for checking manually. Have a play. Good luck edit: Changed it according to archtoad's suggestions. Never realised about Konqueror. And it does make it easier to read. Cheers. |
beadyallen,
Please do me & all other Konqueror users a favor: edit your post to break your code into multiple lines -- it's not handled right by the browser, it's triggering horizontal scrolling that makes all posts difficult to read. I believe this is a stylesheet problem & I believe it's inherited from vBulletin because other fora have the same problem. AND your code will be easier to read for everyone. TIA. dlackovic, Using find will solve the recursion/looping problem. Of course, it's possible that you might want to process your music dirs. one at a time -- that way you can re-rip/encode the bad ones & put the fresh copies where the old ones were. How do you want handle the replacement problem? Is it necessary to ID them all immediately, or just the ones that "gum up Amarok"? |
Thanks everyone for the info.
I was originally planning on going directory by directory, but archtoad6, are you saying that the Find will recurse through all the directories of my music folder? If that's the case I can redirect that echo part of the above command to dump to say, a text file so that then I'd have a list of all the bad files, right? |
Try this:
Code:
find . -maxdepth 1 -iname '*.mp3' -exec sh -c 'curfname="{}";\ |
Quote:
|
Hey thanks a bunch, beadyallen. That code works like a dream for me.
|
Now that I'm looking through the data, I'm noticing that the find didn't log any of the files too corrupt to even be recognized as an mp3. I found that I can make a log file that points out the corrupt files using archtoad6's code:
Code:
File * | grep -v 'MP3 file with' | tee ./corruptfiles |
Quote:
|
Quote:
Code:
find . -iname '*.mp3' -exec sh -c Code:
curfname="{}";\ Anyway, now it's got the number of errors in the file, there's a check to see if 'errors' is more than zero (i.e. there IS an error in the file). If there is, then we output something to standard output. So, to grab both totally knackered (not even recognized as mp3), and sightly corrupt (a few bad blocks but still 'playable') files, you'd just need to first check if the mp3 was recognized, before you check for bad blocks. Something like this should work: Code:
find . -iname '*.mp3' -exec sh -c 'curfname="{}";\ To be honest, the script is getting a bit long, so it might be better to create a separate 'check.sh' file, containing the check lines, and then call that from find, with Code:
find . -iname '*.mp3' -exec check.sh {} \; |
@beadyallen, your script runs fine and recurses. It does identify corrupt mp3s (i see this in the console output) except at the end all I get is an empty allbad.log file :(
|
Well all I can say is it works okay for me. Are you copying and pasting from the post, or are you typing it in? Sounds like you've made a typo somewhere. Especially as the output seems to be working, just the log file isn't created.
Are you working from the full command, or have you split it up and created a check.sh? |
I've done it typing the command, copying and pasting and by splitting and creating a check.sh. The result is the same everytime an empty logfile. I'll test it on an album I know contains faulty mp3s, when I can remember where I put the thing!! Thanks for your input :)
|
Thanks again beadyallen, that worked perfectly. I had pretty much figured out your script as to what it did, but I didn't know how to trap the errors. Thanks everyone for the help; I definitely learned a little more about scripting with this (which is great).
|
Drew,
Sorry, I've been out of touch for a couple of days & am just catching up @ LQ. Glad I could help even a little bit. beadyallen, Great scripting & explanations, you did much better than I could have. |
All times are GMT -5. The time now is 02:41 AM. |