Damon Cortesi's blog

Musings of an entrepreneur.

More Grepping - Mp3's This Time!

| Comments

So my personal laptop’s hard drive recently bit the dust, or so I think. I haven’t had time to bring it in and get it checked out…but it doesn’t boot and it makes a strange, repeating sound that doesn’t sound so good when I try to boot it up. It’s not a clicking, per-say, but more of what seems like a failure of the actuator arm trying to move across the platter. …but what do I know?

In any case, I’ve been managing my music libraries across a couple different computers but since my personal one went down I’ve been looking for a way to re-populate some of my smart playlists that were based on comments. One of the most common ways I use these is for categorizing dance music. For example, if I’m listening a song and I think it’s a good swing song I’ll update the comment to include “Dance, Swing”. And then I just have a Smart Playlist that looks for comments with Swing in them.

The problem is, many of these songs weren’t in my other library. I keep most of my music on a shared server, so luckily I didn’t lose it. But what I wanted to do was go through my music library (several thousand songs as of this writing) and figure out which songs I had tagged with those specific Dance comments. The UNIX command-line to the rescue!

There’s a tool out there called id3v2 that reads ID3 information from mp3 files (the majority of my collection). Using that and the wonders of find and grep, I was able to list out which files contained the Dance comment:

1
find /mp3/ -name "*.mp3" -exec sh -c 'id3v2 -l "$1" | egrep "COMM.*Dance.*" && echo $1' '{}' '{}' \; | tee dance_mp3.txt

I had to do a little fu to be able to use pipes in the exec command, but I found out how to do that on this useful article.

I wish I had been syncing playlists (among other useful things…:-() before the drive failure, but alas…

Comments