Results 1 to 6 of 6

Thread: [SOLVED] Script for editing id3 tag

  1. #1
    Join Date
    May 2007
    Beans
    4

    [SOLVED] Script for editing id3 tag

    I'm new to ubuntu and I would like to know if there is a way to edit the id3 tags of all my mp3 files. They are organized like this:

    ./Artist Name/Album Name/Track Number - Track Name.mp3

    Is it possible to make a script that will edit for each file the information for track name, track number, album name and artist name?

    Thanks
    best regards
    Denis

  2. #2
    Join Date
    Jun 2005
    Location
    North Carolina
    Beans
    388
    Distro
    Ubuntu

    Re: Script for editing id3 tag

    Do you know much about writing scripts? The command line utility that will do the job is mid3v2, see...

    Code:
    man mid3v2
    for instructions on using the command. You will need to write a script lists all of the filenames in the directory and then acts on the files one by one. Extracting information from the directories is possible (see pwd), but not easy.

    The script would work/look something like this...

    Code:
    #!/bin/sh
    
    TEMPLIST=/tmp/tempfile.`date +%s`_$RANDOM
    ls -- *.mp3  >$TEMPLIST 2>/dev/null
    
    while read FileFromList
       do
          command to extract information from path, e.g., pwd
          command to extract track number and title from file
          mid3v2 with the necessary options to write the tags
       done < $TEMPLIST
    
    rm -f $TEMPLIST
    That's just a start.
    Last edited by apswartz; July 18th, 2008 at 05:35 AM.
    When you've found an adequate answer to your post, click on "thread tools" and mark the thread as solved.
    If you find an answer on your own or elsewhere, share it here and mark the thread as solved.

  3. #3
    Join Date
    Jun 2005
    Location
    North Carolina
    Beans
    388
    Distro
    Ubuntu

    Re: Script for editing id3 tag

    You will want to look at sed and awk...

    Code:
    man sed
    man awk
    When you've found an adequate answer to your post, click on "thread tools" and mark the thread as solved.
    If you find an answer on your own or elsewhere, share it here and mark the thread as solved.

  4. #4
    Join Date
    Aug 2006
    Location
    Thailand
    Beans
    1,667
    Distro
    Ubuntu 10.04 Lucid Lynx

    Talking Re: Script for editing id3 tag

    If you would like a GUI editor for your music files EasyTag is very good.

    To install it, just type this into a terminal screen.

    sudo apt-get install easytag

    Here's the SourceForge website, if you would like to check out screenshots, documentation, etc.:

    http://easytag.sourceforge.net/

    Regards,
    Roger
    There are only two things in life that are mandatory.
    Birth and Death.
    Everything else is optional.
    Ubuntu User #10495

  5. #5
    Join Date
    May 2007
    Beans
    4

    Re: Script for editing id3 tag

    This shellscript worked for me. I used the id3v2 command to edit the tags

    Code:
    #!/bin/bash
    
    for i in *
    do
        if test -d "$i"
        then
            pushd "$i"
            for j in *
            do
                if test -d "$j"
                then
    		pushd "$j"
    		if test -d CD1
    		then
    		    for kk in CD*
    		    do
    		    pushd "$kk"
    		    for k in *.mp3
    		    do
    		        echo "$k" | \
    		        awk -v Artist="$i" -v Album="${j}-${kk}" -v MusicFile="$k" -F"(.mp3| - )" '{ print "id3v2 -T \""$1"\" -t \""$2"\" -a \""Artist"\" -A \""Album"\" \""MusicFile"\"" }' | bash
    		    done
    		    popd
    		    done
    		else
    		for k in *.mp3
    		do
    		    echo "$k" | \
    		    awk -v Artist="$i" -v Album="$j" -v MusicFile="$k" -F"(.mp3| - )" '{ print "id3v2 -T \""$1"\" -t \""$2"\" -a \""Artist"\" -A \""Album"\" \""MusicFile"\"" }' | bash
    		done
    		fi
    		popd
                fi
            done
            popd
        fi
    done
    I had to add a case because some of my albuns are double and in this case they are organized like this:

    ./Artist Name/Album Name/CD*/Track Number - Track Name.mp3

    Thanks for everyone that helped.

  6. #6
    Join Date
    Jun 2005
    Location
    North Carolina
    Beans
    388
    Distro
    Ubuntu

    Re: [SOLVED] Script for editing id3 tag

    Wow! Great job!
    When you've found an adequate answer to your post, click on "thread tools" and mark the thread as solved.
    If you find an answer on your own or elsewhere, share it here and mark the thread as solved.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •