Mass .m3u creator

Discussion in 'Software for Windows' started by Venom20, Nov 3, 2012.

  1. Venom20

    Venom20 Senior member

    Joined:
    Apr 12, 2011
    Messages:
    259
    Likes Received:
    0
    Hello all, I'm looking to batch create ~500 m3u's. Currently in my music folder, each album is in it's own folder. Within that folder I'd like to place an m3u for that album. It is very tedious to create them manually, and I can use a few apps that i have to do them one at a time, but I'd like to just batch it. Any suggestions? So far the only thing I've located was a script, but apparently it is buggy.

    File structure:

    Code:
    --Music
         -- Atreyu - The Curse
              -- 01 - Blood Children (An Introduction).mp3
              -- 02 - Bleeding Mascara.mp3
              -- etc.
         -- Black Label Society - Shot To Hell
              -- 01 - Concrete jungle.mp3
              -- 02 - Black mass reverends.mp3
              -- etc.
         -- etc.
     
  2. Gooberlx2

    Gooberlx2 Lifer

    Joined:
    May 4, 2001
    Messages:
    15,371
    Likes Received:
    1
    know any scripting or java?

    m3us are just plain text with the paths of the included music files (either absolute or relative to the location of the m3u). If your directories are consistent, it wouldn't be too hard to put something together.
     
  3. Gooberlx2

    Gooberlx2 Lifer

    Joined:
    May 4, 2001
    Messages:
    15,371
    Likes Received:
    1
    Here's a simple java utility I wrote for your purpose...because I was bored with nothing else to do in a hospital last night:

    http://jumpshare.com/b/P75DGu (expires Nov 18)
    Usage (jre7 x86):
    Code:
    java -jar BatchM3u.jar c:\path\to\music
    Source:
    Code:
    package batchm3u;
    
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.Arrays;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    /**
     *create m3u for music files
     * extensions: mp3, wma, m4a, ogg
     * gathers all tracks within a folder and places them within a m3u file inside that folder, of that folder name
     * @author gooberlx
     */
    public class BatchM3u {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            File topDir = new File(args[0]);
            //recurse contents
            recurse(topDir);
            System.out.println("finished");
        }
        
        private static void recurse(File file){
            if(file.isDirectory()){
                File[] contents = file.listFiles();
                Arrays.sort(contents);
                for(File f : contents){
                    recurse(f);
                }
            }
            else{
                String name = file.getName();
                String extension = name.substring(name.length()-3, name.length());
                if(extension.equalsIgnoreCase("mp3") || extension.equalsIgnoreCase("wma")
                        || extension.equalsIgnoreCase("m4a") || extension.equalsIgnoreCase("ogg")){
                    //place track in m3u file
                    File m3u = new File(file.getParentFile().getAbsolutePath(), file.getParentFile().getName()+".m3u");
                    try {
                        //writers with append
                        FileWriter fw = new FileWriter(m3u, true);
                        BufferedWriter bw = new BufferedWriter(fw);
                        bw.write(file.getName());
                        bw.newLine();
                        bw.flush();
                        bw.close();
                        System.out.println("wrote "+file.getName()+" to "+m3u.getAbsolutePath());
                    } catch (IOException ex) {
                        Logger.getLogger(BatchM3u.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
            
        }
    }
    
     
    #3 Gooberlx2, Nov 4, 2012
    Last edited: Nov 4, 2012
  4. oynaz

    oynaz Platinum Member

    Joined:
    May 14, 2003
    Messages:
    2,439
    Likes Received:
    0
    Now, that's a useful answer!
     
  5. Gooberlx2

    Gooberlx2 Lifer

    Joined:
    May 4, 2001
    Messages:
    15,371
    Likes Received:
    1
    Heh, I figured "what the hell, sounds like a nice little exercise".
     
  6. Venom20

    Venom20 Senior member

    Joined:
    Apr 12, 2011
    Messages:
    259
    Likes Received:
    0
    That is what I'd call a time-saver for sure. I did a bit of java almost 10 years ago, but never could have come up with that. Although I do understand it after looking at it.

    This worked wonderfully, something so simple, it's downright elegant.
     
  7. Gooberlx2

    Gooberlx2 Lifer

    Joined:
    May 4, 2001
    Messages:
    15,371
    Likes Received:
    1
    Glad I could help. :)