LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-13-2009, 12:58 PM   #1
couchquail
LQ Newbie
 
Registered: Jul 2008
Distribution: zenwalk
Posts: 3

Rep: Reputation: 0
Help with an id3tag script


I'm pretty new to bash scripting so some of the stuff is simple, most aren't.

What I'm looking for is a script that will read all my mp3 tags within a directory using id3info and rewrite them with a predefined format using id3tag.

What I do is move a group of mp3s(a 100 or so) to a directory named couch'compilation or such, then I have to manually change the id3 tags on each one to include the artist in the title, rename the album to the directory name and change the artist to me and strip the current track number.

What I've got so far pretty much doesn't do anything.
Code:
#!/bin/bash -
#
# convert title to artist - title
#

function year {
	id3info "$i" | grep TYER | cut -d":" -f2 | sed 's '
	}
function genre {
	id3info "$i" | grep TCON | cut -d":" -f2 | sed 's '
	}
function title {
	id3info "$i" | grep TIT2 | cut -d":" -f2 | sed 's ' 
	}
function artist {
	id3info "$i" | grep TPE1 | cut -d":" -f2 | sed 's '
	}
function album {
	id3info "$i" | grep TALB | cut -d":" -f2 | sed 's '
	}
function track {
	id3info "$i" | grep TRCK | cut -d":" -f2 | sed 's '
	}
function bit {
	id3info "$i" | grep Bitrate | cut -d":" -f2 | sed 's '
	}
function freq {
	id3info "$i" | grep Frequency | cut -d":" -f2 | sed 's '
	}

for i in *.mp3
do
nice -n 19 id3tag -2 --song='$artist" - "$title' "$i" 
done
and the output from id3tag and id3info

Code:
couch[test]$ id3info *.mp3 

*** Tag information for 01 The Look of Love.mp3
=== TYER (Year): 0
=== TCON (Content type): New Wave
=== TIT2 (Title/songname/content description): The Look of Love
=== TPE1 (Lead performer(s)/Soloist(s)): ABC
=== TALB (Album/Movie/Show title): The Ultimate hits of the 80's
=== TRCK (Track number/Position in set): 1/109
*** mp3 info
MPEG1/layer III
Bitrate: 160KBps
Frequency: 44KHz

couch[test]$ id3tag --help
id3tag 
Usage: id3tag [OPTIONS]... [FILES]...
   -h         --help            Print help and exit
   -V         --version         Print version and exit
   -1         --v1tag           Render only the id3v1 tag (default=off)
   -2         --v2tag           Render only the id3v2 tag (default=off)
   -aSTRING   --artist=STRING   Set the artist information
   -ASTRING   --album=STRING    Set the album title information
   -sSTRING   --song=STRING     Set the title information
   -cSTRING   --comment=STRING  Set the comment information
   -CSTRING   --desc=STRING     Set the comment description
   -ySTRING   --year=STRING     Set the year
   -tSTRING   --track=STRING    Set the track number
   -TSTRING   --total=STRING    Set the total number of tracks
   -gSHORT    --genre=SHORT     Set the genre
   -w         --warning         Turn on warnings (for debugging) (default=off)
   -n         --notice          Turn on notices (for debugging) (default=off)
I really don't know what I've done wrong.
Any help would be very appreciated
 
Old 08-13-2009, 02:01 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,834

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Do you really want to change the song title to include both the artist and title information? Why?

Well, for one thing this will not work:
Code:
id3tag -2 --song='$artist" - "$title' "$i"
Single quotes make everything inside them literal. So you're setting the title of the song to the literal string |$artist" - "$title|. You need to use double quotes only around variables, which still allow the values to be substituted.

(Unlike single quotes, double quotes allow $, ` and \ to be interpreted, which allows for variable and command substitutions and escape sequences.).

Actually, looking again, you're not even using variables, but functions. Functions aren't called by "$name", just "name" alone. So what you really need to be using is $(command) substitution:
Code:
id3tag -2 --song="$(artist) - $(title)" "$i"
Next, you're doing a lot of unecessary work to process the fields in your functions. Sed can do it all by itself. Try this:

Code:
id3info "$i"|sed -rn '\|TALB| s|.*:[ ](.*)$|\1|p'
You can learn more about sed here.


Finally, I've been working on something similar (but more complex) myself for the last week, and I've found that working with music metadata is a real pain, particularly when trying to work with multiple formats. I don't see id3info/id3tag available on Debian, but for mp3 files I've had better success with mid3v2, the python-based tag reader. It has a much easier input and output format for using in shell scripts. You might give it a try.


Edit: One more thing I just noticed. You're simultaneously reading information from and writing to the same file. I'm not sure that's safe. It would be better for you to read the tag information into variables first and then write out the new values only after you have everything extracted.

Last edited by David the H.; 08-13-2009 at 02:05 PM.
 
Old 08-13-2009, 04:19 PM   #3
couchquail
LQ Newbie
 
Registered: Jul 2008
Distribution: zenwalk
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks alot
Your
Code:
id3tag -2 --song="$(artist) - $(title)" "$i"
worked like a charm.

Why do I do this?
My mp3 player(Philips GoGear 4gb) doesn't do playlists very well. When I do it this way it reads the title of the mp3 which now includes the artist. I can also change 'playlists' by selecting a new album.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 09:40 AM
MySQL Updates With Null When Perl Script Run From Shell Script ThisGuyIKnow Programming 6 08-12-2008 10:56 AM
Shell Script: want to insert values in database when update script runs ring Programming 2 10-25-2007 11:48 PM
Problems with ID3Tag when installing GTKPod stevo22 Linux - Newbie 3 08-24-2005 06:40 PM
how to make filename match id3tag? rickenbacherus Linux - Software 5 11-18-2003 07:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration