Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have many mp3 songs in a directory and I want to sort them by artist such that each artist name is a directory containing that artist's music.

share|improve this question
2  
... Well... I'm afraid this question is terribly unclear, you should consider rewriting it so that you can get some answers. It is very hard to answer something that makes no sense. Thanks. –  Josiah Oct 5 '12 at 18:06
    
Is the artist's name in the filename? Is there an unambiguous way to extracting the artist name from the filename or from the file content? –  wallyk Oct 5 '12 at 18:18
    
This does not belong on stackoverflow, the OP had not asked for a "programmatic" solution that came from a subsequent edit. I have changed it to batch. It is perfectly on topic here, see my answer below. –  terdon Oct 5 '12 at 18:34
    
@terdon The reason this seems to belong on stackoverflow is because the user had tagged this question as unix-programming. –  Ganesh R. Oct 5 '12 at 18:37
3  
If this question is about simple Unix shell scripting and usage (and it really looks like it), it is on topic on Super User. But please also note that existence of tags does not make tagged questions on topic. –  Daniel Beck Oct 5 '12 at 19:08
show 2 more comments

closed as not constructive by Dave M, Indrek, MaQleod, Mokubai, 8088 Oct 5 '12 at 20:50

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers

This assumes your mp3 tags are in id3v2 format. id3v1 formats things a little differently. I recommend something like mediainfo for that. This example uses id3v2

for file in *.mp3; do
    IFS=$':'
    artist="$(id3v2 -l "${file}" | grep "TPE1" | awk '{ print $2 }')"
    # Your artist name is now stored in $artist.
    # This example just creates an artist directory and moves the file into it.
    # Terrible way to organize music, but this is a demonstration!
    [[ ! -d "${artist}" ]] && mkdir -p "${artist}"
    mv -f "${file}" "${artist}"
done

A real solution is to use something like MusicBrainz Picard.

share|improve this answer
    
What if there are multiple files from the same artist? Will this handle that scenario? –  Ganesh R. Oct 5 '12 at 18:28
    
It will move ALL songs by the same artist into the same artist folder. This assumes that all files are already tagged properly. –  UtahJarhead Oct 5 '12 at 18:30
    
Read the comments in that script. Don't just run what I posted and call it good. –  UtahJarhead Oct 5 '12 at 18:33
add comment

I am not sure what OS you are on, but since your question was tagged as Unix-programming I will assume you are on an *ix. So, if you can install id3tool you could run the following BASH command line:

find . -name "*.mp3" | while read n; do 
    dir=`id3tool "$n" | grep Artist | cut -f 3 | sed 's/\s*$//'`; 
    mkdir -p "$dir"; 
    mv "$n" "$dir"/"$n" ; 
done

EXPLANATION:

This little script will loop through each of your mp3 files, extract the artist's name using id3tool and save it in the variable $dir. It will then create a directory with the artist's name (unless it already exists) and proceed to move the file into that directory.

You can also do this in a GUI way by using music players such as amarok that offer this feature (or at least it used to). There are also various id3 editors, just search through your favorite software source, at least some of which should also be able to do this.

share|improve this answer
1  
And, of course, I now see that @UtahJarhead has given essentially the same answer while I was writing mine. Oh well :) –  terdon Oct 5 '12 at 18:45
    
For the record, it's recommended to not use ` in bash scripts. They don't nest very well and it's easier to read $(). –  UtahJarhead Oct 5 '12 at 19:58
add comment

I would do this in Python, with the tool pointed out in this answer on Stack Overflow, eyeD3.

share|improve this answer
    
+1 I think this belongs on StackOverflow more than StackExchange –  Ganesh R. Oct 5 '12 at 18:17
    
Right. Corrected. Thanks! –  bernard paulus Oct 5 '12 at 18:21
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.