Mass .m3u creator

Venom20

Senior member
Apr 12, 2011
259
0
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.
 

Gooberlx2

Lifer
May 4, 2001
15,381
6
91
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.
 

Gooberlx2

Lifer
May 4, 2001
15,381
6
91
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);
                }
            }
        }
        
    }
}
 
Last edited:

Venom20

Senior member
Apr 12, 2011
259
0
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.