GithubHelp home page GithubHelp logo

itunes-parser's Introduction

iTunes Parser

A Java parser for the iTunes Library XML file.

Depencies

dom4j to parse the XML file. https://dom4j.github.io/

How to use

Create a parser object

File file = new File("/home/phillip/iTunes Library.xml");
Parser parser = new Parser(file);

Parse the XML file

try {
    parser.parse()
} catch ( DocumentException e ) {
    e.printStackTrace();
}

Library

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.

Get the Library object and print some properties

Library library = parser.getLibrary();
System.out.println(library.getApplicationVersion());
System.out.println(library.getMusicFolder());
...

Tracks

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.

Get the Map with Tracks and print some properties of one

Map<Integer, Track> tracks = parser.getTracks();
Track track1 = tracks.get(100);
System.out.println(track1.getName());
System.out.println(track1.isDisabled());
...

Iterate through the Tracks

Map<Integer, Track> tracks = parser.getTracks();
for ( Track track : tracks.values() ) {
    System.out.println(track.getName());
}

Playlists

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".

Get the Map with Playlists and print some properties of one

Map<Integer, Playlist> playlists = parser.getPlaylists();
Playlist playlist1 = playlists.get(100);
System.out.println(playlist1.getName());
System.out.println(playlist1.isFolder());
...

Iterate through the Playlists

Map<Integer, Playlist> playlists = parser.getPlaylists();
for ( Playlist playlist;playlists.values() ) {
    System.out.println(playlist.getName());
}

Get the Tracks of a Playlist

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());
}

TODO

  • Save the order of the songs in a playlist.

itunes-parser's People

Contributors

pireba avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.