@Test public void testMP4ParsingAudio() throws Exception { Metadata metadata = new Metadata(); String content = getText("testMP4.m4a", metadata); assertEquals("audio/mp4", metadata.get(Metadata.CONTENT_TYPE)); assertEquals("Test Title", metadata.get(TikaCoreProperties.TITLE)); assertEquals("Test Artist", metadata.get(TikaCoreProperties.CREATOR)); assertEquals("2012-01-28T18:39:18Z", metadata.get(TikaCoreProperties.CREATED)); assertEquals("2012-01-28T18:40:25Z", metadata.get(TikaCoreProperties.MODIFIED)); assertContains("Test Title", content); assertContains("Test Artist", content); assertContains("Test Album", content); assertContains("2008", content); assertContains("Test Comment", content); assertContains("Test Genre", content); assertEquals("Test Album", metadata.get(XMPDM.ALBUM)); assertEquals("Test Artist", metadata.get(XMPDM.ARTIST)); assertEquals("Test Composer", metadata.get(XMPDM.COMPOSER)); assertEquals("2008", metadata.get(XMPDM.RELEASE_DATE)); assertEquals("Test Genre", metadata.get(XMPDM.GENRE)); assertEquals("Test Comments", metadata.get(XMPDM.LOG_COMMENT.getName())); assertEquals("1", metadata.get(XMPDM.TRACK_NUMBER)); assertEquals("Test Album Artist", metadata.get(XMPDM.ALBUM_ARTIST)); assertEquals("6", metadata.get(XMPDM.DISC_NUMBER)); assertEquals("0", metadata.get(XMPDM.COMPILATION)); assertEquals("44100", metadata.get(XMPDM.AUDIO_SAMPLE_RATE)); assertEquals("Stereo", metadata.get(XMPDM.AUDIO_CHANNEL_TYPE)); assertEquals("M4A", metadata.get(XMPDM.AUDIO_COMPRESSOR)); assertEquals("0.07", metadata.get(XMPDM.DURATION)); assertEquals("iTunes 10.5.3.3", metadata.get(XMP.CREATOR_TOOL)); TikaInputStream tstream = TikaInputStream.get( MP4ParserTest.class.getResourceAsStream("/test-documents/testMP4.m4a")); tstream.getFile(); ContentHandler handler = new BodyContentHandler(); try { AUTO_DETECT_PARSER.parse(tstream, handler, metadata, new ParseContext()); } finally { tstream.close(); } }
public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { TemporaryResources tmp = new TemporaryResources(); TikaInputStream tstream = TikaInputStream.get(stream, tmp); try (IsoFile isoFile = new IsoFile(tstream.getFile())) { tmp.addResource(isoFile); FileTypeBox fileType = getOrNull(isoFile, FileTypeBox.class); if (fileType != null) { MediaType type = MediaType.application("mp4"); for (Map.Entry<MediaType, List<String>> e : typesMap.entrySet()) { if (e.getValue().contains(fileType.getMajorBrand())) { type = e.getKey(); break; } } metadata.set(Metadata.CONTENT_TYPE, type.toString()); if (type.getType().equals("audio")) { metadata.set(XMPDM.AUDIO_COMPRESSOR, fileType.getMajorBrand().trim()); } } else { metadata.set(Metadata.CONTENT_TYPE, "video/quicktime"); } MovieBox moov = getOrNull(isoFile, MovieBox.class); if (moov == null) { return; } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); handleMovieHeaderBox(moov, metadata, xhtml); handleTrackBoxes(moov, metadata, xhtml); UserDataBox userData = getOrNull(moov, UserDataBox.class); if (userData != null) { extractGPS(userData, metadata); MetaBox metaBox = getOrNull(userData, MetaBox.class); handleApple(metaBox, metadata, xhtml); } xhtml.endDocument(); } finally { tmp.dispose(); } }
MP4Parser extends AbstractParser { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { TemporaryResources tmp = new TemporaryResources(); TikaInputStream tstream = TikaInputStream.get(stream, tmp); try (IsoFile isoFile = new IsoFile(tstream.getFile())) { tmp.addResource(isoFile); FileTypeBox fileType = getOrNull(isoFile, FileTypeBox.class); if (fileType != null) { MediaType type = MediaType.application("mp4"); for (Map.Entry<MediaType, List<String>> e : typesMap.entrySet()) { if (e.getValue().contains(fileType.getMajorBrand())) { type = e.getKey(); break; } } metadata.set(Metadata.CONTENT_TYPE, type.toString()); if (type.getType().equals("audio")) { metadata.set(XMPDM.AUDIO_COMPRESSOR, fileType.getMajorBrand().trim()); } } else { metadata.set(Metadata.CONTENT_TYPE, "video/quicktime"); } MovieBox moov = getOrNull(isoFile, MovieBox.class); if (moov == null) { return; } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); handleMovieHeaderBox(moov, metadata, xhtml); handleTrackBoxes(moov, metadata, xhtml); UserDataBox userData = getOrNull(moov, UserDataBox.class); if (userData != null) { extractGPS(userData, metadata); MetaBox metaBox = getOrNull(userData, MetaBox.class); handleApple(metaBox, metadata, xhtml); } xhtml.endDocument(); } finally { tmp.dispose(); } } }
MP4Parser extends AbstractParser { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { TemporaryResources tmp = new TemporaryResources(); TikaInputStream tstream = TikaInputStream.get(stream, tmp); try (IsoFile isoFile = new IsoFile(tstream.getFile())) { tmp.addResource(isoFile); FileTypeBox fileType = getOrNull(isoFile, FileTypeBox.class); if (fileType != null) { MediaType type = MediaType.application("mp4"); for (Map.Entry<MediaType, List<String>> e : typesMap.entrySet()) { if (e.getValue().contains(fileType.getMajorBrand())) { type = e.getKey(); break; } } metadata.set(Metadata.CONTENT_TYPE, type.toString()); if (type.getType().equals("audio")) { metadata.set(XMPDM.AUDIO_COMPRESSOR, fileType.getMajorBrand().trim()); } } else { metadata.set(Metadata.CONTENT_TYPE, "video/quicktime"); } MovieBox moov = getOrNull(isoFile, MovieBox.class); if (moov == null) { return; } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); handleMovieHeaderBox(moov, metadata, xhtml); handleTrackBoxes(moov, metadata, xhtml); UserDataBox userData = getOrNull(moov, UserDataBox.class); if (userData != null) { extractGPS(userData, metadata); MetaBox metaBox = getOrNull(userData, MetaBox.class); handleApple(metaBox, metadata, xhtml); } xhtml.endDocument(); } finally { tmp.dispose(); } }  }
MP4Parser extends AbstractParser { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { TemporaryResources tmp = new TemporaryResources(); TikaInputStream tstream = TikaInputStream.get(stream, tmp); try (IsoFile isoFile = new IsoFile(tstream.getFile())) { tmp.addResource(isoFile); FileTypeBox fileType = getOrNull(isoFile, FileTypeBox.class); if (fileType != null) { MediaType type = MediaType.application("mp4"); for (Map.Entry<MediaType, List<String>> e : typesMap.entrySet()) { if (e.getValue().contains(fileType.getMajorBrand())) { type = e.getKey(); break; } } metadata.set(Metadata.CONTENT_TYPE, type.toString()); if (type.getType().equals("audio")) { metadata.set(XMPDM.AUDIO_COMPRESSOR, fileType.getMajorBrand().trim()); } } else { metadata.set(Metadata.CONTENT_TYPE, "video/quicktime"); } MovieBox moov = getOrNull(isoFile, MovieBox.class); if (moov == null) { return; } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); handleMovieHeaderBox(moov, metadata, xhtml); handleTrackBoxes(moov, metadata, xhtml); UserDataBox userData = getOrNull(moov, UserDataBox.class); if (userData != null) { extractGPS(userData, metadata); MetaBox metaBox = getOrNull(userData, MetaBox.class); handleApple(metaBox, metadata, xhtml); } xhtml.endDocument(); } finally { tmp.dispose(); } }  Set<MediaType> getSupportedTypes(ParseContext context); void parse(
            InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context); @Field void setMaxRecordSize(long maxRecordSize); }
MP4Parser extends AbstractParser { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { TemporaryResources tmp = new TemporaryResources(); TikaInputStream tstream = TikaInputStream.get(stream, tmp); try (IsoFile isoFile = new IsoFile(tstream.getFile())) { tmp.addResource(isoFile); FileTypeBox fileType = getOrNull(isoFile, FileTypeBox.class); if (fileType != null) { MediaType type = MediaType.application("mp4"); for (Map.Entry<MediaType, List<String>> e : typesMap.entrySet()) { if (e.getValue().contains(fileType.getMajorBrand())) { type = e.getKey(); break; } } metadata.set(Metadata.CONTENT_TYPE, type.toString()); if (type.getType().equals("audio")) { metadata.set(XMPDM.AUDIO_COMPRESSOR, fileType.getMajorBrand().trim()); } } else { metadata.set(Metadata.CONTENT_TYPE, "video/quicktime"); } MovieBox moov = getOrNull(isoFile, MovieBox.class); if (moov == null) { return; } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); handleMovieHeaderBox(moov, metadata, xhtml); handleTrackBoxes(moov, metadata, xhtml); UserDataBox userData = getOrNull(moov, UserDataBox.class); if (userData != null) { extractGPS(userData, metadata); MetaBox metaBox = getOrNull(userData, MetaBox.class); handleApple(metaBox, metadata, xhtml); } xhtml.endDocument(); } finally { tmp.dispose(); } }  Set<MediaType> getSupportedTypes(ParseContext context); void parse(
            InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context); @Field void setMaxRecordSize(long maxRecordSize);  }