Set ID3 tags based on file names

De La Soul gave away free downloads of their whole collection for one day recently. Thank you De La Soul! Some of the albums are missing their ID3 tags, though, so I took the opportunity to learn a little about BASH and fix the situation.

This Script will take care of the tags for you on “De La Soul Is Dead.” You will have to modify it slightly for other albums, but that isn’t too hard :) Here are the tags for the first track as I found them:


$ id3 -l 01*
01. De La Soul - Intro.mp3:
Title : Artist:
Album : Year: , Genre: Unknown (255)
Comment: http://rappalata.net/ Track: 0

And here they are after running the script:


$ id3 -l 01*
01. De La Soul - Intro.mp3:
Title : Intro Artist: De La Soul
Album : De La Soul Is Dead Year: 1991, Genre: Unknown (255)
Comment: http://rappalata.net/ Track: 1

Here’s the script. You’ll have to uncomment some lines to make it work. If you’re not comfortable with that, you might want to think again about running scripts you found on the web 😉


#!/bin/bash

# After you're satisfied that the script does what
# you want, uncomment the five lines that do
# the real work.

find . -name "*.mp3" -print0 | while read -d $'\0' file
do
echo "$file"
TRACK="${file:2:2}" #The first two characters are the track number
TITLE="`echo $file | cut -c20-`" #Remove the first 20 characters.
TITLE="${TITLE%.mp3}" #remove the .mp3 from the end.
echo "$TITLE"
echo "$TRACK"
# id3 -y 1991 "$file"
# id3 -a "De La Soul" "$file"
# id3 -A "De La Soul Is Dead" "$file"
# id3 -t "$TITLE" "$file" #set the ID3 title tag to $TITLE
# id3 -T "$TRACK" "$file" #set the ID3 track number to $TRACK
done

 

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>