A Java parser for the iTunes Library XML file.
dom4j to parse the XML file. https://dom4j.github.io/
File file = new File("/home/phillip/iTunes Library.xml");
Parser parser = new Parser(file);
try {
parser.parse()
} catch ( DocumentException e ) {
e.printStackTrace();
}
The global properties of the iTunes Library (application version, path to music folder etc.) are stored in a Library object. If a property of the Library is not set in the XML file, the getter returns null.
Library library = parser.getLibrary();
System.out.println(library.getApplicationVersion());
System.out.println(library.getMusicFolder());
...
The properties of a Track (name, artist etc.) are stored in a Track object. If a property of a Track is not set in the XML file, the getter returns null. The Tracks of the Library are collected in a Track Map. The Map key is the Track ID of the Track.
Map<Integer, Track> tracks = parser.getTracks();
Track track1 = tracks.get(100);
System.out.println(track1.getName());
System.out.println(track1.isDisabled());
...
Map<Integer, Track> tracks = parser.getTracks();
for ( Track track : tracks.values() ) {
System.out.println(track.getName());
}
The properties of a Playlist (name, is folder etc.) are stored in a Playlist object. If a property of a Playlist is not set in the XML file, the getter returns null. The Playlists of the Library are collected in a Playlist Map. The Map key is the Playlist ID of the Playlist. The Tracks of a Playlist are collected as a Track Map in the attribute "playlistItems".
Map<Integer, Playlist> playlists = parser.getPlaylists();
Playlist playlist1 = playlists.get(100);
System.out.println(playlist1.getName());
System.out.println(playlist1.isFolder());
...
Map<Integer, Playlist> playlists = parser.getPlaylists();
for ( Playlist playlist;playlists.values() ) {
System.out.println(playlist.getName());
}
Map<Integer, Playlist> playlists = parser.getPlaylists();
Playlist playlist1 = playlists.get(100);
Map<Integer, Track> tracksOfPlaylist1 = playlist1.getPlaylistItems();
for ( Track track : tracksOfPlaylist1.values() ) {
System.out.println(track.getName());
}
iTunes-Parser is a Maven project.
Build an executable jar from the source:
mvn clean compile package
Create a new release and deploy it to Maven central:
mvn clean release:clean release:prepare release:perform || mvn release:rollback
- Save the order of the songs in a playlist.