//parses children of 'ilst': iTunes
private void parseITunesMetaData(Box ilst) {
final List<Box> boxes = ilst.getChildren();
long l;
ITunesMetadataBox data;
for(Box box : boxes) {
l = box.getType();
data = (ITunesMetadataBox) box.getChild(BoxTypes.ITUNES_METADATA_BOX);
if(l==BoxTypes.ARTIST_NAME_BOX) put(Field.ARTIST, data.getText());
else if(l==BoxTypes.TRACK_NAME_BOX) put(Field.TITLE, data.getText());
else if(l==BoxTypes.ALBUM_ARTIST_NAME_BOX) put(Field.ALBUM_ARTIST, data.getText());
else if(l==BoxTypes.ALBUM_NAME_BOX) put(Field.ALBUM, data.getText());
else if(l==BoxTypes.TRACK_NUMBER_BOX) {
byte[] b = data.getData();
put(Field.TRACK_NUMBER, new Integer(b[3]));
put(Field.TOTAL_TRACKS, new Integer(b[5]));
}
else if(l==BoxTypes.DISK_NUMBER_BOX) put(Field.DISK_NUMBER, data.getInteger());
else if(l==BoxTypes.COMPOSER_NAME_BOX) put(Field.COMPOSER, data.getText());
else if(l==BoxTypes.COMMENTS_BOX) put(Field.COMMENTS, data.getText());
else if(l==BoxTypes.TEMPO_BOX) put(Field.TEMPO, data.getInteger());
else if(l==BoxTypes.RELEASE_DATE_BOX) put(Field.RELEASE_DATE, data.getDate());
else if(l==BoxTypes.GENRE_BOX||l==BoxTypes.CUSTOM_GENRE_BOX) {
String s = null;
if(data.getDataType()==ITunesMetadataBox.DataType.UTF8) s = data.getText();
else {
final int i = data.getInteger();
if(i>0&&i<STANDARD_GENRES.length) s = STANDARD_GENRES[data.getInteger()];
}
if(s!=null) put(Field.GENRE, s);
}
else if(l==BoxTypes.ENCODER_NAME_BOX) put(Field.ENCODER_NAME, data.getText());
else if(l==BoxTypes.ENCODER_TOOL_BOX) put(Field.ENCODER_TOOL, data.getText());
else if(l==BoxTypes.COPYRIGHT_BOX) put(Field.COPYRIGHT, data.getText());
else if(l==BoxTypes.COMPILATION_PART_BOX) put(Field.COMPILATION, data.getBoolean());
else if(l==BoxTypes.COVER_BOX) {
final Artwork aw = new Artwork(Artwork.Type.forDataType(data.getDataType()), data.getData());
if(contents.containsKey(Field.COVER_ARTWORKS)) get(Field.COVER_ARTWORKS).add(aw);
else {
final List<Artwork> list = new ArrayList<Artwork>();
list.add(aw);
put(Field.COVER_ARTWORKS, list);
}
}
else if(l==BoxTypes.GROUPING_BOX) put(Field.GROUPING, data.getText());
else if(l==BoxTypes.LYRICS_BOX) put(Field.LYRICS, data.getText());
else if(l==BoxTypes.RATING_BOX) put(Field.RATING, data.getInteger());
else if(l==BoxTypes.PODCAST_BOX) put(Field.PODCAST, data.getInteger());
else if(l==BoxTypes.PODCAST_URL_BOX) put(Field.PODCAST_URL, data.getText());
else if(l==BoxTypes.CATEGORY_BOX) put(Field.CATEGORY, data.getText());
else if(l==BoxTypes.KEYWORD_BOX) put(Field.KEYWORDS, data.getText());
else if(l==BoxTypes.DESCRIPTION_BOX) put(Field.DESCRIPTION, data.getText());
else if(l==BoxTypes.LONG_DESCRIPTION_BOX) put(Field.DESCRIPTION, data.getText());
else if(l==BoxTypes.TV_SHOW_BOX) put(Field.TV_SHOW, data.getText());
else if(l==BoxTypes.TV_NETWORK_NAME_BOX) put(Field.TV_NETWORK, data.getText());
else if(l==BoxTypes.TV_EPISODE_BOX) put(Field.TV_EPISODE, data.getText());
else if(l==BoxTypes.TV_EPISODE_NUMBER_BOX) put(Field.TV_EPISODE_NUMBER, data.getInteger());
else if(l==BoxTypes.TV_SEASON_BOX) put(Field.TV_SEASON, data.getInteger());
else if(l==BoxTypes.PURCHASE_DATE_BOX) put(Field.PURCHASE_DATE, data.getText());
else if(l==BoxTypes.GAPLESS_PLAYBACK_BOX) put(Field.GAPLESS_PLAYBACK, data.getText());
else if(l==BoxTypes.HD_VIDEO_BOX) put(Field.HD_VIDEO, data.getBoolean());
else if(l==BoxTypes.ARTIST_SORT_BOX) put(Field.ARTIST_SORT_TEXT, data.getText());
else if(l==BoxTypes.TRACK_SORT_BOX) put(Field.TITLE_SORT_TEXT, data.getText());
else if(l==BoxTypes.ALBUM_SORT_BOX) put(Field.ALBUM_SORT_TEXT, data.getText());
else if(l==BoxTypes.CUSTOM_ITUNES_METADATA_BOX) {
// this is special iTunes tag that stores gapless info
FairPlayDataBox nameBox = (FairPlayDataBox) box.getChild(BoxTypes.ITUNES_METADATA_NAME_BOX);
String name = new String(nameBox.getData()).trim();
if (name.equals("iTunSMPB")) {
put(Field.GAPLESS_PLAYBACK, data.getText());
}
}
}
}