|
|
 |
11-03-2012, 02:31 AM
|
#1
|
|
Senior Member
Join Date: Apr 2011
Location: Ontario, Canada
Posts: 255
|
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.
|
|
|
11-03-2012, 04:07 PM
|
#2
|
|
Lifer
Join Date: May 2001
Location: Denver, CO
Posts: 13,964
|
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.
|
|
|
11-04-2012, 12:25 PM
|
#3
|
|
Lifer
Join Date: May 2001
Location: Denver, CO
Posts: 13,964
|
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.
|
|
|
11-05-2012, 03:41 AM
|
#4
|
|
Platinum Member
Join Date: May 2003
Location: Denmark
Posts: 2,133
|
Now, that's a useful answer!
|
|
|
11-05-2012, 11:22 AM
|
#5
|
|
Lifer
Join Date: May 2001
Location: Denver, CO
Posts: 13,964
|
Heh, I figured "what the hell, sounds like a nice little exercise".
|
|
|
11-05-2012, 10:21 PM
|
#6
|
|
Senior Member
Join Date: Apr 2011
Location: Ontario, Canada
Posts: 255
|
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.
|
|
|
11-06-2012, 10:45 AM
|
#7
|
|
Lifer
Join Date: May 2001
Location: Denver, CO
Posts: 13,964
|
Glad I could help.
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:16 PM.
|