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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
11-24-2007, 11:18 AM
|
#1
|
|
LQ Newbie
Registered: Nov 2007
Posts: 2
Rep:
|
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.
|
|
|
|
11-24-2007, 01:23 PM
|
#2
|
|
Senior Member
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109
Rep:
|
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.
|
|
|
|
05-15-2009, 11:25 AM
|
#3
|
|
LQ Newbie
Registered: May 2009
Posts: 1
Rep:
|
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"
|
|
|
|
05-15-2009, 11:42 AM
|
#4
|
|
Moderator
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.4 OpenSuSE 12.2
Posts: 9,893
|
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
|
|
|
|
05-16-2009, 05:55 AM
|
#5
|
|
LQ Newbie
Registered: Nov 2007
Posts: 2
Original Poster
Rep:
|
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.
|
|
|
|
12-29-2011, 04:28 PM
|
#6
|
|
LQ Newbie
Registered: Dec 2011
Posts: 2
Rep: 
|
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
|
|
|
|
12-29-2011, 05:24 PM
|
#7
|
|
LQ Newbie
Registered: Dec 2011
Posts: 2
Rep: 
|
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`"
|
|
|
|
09-08-2012, 01:03 PM
|
#8
|
|
LQ Newbie
Registered: Jul 2004
Location: Spain
Posts: 5
Rep:
|
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
|
|
|
|
02-16-2013, 09:07 AM
|
#9
|
|
LQ Newbie
Registered: Feb 2013
Posts: 2
Rep: 
|
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
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:10 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|