Go Back   AnandTech Forums > Software > Software for Windows

Forums
· Hardware and Technology
· CPUs and Overclocking
· Motherboards
· Video Cards and Graphics
· Memory and Storage
· Power Supplies
· Cases & Cooling
· SFF, Notebooks, Pre-Built/Barebones PCs
· Networking
· Peripherals
· General Hardware
· Highly Technical
· Computer Help
· Home Theater PCs
· Consumer Electronics
· Digital and Video Cameras
· Mobile Devices & Gadgets
· Audio/Video & Home Theater
· Software
· Software for Windows
· All Things Apple
· *nix Software
· Operating Systems
· Programming
· PC Gaming
· Console Gaming
· Distributed Computing
· Security
· Social
· Off Topic
· Politics and News
· Discussion Club
· Love and Relationships
· The Garage
· Health and Fitness
· Merchandise and Shopping
· For Sale/Trade
· Hot Deals with Free Stuff/Contests
· Black Friday 2013
· Forum Issues
· Technical Forum Issues
· Personal Forum Issues
· Suggestion Box
· Moderator Resources
· Moderator Discussions
   

Reply
 
Thread Tools
Old 11-03-2012, 02:31 AM   #1
Venom20
Senior Member
 
Venom20's Avatar
 
Join Date: Apr 2011
Location: Ontario, Canada
Posts: 259
Default Mass .m3u creator

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.
Venom20 is offline   Reply With Quote
Old 11-03-2012, 04:07 PM   #2
Gooberlx2
Lifer
 
Gooberlx2's Avatar
 
Join Date: May 2001
Location: Denver, CO
Posts: 14,662
Default

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 is offline   Reply With Quote
Old 11-04-2012, 12:25 PM   #3
Gooberlx2
Lifer
 
Gooberlx2's Avatar
 
Join Date: May 2001
Location: Denver, CO
Posts: 14,662
Default

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 by Gooberlx2; 11-04-2012 at 01:31 PM.
Gooberlx2 is offline   Reply With Quote
Old 11-05-2012, 03:41 AM   #4
oynaz
Platinum Member
 
Join Date: May 2003
Location: Denmark
Posts: 2,357
Default

Now, that's a useful answer!
oynaz is offline   Reply With Quote
Old 11-05-2012, 11:22 AM   #5
Gooberlx2
Lifer
 
Gooberlx2's Avatar
 
Join Date: May 2001
Location: Denver, CO
Posts: 14,662
Default

Heh, I figured "what the hell, sounds like a nice little exercise".
Gooberlx2 is offline   Reply With Quote
Old 11-05-2012, 10:21 PM   #6
Venom20
Senior Member
 
Venom20's Avatar
 
Join Date: Apr 2011
Location: Ontario, Canada
Posts: 259
Default

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.
Venom20 is offline   Reply With Quote
Old 11-06-2012, 10:45 AM   #7
Gooberlx2
Lifer
 
Gooberlx2's Avatar
 
Join Date: May 2001
Location: Denver, CO
Posts: 14,662
Default

Glad I could help.
Gooberlx2 is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:24 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.