package us.jyg.freshet.util;
import java.io.File;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import us.jyg.freshet.dao.model.Song;
import us.jyg.freshet.manager.SongManager;
public class Loader {
protected final static Log log = LogFactory.getLog(Loader.class);
public static void main(String[] args) {
FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext("resources/Spring/applicationContext.xml");
SongManager songManager = (SongManager)ctx.getBean("songManager", SongManager.class);
Miner miner = new Miner("/shared/My Music/a");
File f;
int count = 0;
while( (f=miner.next()) != null) {
try {
if (f.getName().matches(".*[mM][pP]3")) {
SongData songData = new SongData(f);
Song song = songManager.saveSong(songData);
count++;
log.debug("Saved: " + song.getName() + " ("+song.getId() +")"+
", " + song.getAlbum().getName() +
", " + song.getArtist().getName() +
", " + song.getGenre().getName());
}
} catch (SongDataException sdE) {
log.error("Could not process file: " +f.getAbsolutePath());
}
if (count % 100 == 0) log.debug("Count " + count);
}
}
}