LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 11-24-2007, 12:18 PM   #1
simonloach
LQ Newbie
 
Registered: Nov 2007
Posts: 2

Rep: Reputation: 0
Bash script for sorting and renaming multiple mp3 files by id3 tags


Hi I have several thousand mp3 files that I would like to sort into directories and rename so that they are all like:

/music/mp3/Artist-Album-Year/TrackNumber-Artist-TrackName.mp3

I have found a program that will return the data contained in the id3 tags (id3tool) and display it like:

./id3tool 10\ So\ Here\ We\ Are.mp3
Filename: 10 So Here We Are.mp3
Song Title: So Here We Are
Artist: Bloc Party
Album: Silent Alarm
Track: 10
Year: 2005
Genre: Rock (0x11)

I just need to find out how to create the directories and rename the files from the output of id3tool.

Thanks for any help.
 
Old 11-24-2007, 02:23 PM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Hi.

Code:
#!/bin/bash
TITLE="`id3tool "$1" | grep '^Song Title:' | awk '{ for (i=3;i<=NF;i++) { printf $i; printf " " } }'`"
ARTIST="`id3tool "$1" | grep '^Artist:' | awk '{ for (i=2;i<=NF;i++) { printf $i; printf " " } }'`"
ALBUM="`id3tool "$1" | grep '^Album:' | awk '{ for (i=2;i<=NF;i++) { printf $i; printf " " } }'`"
YEAR="`id3tool "$1" | grep '^Year:' | awk '{ for (i=2;i<=NF;i++) { printf $i; printf " " } }'`"
TRACKNUM="`id3tool "$1" | grep '^Year:' | awk '{ print $2 }'`"

install -D "$1" /music/mp3/"$ARTIST-$ALBUM-$YEAR"/"$TRACKNUM-$ARTIST-$TITLE".mp3
does what you're looking for.
 
Old 05-15-2009, 12:25 PM   #3
fancybone
LQ Newbie
 
Registered: May 2009
Posts: 1

Rep: Reputation: 0
Thanks, ilikejam, I modified your script to work with id3info instead of id3tool; I don't think id3tool supports id3v2.

Code:
#!/bin/bash
TITLE="`id3info "$1" | grep '^=== TIT2' | sed -e 's/.*: //g'`"
ARTIST="`id3info "$1" | grep '^=== TPE1' | sed -e 's/.*: //g'`"
ALBUM="`id3info "$1" | grep '^=== TALB' | sed -e 's/.*: //g'`"
YEAR="`id3info "$1" | grep '^=== TYER' | sed -e 's/.*: //g'`"
TRACKNUM="`id3info "$1" | grep '=== TRCK' | sed -e 's/.*: //g'`"

echo "$ARTIST $TITLE $ALBUM $YEAR $TRACKNUM"

mv $1 "$ARTIST - $ALBUM - $TRACKNUM - $TITLE.mp3"
 
Old 05-15-2009, 12:42 PM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
You may be interested in eyeD3, which let you rename the files specifying which tags you want to insert. For example:
Code:
eyeD3 --rename="%A - %a - %n - %t" $file
 
Old 05-16-2009, 06:55 AM   #5
simonloach
LQ Newbie
 
Registered: Nov 2007
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for the responses, but I think I solved this problem quite a long time ago. I'm sorry I didn't respond I must have completely forgot about this. Hopefully it will be of use to other people.
 
Old 12-29-2011, 05:28 PM   #6
dantheperson
LQ Newbie
 
Registered: Dec 2011
Posts: 2

Rep: Reputation: Disabled
and if you save that as reorg.sh you can process all files in a directory with:

for file in *; do reorg.sh $file; done
 
Old 12-29-2011, 06:24 PM   #7
dantheperson
LQ Newbie
 
Registered: Dec 2011
Posts: 2

Rep: Reputation: Disabled
Also, to cope with files that have the album track count


#cope with track count e.g. tracknum=10/11
CUTTRACKNUM="`echo $TRACKNAME | cut -c1-2`"
 
Old 09-08-2012, 02:03 PM   #8
aix_bloke
LQ Newbie
 
Registered: Jul 2004
Location: Spain
Posts: 5

Rep: Reputation: 0
Using the suggestions from colucix:
Quote:
eyeD3 --rename="%A - %a - %n - %t" $file
and the idea from dantheperson:
Quote:
for file in *; do reorg.sh $file; done
I have the following:
Code:
#!/bin/bash
# Next line added to cope with spaces in filenames
IFS="
"
for file in *.mp3
 do
    eyeD3 --rename="%A - %a - %n - %t" $file
 done
Hope this helps someone as the previous posts got me started on what I wanted to achieve.

Kevin
 
Old 02-16-2013, 10:07 AM   #9
koala
LQ Newbie
 
Registered: Feb 2013
Posts: 2

Rep: Reputation: Disabled
Lightbulb Full script to update ALL tags

Hi,

The script below asumes you have your music in directories in the form ".../Artist/Album/song-file.mp3", and you run the script from the Artist directory.

Hope you all find it usefull.

Cheers,

Kev

#! /bin/bash
for ART in *
do
if [ -d "$ART" ]
then
echo "++++++++++++++++++++++++++++++++++++++++"
echo "Artist: "$ART
echo "++++++++++++++++++++++++++++++++++++++++"
cd "$ART"
for SUB in *
do
if [ -d "$SUB" ]
then
cd "$SUB"
ALBUM=`pwd | awk -F\/ '{print $NF}'`
echo "Album: " $ALBUM
echo "========================"
for SONG in *mp3
do
TITLE=`echo $SONG | cut -d\. -f1 | tr "_" " "`
echo $TITLE
id3tag --song="\"$TITLE\"" $SONG
id3tag --album="\"$ALBUM\"" $SONG
id3tag --artist="\"$ART\"" $SONG
done
cd ..
fi
echo " "
done
cd ..
echo " "
fi
done
exit 0
 
  


Reply

Tags
bash, id3, mp3, rename


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Bash Script - Rename Multiple Files embsupafly Programming 16 04-02-2010 04:50 AM
slackware comes with any mp3, id3 tags manipulating utility? nass Slackware 2 06-26-2007 11:34 AM
Updating ID3 (MP3) Tags DJ747 Linux - Software 3 05-15-2005 12:22 PM
Need help with shell script - renaming multiple files NiallC Linux - Newbie 25 07-04-2004 11:45 AM
Sorting mp3s into folders by ID3 tags? deadjoebob Linux - Software 0 03-07-2004 01:21 PM


All times are GMT -5. The time now is 11:11 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration