Strip All Unwanted MP3 ID3 Tags

Posted by admin on June 20, 2010 under Tech Tips | 11 Comments to Read

A while back, I wanted to find a tool that would go through my entire collection of MP3′s and remove all the extra ID3 tags I didn’t want. For example, when I purchase music from Amazon, Rhapsody, and other online music stores, there are a number of tags in the files that track things like the purchase date and sales transaction ID’s. I also like to get rid of annoying comments and other hidden tags that most editors won’t even show you.

In my search for a tool, I came across this very useful post outlining a similar project. In the authors quest to do the same thing, he came up with a shell script that searches for all MP3 files, and removes tags that are not in his list of “good” tags. I usually don’t like to rehash the work someone else has done, but since I use his script so often, I thought it would be useful to repost it with only minor modifications.

Prerequisite: Install eyeD3

The script requires the eyeD3 tag editor to parse and manipulate the tag data. So be sure to install eyeD3, which should be available in your favorite Linux repository.

sudo apt-get install eyed3

Save and Modify Script

Save the following script as strip-tags.sh somewhere in your executable path.

#!/bin/bash
# Script name: strip-tags.sh
# Original Author: Ian of DarkStarShout Blog
# Site: http://darkstarshout.blogspot.com/
# Options slightly modified to liking of SavvyAdmin.com
 
oktags="TALB APIC TCON TPE1 TPE2 TPE3 TIT2 TRCK TYER TCOM TPOS"
 
indexfile=`mktemp`
 
#Determine tags present:
find . -iname "*.mp3" -exec eyeD3 --no-color -v {} ; > $indexfile
tagspresent=`sort -u $indexfile | awk -F): '/^<.*$/ {print $1}' 
| uniq | awk -F)> '{print $1}' | awk -F( '{print $(NF)}' 
| awk 'BEGIN {ORS=" "} {print $0}'`
 
rm $indexfile
 
#Determine tags to strip:
tostrip=`echo -n $tagspresent $oktags $oktags 
| awk 'BEGIN {RS=" "; ORS="n"} {print $0}' | sort | uniq -u 
| awk 'BEGIN {ORS=" "} {print $0}'`
 
#Confirm action:
echo
echo The following tags have been found in the mp3s:
echo $tagspresent
echo These tags are to be stripped:
echo $tostrip
echo
echo -n Press enter to confirm, or Ctrl+C to cancel...
read dummy
 
#Strip 'em
stripstring=`echo $tostrip 
| awk 'BEGIN {FS="n"; RS=" "} {print "--set-text-frame=" $1 ": "}'`
 
# First pass copies any v1.x tags to v2.3 and strips unwanted tag data.
# Second pass removes v1.x tags, since I don't like to use them.
# Without --no-tagging-time-frame, a new unwanted tag is added.  :-)
 
find . -iname "*.mp3" 
-exec eyeD3 --to-v2.3 --no-tagging-time-frame $stripstring {} ; 
-exec eyeD3 --remove-v1 --no-tagging-time-frame {} ; 
 
echo "Script complete!"

To run the script, just execute it from the top level parent directory.

cd ~/Music/
strip-tags.sh

I really didn’t change a whole lot from the original, only making slight tweaks to eyeD3 options. For example, I removed colors from the eyeD3 output when creating the first list of tags, and added a line to remove v1.x ID3 tags since I don’t like to keep them around.

Be sure to edit the list of good tags identified by the “okaytags” variable. My preferred list includes the following:

oktags="TALB APIC TCON TPE1 TPE2 TPE3 TIT2 TRCK TYER TCOM TPOS"

TALB - Album/Movie/Show title
APIC - Attached picture (Album Art)
TCON - Content type (Genre)
TPE1 - Lead performer(s)/Soloist(s)
TPE2 - Band/orchestra/accompaniment
TPE3 - Conductor/performer refinement
TIT2 - Title/songname/content description
TRCK - Track number/Position in set
TYER - Year
TCOM - Composer
TPOS - Part of a set

Enjoy!

Be Sociable, Share!

Comments

  • Gerhard Burger said,

    You forgot to make the script executable:

    chmod +x /pathtoscript/strip-tags.sh

    very useful script though, thanks!

  • John said,

    I get this when I try to run it:

    awk: line 0: regular expression compile failed (missing ‘(‘)
    ):
    awk: line 0: regular expression compile failed (missing ‘(‘)
    )>

    The following tags have been found in the mp3s:

    These tags are to be stripped:

    Press enter to confirm, or Ctrl+C to cancel…

  • Harald Boehmecke said,

    Hi John,

    Found a solution to your problem:

    Replace:
    tagspresent=`sort -u $indexfile | awk -F): ‘/^ ‘{print $1}’ | awk -F( ‘{print $(NF)}’
    | awk ‘BEGIN {ORS=” “} {print $0}’`

    with:
    tagspresent=`sort -u $indexfile | awk -F”):” ‘/^” ‘{print $1}’ | awk -F”(” ‘{print $(NF)}’
    | awk ‘BEGIN {ORS=” “} {print $0}’`

    Oh, and thx for the script gmendoza. Great one!

    Regards,

    Harald

  • Manipulando Tags ID3 Com O eyeD3 | Daemonio Labs said,

    [...] [3] Strip All Unwanted MP3 ID3 Tags, by gmendoza (Acessado em: Novembro/2011) http://savvyadmin.com/strip-all-unwanted-mp3-id3-tags/ [...]

  • MrYoda said,

    Thanks so much! A minor tweak was needed with the awk commands (needed some ticks around the -F options). What a time saver as the script was 99% ready to go for me. I needed this to strip out all the unneeded ID3 tags for use in my car, which only displays artist, album, title/song, and genre. My car (Mini Cooper with USB/iPod option) was choking on all my music and I realized it was due to the 25GB+ of songs with so many unneeded tags. The mini stores 20,000 data points and with more than 4,000 songs and an average of 8 tags per, I was killing the car… anyway thanks because this SOLVED MY PROBLEMS! (For example these tags where stripped from my MP3s, imagine how much space it was taking in my car’s buffer… APIC COMM GEOB MCDI PCNT PRIV TBPM TCOM TCOP TDRC TENC TIPL TLEN TMCL TMED TOFN TOWN TPE2 TPE3 TPOS TPUB TRCK TSOP TSRC UFID).

  • andrew cooke said,

    if you have a lot of files it’s significantly faster to do:

    find . -iname “*.mp3″ -print0 | xargs -0 -n 10000 eyeD3 –no-color -v >> $indexfile

  • NotYetHappy said,

    Unfortunately, I can’t run your script under Ubuntu, I still get this error:
    awk: line 0: regular expression compile failed (missing ‘(‘)
    ”):”
    awk: 1: unexpected character 0xe2
    awk: line 1: runaway regular expression /^” …
    ./strip-tags.sh: Zeile 14: NF: Kommando nicht gefunden.
    awk: 1: unexpected character 0xe2
    awk: line 0: regular expression compile failed (missing ‘)’)
    ”(”
    awk: 1: unexpected character 0xe2
    awk: line 2: missing } near end of file

    I used your original script and then the modification in the second comment. What do I have to modify to run it successfully on Ubuntu?

  • NotYetHappy said,

    It’s me again.
    How could I set the missing language descriptor for the already existing comments? I would like to add ‘eng’ for all COMM-frames.
    eyeD3 has something like
    -c [LANGUAGE]:[DESCRIPTION]:COMMENT, –comment=[LANGUAGE]:[DESCRIPTION]:COMMENT
    but I have no idea, how I could add just the language ‘eng’ to the existing COMM value.

  • John said,

    Thanks for this. Works great and saved me a bunch of time.

  • mrmason said,

    Had same problem as John on Ubuntu 12.04. After trying Harald Boehmecke’s solution, I installed gawk and used original language. Ran perfectly.
    Just FYI, just before a re-ran the script I took out some odd looking green colored blocks that had suddenly appeared at the beginning of each blank line. I don’t think this was the problem as it wasn’t there in the original file I created. Still worth mentioning though.

  • Rainer said,

    in order to delete only the comment tag which is used for instance by amazon the following command is sufficient

    find . -name “*.mp3″ -exec eyeD3 –no-color –remove-comments {} ;

Add A Comment