ID3 tagging script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ID3 tagging script
# 1  
Old 04-10-2007
ID3 tagging script

I'm trying to get a little script working with DropScript 0.5 that edits the ID3 tags of an MP3. Here's what I've got:

Code:
#!/bin/sh

# Strip directory part but leave extension.
in_base=`basename "$@"`
# Strip extension.
in_noext=`echo "$in_base" | sed 's/\.[^.]*$//'`

/opt/local/bin/id3v2 --TPE2 "$in_noext" "$@"

It works fine when I drop one file on it at a time, but when I drop more than one file on it, it's writing a list of all the files to each individual file. I know I need to replace the first
Code:
$@

with something that will only look at each file, not all the files. But I'm such a shell scripting newb, that I don't know what to replace it with. Any ideas?

Many thanks in advance for any help!
# 2  
Old 04-10-2007
I got some help via the DropScript author via email:

Quote:
This won't work:

Code:
in_base=`basename "$@"`

Because $@ is a list of files. You need a for loop, I figure.
Can anyone point me towards a for loop example?
# 3  
Old 04-11-2007
Quote:
Originally Posted by SimonDorfman
I'm trying to get a little script working with DropScript 0.5 that edits the ID3 tags of an MP3. Here's what I've got:

Code:
#!/bin/sh

# Strip directory part but leave extension.
in_base=`basename "$@"`
# Strip extension.
in_noext=`echo "$in_base" | sed 's/\.[^.]*$//'`

/opt/local/bin/id3v2 --TPE2 "$in_noext" "$@"

It works fine when I drop one file on it at a time, but when I drop more than one file on it, it's writing a list of all the files to each individual file. I know I need to replace the first
Code:
$@

with something that will only look at each file, not all the files. But I'm such a shell scripting newb, that I don't know what to replace it with. Any ideas?

Use a for loop.

In a POSIX shell, basename is not needed:
Code:
for file in "$@"
do
   in_base=${file##*/}
   in_noext=${in_base%.*}
done

# 4  
Old 04-11-2007
Thank you cfajohnson. The for loop seems to be working, but now I think I need a for loop for the id3v2 command because it's tagging each file with the first file's name. Or do I need to put the id3v2 command into the first loop somehow? Here's what I've got right now:

Code:
#!/bin/sh

# Strip directory and extension.
for file in "$@"
do
   in_base=${file##*/}
   in_noext=${in_base%.*}
done

# Tag each file's ID3 field "Album Artist" (a.k.a.-"Band/Orchestra/Accompaniment") with the file name
/opt/local/bin/id3v2 --TPE2 "$in_noext" "$@"

# 5  
Old 04-11-2007
I figured it out. Here's my working script. Again, thanks for the help!

Code:
#!/bin/sh

for file in "$@"
do
   # Strip directory and extension of each file.
   in_base=${file##*/}
   in_noext=${in_base%.*}

   # Tag each file's ID3 field "Album Artist" (a.k.a.-"Band/Orchestra/Accompaniment") with the file name
   /opt/local/bin/id3v2 --TPE2 "$in_noext" "${file}"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. What is on Your Mind?

Discussion (Thread) Tagging Upgrades

Dear All, I have made significant progress coding new discussion thread tagging features. As always, we want all users to tag thread and moderators to tag threads with relevant keywords. Moving forward, in addition to the #1 important "human tagging", we will also auto tag threads with one... (4 Replies)
Discussion started by: Neo
4 Replies

2. Solaris

Solaris 9 VLAN tagging with ce interface

Hi, Is it possible to VLAN tag with a ce interface on Solaris 9? Link speed is gb. ce:0:ce0:link_speed 1000 I have a ce0 interface I would need to have access to another VLAN as well as the one it's currently on. What commands would I need to run? Thanks.;) (2 Replies)
Discussion started by: sparcman
2 Replies

3. Shell Programming and Scripting

CVS Tagging Script

Hi All, We have to tag all source code files to prepare a release kit. We have one CVS Project under which all files have to be tagged. We use the following cvs command to tag a specific version of a file: 'cvs rtag -r X.XX -F "newbuild" somefile' This command asks for the CVS Login... (3 Replies)
Discussion started by: rahulrathod
3 Replies
Login or Register to Ask a Question