Let’s redo our mp3 ID3v2 Tags recursively

5 05 2010

So you have a bunch of mp3s that you want/need to tag/re-tag. You could use some of the fancy GUI programs out there. Kid3 and Easytag are just two that come to mind. Unfortunately you’ll have to input/type quite a bit if you have a lot of mp3s. So why not have your computer do it for you? So using some standard commands and a couple of packages most distros might have in their repositories we can accomplish it rather easily.
While this script will only tag your mp3s based on its file path it is not that hard to modify. Using a clever combination of file, cut, awk and sed you can add all the tags id3tag(part of the id3lib package) handles: artist, album, song, comment, comment description, year, track, total number of tracks, and genre.
I use either v2strip or the id3v2 packages to strip the tags. If you have one and not the other just comment/uncomment the appropriate one.

While this script shouldn’t do any unreparable damage to your files always test first on a copy.

———————-

#!/bin/bash

## Description: This script will traverse a directory, find mp3s, strip all ID3 tags(both ID3v1 and ID3v2),
## then re-tag them based on the directory structure.
## Existing file structure MUST be ./artist/album/song.mp3
## Depends: id3lib – http://id3lib.sourceforge.net
## id3v2 – http://id3v2.sourceforge.net
## v2strip(optional) – google it if you distro doesn’t have it.

IFS=$’\t\n’

for i in $( find . -iname ‘*.mp3′ )
do

# Let’s get the existing tags out of there.

id3v2 -D “$i”
# v2strip “$i”

if [ -f "$i" ];then

artist=$(echo “$i” | awk -F/ ‘{print $2}’)
album=$(echo “$i” | awk -F/ ‘{print $3}’)
title=$(echo “$i” | awk -F/ ‘{print $4}’)

nice -n 19 id3tag -2 –artist=”$artist” –album=”$album” –song=”$title” “$i”

fi
done


Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.