// Bail out
return;
}
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
xhtml.startDocument();
// Pull out some information from the header box
MovieHeaderBox mHeader = getOrNull(moov, MovieHeaderBox.class);
if (mHeader != null) {
// Get the creation and modification dates
metadata.set(
Metadata.CREATION_DATE,
MP4TimeToDate(mHeader.getCreationTime())
);
metadata.set(
TikaCoreProperties.MODIFIED,
MP4TimeToDate(mHeader.getModificationTime())
);
// Get the duration
double durationSeconds = ((double)mHeader.getDuration()) / mHeader.getTimescale();
// TODO Use this
// The timescale is normally the sampling rate
metadata.set(XMPDM.AUDIO_SAMPLE_RATE, (int)mHeader.getTimescale());
}
// Get some more information from the track header
// TODO Decide how to handle multiple tracks
List<TrackBox> tb = moov.getBoxes(TrackBox.class);
if (tb.size() > 0) {
TrackBox track = tb.get(0);
TrackHeaderBox header = track.getTrackHeaderBox();
// Get the creation and modification dates
metadata.set(
TikaCoreProperties.CREATED,
MP4TimeToDate(header.getCreationTime())
);
metadata.set(
TikaCoreProperties.MODIFIED,
MP4TimeToDate(header.getModificationTime())
);
// Get the video with and height
metadata.set(Metadata.IMAGE_WIDTH, (int)header.getWidth());
metadata.set(Metadata.IMAGE_LENGTH, (int)header.getHeight());
// Get the sample information
SampleTableBox samples = track.getSampleTableBox();
SampleDescriptionBox sampleDesc = samples.getSampleDescriptionBox();
if (sampleDesc != null) {
// Look for the first Audio Sample, if present
AudioSampleEntry sample = getOrNull(sampleDesc, AudioSampleEntry.class);
if (sample != null) {
XMPDM.ChannelTypePropertyConverter.convertAndSet(metadata, sample.getChannelCount());
//metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, sample.getSampleSize()); // TODO Num -> Type mapping
metadata.set(XMPDM.AUDIO_SAMPLE_RATE, (int)sample.getSampleRate());
//metadata.set(XMPDM.AUDIO_, sample.getSamplesPerPacket());
//metadata.set(XMPDM.AUDIO_, sample.getBytesPerSample());
}
}
}
// Get metadata from the User Data Box
UserDataBox userData = getOrNull(moov, UserDataBox.class);
if (userData != null) {
MetaBox meta = getOrNull(userData, MetaBox.class);
// Check for iTunes Metadata
// See http://atomicparsley.sourceforge.net/mpeg-4files.html and
// http://code.google.com/p/mp4v2/wiki/iTunesMetadata for more on these
AppleItemListBox apple = getOrNull(meta, AppleItemListBox.class);
if (apple != null) {
// Title
AppleTrackTitleBox title = getOrNull(apple, AppleTrackTitleBox.class);
addMetadata(TikaCoreProperties.TITLE, metadata, title);
// Artist
AppleArtistBox artist = getOrNull(apple, AppleArtistBox.class);
addMetadata(TikaCoreProperties.CREATOR, metadata, artist);
addMetadata(XMPDM.ARTIST, metadata, artist);
// Album
AppleAlbumBox album = getOrNull(apple, AppleAlbumBox.class);
addMetadata(XMPDM.ALBUM, metadata, album);
// Composer
AppleTrackAuthorBox composer = getOrNull(apple, AppleTrackAuthorBox.class);
addMetadata(XMPDM.COMPOSER, metadata, composer);
// Genre
AppleStandardGenreBox sGenre = getOrNull(apple, AppleStandardGenreBox.class);
AppleCustomGenreBox cGenre = getOrNull(apple, AppleCustomGenreBox.class);
addMetadata(XMPDM.GENRE, metadata, sGenre);
addMetadata(XMPDM.GENRE, metadata, cGenre);
// Year
AppleRecordingYearBox year = getOrNull(apple, AppleRecordingYearBox.class);
addMetadata(XMPDM.RELEASE_DATE, metadata, year);
// Track number
AppleTrackNumberBox trackNum = getOrNull(apple, AppleTrackNumberBox.class);
if (trackNum != null) {
metadata.set(XMPDM.TRACK_NUMBER, trackNum.getTrackNumber());
//metadata.set(XMPDM.NUMBER_OF_TRACKS, trackNum.getNumberOfTracks()); // TODO
}
// Comment
AppleCommentBox comment = getOrNull(apple, AppleCommentBox.class);
addMetadata(XMPDM.LOG_COMMENT, metadata, comment);
// Encoder
AppleEncoderBox encoder = getOrNull(apple, AppleEncoderBox.class);
// addMetadata(XMPDM.???, metadata, encoder); // TODO
// As text
for (Box box : apple.getBoxes()) {
if (box instanceof AbstractAppleMetaDataBox) {
xhtml.element("p", ((AbstractAppleMetaDataBox)box).getValue());
}
}
}
// TODO Check for other kinds too
}
// All done
xhtml.endDocument();
}