I jotted this down in my notes for iTunes DSM but you basically need to download these packages:
- Apache Commons Configuration - Plist XML files
- http://commons.apache.org/configuration/
- Provides Exceptions for Apache
- http://commons.apache.org/lang/
- Apache Logging
- http://commons.apache.org/downloads/download_logging.cgi
- Apache Predicate
- http://commons.apache.org/collections/
- Apache Base64
- http://commons.apache.org/codec/
import java.io.File;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.plist.XMLPropertyListConfiguration;
public class ITunesXML {
private static String SPACE_CHAR = "%20";
private static String LOCATION_PREFIX = "file://localhost";
private XMLPropertyListConfiguration config;
public ITunesXML(String location){
try{
config = new XMLPropertyListConfiguration(location);
}
catch(ConfigurationException e){
System.out.println("Exception ITunesXML Constructor");
}
}
public String getITunesDirectory(){
String loc = config.getString("Music Folder");
assert loc != null;
assert !loc.equals("");
loc = loc.replaceAll(SPACE_CHAR, " ");
loc = loc.replaceAll(LOCATION_PREFIX, "");
try{
File file = new File(loc);
assert file.exists();
}
catch(Exception e){
System.out.println("Error in getITunesDirectory");
}
return loc;
}
public static void main(String[] args){
ITunesXML xml = new ITunesXML("C:\\location\\to\\iTunes Music Library.xml");
System.out.println(xml.getITunesDirectory());
}
}
So here's a simple example on how to read the Mac OSX property list xml files in Java using Apache Commons packages! Now on to code the rest of the bug fixes.
Brian
Instead of running code, there are also other easier ways to remove duplicates in iTunes. You can take a look at this post.
ReplyDelete