LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-18-2005, 05:59 PM   #1
chazza
LQ Newbie
 
Registered: Dec 2003
Location: Manchester, UK
Distribution: Fedora Core
Posts: 17

Rep: Reputation: 0
Shell script using id3info to catalog mp3s


I'm looking for an easy way to catalog my mp3 files which are in an organised directory structure. I want to write a script that uses id3info to read each file in turn then output the tags to a .csv file but I can't see how to do this recursively so that it looks at each directory in turn.

find /mnt/mp3s -name *.mp3 > ~/mp3list.txt

will generate a list of filenames and paths but I can't work out how to pipe this list line by line to id3info (if this is the right approach!).

Any clues please ?
 
Old 04-18-2005, 07:03 PM   #2
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
You could try the following:-
Code:
for i in $(find /mnt/mp3s -type f -name "*.mp3" | tr " " "^"); do id3info "$(echo $i | tr "^" " ")"; done
The 'tr " " "^"' and 'tr "^" " "' is in case the are any file names with spaces in, as the 'for i in' uses spaces as a delimiter.

Of course, if you are likely to encounter a "^" in a file name you should change it for something more obscure.
 
Old 04-18-2005, 07:40 PM   #3
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Rep: Reputation: 61
You might also look at an available shell program named 'mp3info'
 
Old 04-19-2005, 04:55 AM   #4
chazza
LQ Newbie
 
Registered: Dec 2003
Location: Manchester, UK
Distribution: Fedora Core
Posts: 17

Original Poster
Rep: Reputation: 0
Cheers ! ....

... script worked a treat, thanks a lot.

Chas.
 
Old 04-19-2005, 06:43 AM   #5
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
Re: Cheers ! ....

Quote:
Originally posted by chazza
... script worked a treat, thanks a lot.

Chas.
Glad it helped, but this one is shorter, easier and quicker:-
Code:
find /mnt/mp3s -type f -name "*.mp3" -exec id3info {} \;
>Note to self - Do not post when tired.
 
Old 04-19-2005, 09:00 AM   #6
chazza
LQ Newbie
 
Registered: Dec 2003
Location: Manchester, UK
Distribution: Fedora Core
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks.

I didn't really think this through enough :-)

I assumed the output would be regular and parsable but unfortunately it only returns the tags where there is a value and you cannot request particular tags. Further it (id3info) does not always return the tags in the same order !

The script plus id3info currently returns a large file comprising something like as follows ....


*** Tag information for /mnt/mp3s/blur/13/01-tender.mp3
=== TIT2 (Title/songname/content description): Tender
=== TPE1 (Lead performer(s)/Soloist(s)): Blur
=== TALB (Album/Movie/Show title): 13
=== TYER (Year): 1999
=== COMM (Comments): ()[]:
=== TCON (Content type): (17)
=== TRCK (Track number/Position in set): 1
*** mp3 info
MPEG1/layer III
Bitrate: 320KBps
Frequency: 44KHz

*** Tag information for /mnt/mp3s/blur/13/02-bugman.mp3
=== TIT2 (Title/songname/content description): Bugman
=== TPE1 (Lead performer(s)/Soloist(s)): Blur
=== TALB (Album/Movie/Show title): 13
=== TYER (Year): 1999
=== COMM (Comments): ()[]:
=== TCON (Content type): (17)
=== TRCK (Track number/Position in set): 2
*** mp3 info
MPEG1/layer III
Bitrate: 320KBps
Frequency: 44KHz

.... but if the record length is not always consistent .... the "field" order not fixed ..... and the fields not fixed (!) ..... then I'm struggling.


In truth what I really want is a nicely formated row per record :-

/mnt/mp3s/blur/13|02-bugman.mp3|Bugman|Blur|13|1999|2|MPEG1/layer III|320KBps|44KHz

i.e. PATH|FILE|TRACKNAME|ARTIST|CDTITLE|YEAR|TRACKNUMBER|FORMAT|BITRATE|FREQUENCY

... or delimeted with "," or ";" or "~" or whatever.


AWK and SED just make my brain liquify and run out of my ears, but it should be doable I think. Is this really, really hard or am I just a dunce ?
 
Old 04-19-2005, 02:42 PM   #7
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Rep: Reputation: 61
Did you check out mp3info? ... Here's the man page ... http://www.die.net/doc/linux/man/man1/mp3info.1.html
 
Old 04-19-2005, 05:39 PM   #8
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
Quote:
Originally posted by chazza
Thanks.

I didn't really think this through enough :-)
...
In truth what I really want is a nicely formated row per record :-

/mnt/mp3s/blur/13|02-bugman.mp3|Bugman|Blur|13|1999|2|MPEG1/layer III|320KBps|44KHz

i.e. PATH|FILE|TRACKNAME|ARTIST|CDTITLE|YEAR|TRACKNUMBER|FORMAT|BITRATE|FREQUENCY

... or delimeted with "," or ";" or "~" or whatever.


AWK and SED just make my brain liquify and run out of my ears, but it should be doable I think. Is this really, really hard or am I just a dunce ?
It could be done, see http://www.tgunkel.de/software/files/mp32ogg for an idea how.

However rickh is right, the best tool for the job is mp3info. If you haven't got it, its less than 50Kb. http://www.ibiblio.org/mp3info/

Code:
find /mnt/mp3s/ -type f -name "*.mp3" -exec mp3info -p "%F - %t - %a - %l - %y - %n - MPEG%1.1v Layer %L - %rKBps - %qKHz\n" '{}' \;

Last edited by ahh; 04-19-2005 at 06:03 PM.
 
Old 04-19-2005, 10:32 PM   #9
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Rep: Reputation: 61
Thanks for the script. I knew it would work, but hadn't gotten around to figuring out the syntax yet.
 
Old 04-20-2005, 12:25 AM   #10
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Rep: Reputation: 61
Well had to figure out syntax anyway. Many of my files are ripped from vinyl, or I deleted the id3 tag for some reason. The information I want is Artist, Title, Size, Duration, and Bitrate. mp3info needs to compute it from scanning the file rather than getting it from a tag.

Works good, tho. Gives me a nicely delimited file with the info I want.

Also ... check out a program called Tellico for a library ... Near as I'm able to tell tho, you need this formatting tool to prepare data for import.

Last edited by rickh; 04-20-2005 at 12:33 AM.
 
Old 04-20-2005, 04:13 AM   #11
chazza
LQ Newbie
 
Registered: Dec 2003
Location: Manchester, UK
Distribution: Fedora Core
Posts: 17

Original Poster
Rep: Reputation: 0
Fantastic! ....

... It just works (tm) :-)

Thanks for all.
 
  


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
Shell script inside shell script treotan Linux - General 4 02-19-2009 07:34 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-12-2005 12:08 AM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 04:00 PM


All times are GMT -5. The time now is 10:40 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