Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have about 30K songs in mp3. I already organized/tagged them with Musicbrainz Picard. But Picard made an excess of folders and subfolders inside each other because of the tags. What I need now is a script to do the following inside the main music folder:

  1. To read each subfolder and move all the mp3 files inside the subfolder's folders to the main subfolder. For example:

     Music -  
       Offspring -
          Album 1 - 20 songs
          Album 2 - 30 songs
          Album 3 - 5 Songs
             Folder 1 - 2 Songs
             Folder 2 - 3 Songs
       Journey -
          Song Pack 1 - 2 Songs
               Packy 1 - 15 Songs
               Packy 2 - 20 Songs
               Packy 3 - 7 Songs
          Album 2 - 20 songs
          Whatever 3 - 10 Songs
    

After script they would be like this:

     Music -    
       Offspring - All Songs inside THIS folder. Not inside subfolders of Offspring.  
       Journey - All Songs inside THIS folder. Not inside subfolders of Journey.   

And so on..

So all the music for each subfolder of each music group should not have any more subfolders and all songs inside their respective sub-subfolders should be moved to the main sub-folder of the music group.

So when I check Music and I see the Bee Gees then I KNOW that all the songs are right there and not inside some subfolder of Bee Gees.

NOTE - In some cases there are more than 20 recursive sub-folders. An example is: Music/Lady Gaga/1/Album/Lady Gaga/2/2/2/1/1/1/1/3/3Album 2/Lady Gaga/1/1/1/SONG.mp3. In this case i want the son inside Music/Lady Gaga and eliminate the rest of the folders.

share|improve this question

4 Answers 4

up vote 2 down vote accepted
+50

I suggest the following (tested, but without warranty) script, to be run from the master directory, under which all artists directories live:

#!/bin/bash

for f in *; do
  find "$f" -mindepth 2 -type f -exec mv --backup=numbered -t "$f" {} +
done

for f in *; do
  find "$f" -mindepth 1 -type d
done |
  sort -r |
  while read d; do
    rmdir "$d"
  done

It also take care of duplicates and empty sub-directories removal.

share|improve this answer
    
I can confirm after passing this script, the 30K songs got down to 13K (64GB) and 3K folders. Tested in Banshee and as it looks not only did it organize it the way i wanted, but it did actually delete all empty sub-directories AND remove duplicates which obviously were a lot. I only wish I could give you more points since you just saved me several days of organizing my music. Many thanks enzotib. I can not give the bounty for the next 6 hours. –  Luis Alvarado Jun 16 '11 at 12:57
    
To be honest, name duplicates would be renamed by the script (see the --backup parameter to mv). This I meant when I writed "take care of duplicates", because I could not say in advance if they were true duplicates (same content), without further analysis. –  enzotib Jun 16 '11 at 13:15
    
Well it removed a lot of songs that when i checked with the original were already duplicated. –  Luis Alvarado Jun 16 '11 at 14:18

Have a look at Easytag Install easytag.

enter image description here

The scanner option (Scanner -> Rename Files and Directory) is capable to re-arrange your files based on parameters from the ID tag.

Example:

Artist/Track# - track name.ogg: %a/%n - %t

would result in:
Prince/07 - Purple Rain.ogg

share|improve this answer
    
Sorry but i can't seem to find the "Press Enter to start the renaming". I have the option ready but how to apply it. the only thing it does is scan and scan and scan. Takes several minutes to complete and does nothing. –  Luis Alvarado Jun 5 '11 at 21:39
    
It first loads all the music files; that will take some time if you have lots of music files. The renaming starts with the icon that represent a hard disc (in the top bar). Since I found out I can add arrows with shutter :D I updated the pix for you! –  Rinzwind Jun 5 '11 at 21:41
    
and make a backup first because I made a mess of my music files 1st time I used it ;) –  Rinzwind Jun 5 '11 at 21:45
    
My music folder is in /media/fun/music and I would like the artists to have their directory in it AND THEN the music. No subfolders for albums, years or whatever. Just for example /media/fun/music/blackeyedpeas/ALL SONGS HERE. Without subdividing them in albums. The way I put it was "/media/fun/music/%a/%t| Is this correct before I test if it works (Since it takes A LOT for 30K songs) –  Luis Alvarado Jun 5 '11 at 23:14
    
Tested with 10 folders and the subfolders inside them. It moved some but not all of them. For example, in cases where there were a lot of subfolders inside each other it did not move the song. In cases where the song was inside an album folder (like 2pac/album/song.mp3) it moved the song to music/2pac correctly. But this took a lot of time. For all songs it will take several hours. What am looking for is a script that using maybe a for can move this songs to the main folder of the artist. –  Luis Alvarado Jun 5 '11 at 23:44

If you have space enough to back up your music before you do this, you might want to do it. I tested it, but it comes with no warranty--if it breaks, you get to keep all the pieces.

I did this under the assumption (borne from your description) that you have a main folder subdivided by artist, further subdivided by album. If this matches your setup, continue.

In a terminal, cd into your music directory, and run this command (in bash):

for j in * ; do (cd "$j" ; (for i in * ; do (cd "$i" ; find . -name \*.[mM][pP]3 -exec mv {} . \; ) ; done)) ; done

If you have questions, just ask.

share|improve this answer

You might be able to modify the settings for Picard so that it doesn't create this directory hierarchy to begin with--tt is possible that it somewhat relies on these files remaining where it left them.

share|improve this answer
    
How would I go about doing that if you don't mind me asking? –  Luis Alvarado Jun 21 '11 at 4:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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