MediaInfoScanner { protected Codec getCodecInfo(CodecType codecType, Map<String, String> codecInfos) { Codec codec = new Codec(codecType); codec.setCodecSource(CodecSource.MEDIAINFO); codec.setCodec(codecInfos.get(Codec.MI_CODEC)); codec.setCodecFormat(codecInfos.get(Codec.MI_CODEC_FORMAT)); codec.setCodecFormatProfile(codecInfos.get(Codec.MI_CODEC_FORMAT_PROFILE)); codec.setCodecFormatVersion(codecInfos.get(Codec.MI_CODEC_FORMAT_VERSION)); codec.setCodecId(codecInfos.get(Codec.MI_CODEC_ID)); codec.setCodecIdHint(codecInfos.get(Codec.MI_CODEC_ID_HINT)); codec.setCodecLanguage(codecInfos.get(Codec.MI_CODEC_LANGUAGE)); String[] keyBitrates = {Codec.MI_CODEC_BITRATE, Codec.MI_CODEC_NOMINAL_BITRATE}; for (String key : Arrays.asList(keyBitrates)) { String infoValue = codecInfos.get(key); if (StringUtils.isNotBlank(infoValue)) { if (infoValue.contains(Movie.SPACE_SLASH_SPACE)) { infoValue = infoValue.substring(0, infoValue.indexOf(Movie.SPACE_SLASH_SPACE)); } if (StringTools.isValidString(infoValue.trim())) { infoValue = infoValue.substring(0, infoValue.length() - 3); codec.setCodecBitRate(infoValue); break; } } if (codecType.equals(CodecType.AUDIO) && key.equals(Codec.MI_CODEC_BITRATE)) { break; } } String codecChannels = ""; for (String cc : Codec.MI_CODEC_CHANNELS) { codecChannels = codecInfos.get(cc); if (StringUtils.isNotBlank(codecChannels)) { break; } } if (StringUtils.isNotBlank(codecChannels)) { if (codecChannels.contains("/")) { codecChannels = codecChannels.substring(0, codecChannels.indexOf('/')); } Matcher codecMatch = PATTERN_CHANNELS.matcher(codecChannels); if (codecMatch.matches()) { codec.setCodecChannels(Integer.parseInt(codecMatch.group(1))); } } return codec; } MediaInfoScanner(); boolean extendedExtension(String filename); void update(Movie currentMovie); void scan(Movie currentMovie); void updateMovieInfo(Movie movie, Map<String, String> infosGeneral, List<Map<String, String>> infosVideo,
            List<Map<String, String>> infosAudio, List<Map<String, String>> infosText,
            Map<String, String> infosMultiPart); String archiveScan(String movieFilePath); static final String OS_NAME; static final String OS_VERSION; static final String OS_ARCH; }
@Test public void testAvi() { LOG.info("Avi"); getMediaInfoTestFile("AVI_DTS_ES_6.1.AVI.txt", true); Codec codec; int counter = 1; for (Map<String, String> codecInfo : infosVideo) { codec = MI_TEST.getCodecInfo(CodecType.VIDEO, codecInfo); LOG.info(counter++ + " = " + codec.toString()); } counter = 1; for (Map<String, String> codecInfo : infosAudio) { codec = MI_TEST.getCodecInfo(CodecType.AUDIO, codecInfo); LOG.info(counter++ + " = " + codec.toString()); } getMediaInfoTestFile("AVI_DTS_MA_7.1.AVI.txt", true); counter = 1; for (Map<String, String> codecInfo : infosVideo) { codec = MI_TEST.getCodecInfo(CodecType.VIDEO, codecInfo); LOG.info(counter++ + " = " + codec.toString()); } counter = 1; for (Map<String, String> codecInfo : infosAudio) { codec = MI_TEST.getCodecInfo(CodecType.AUDIO, codecInfo); LOG.info(counter++ + " = " + codec.toString()); } }
@Test public void testChannels() { LOG.info("Channels"); getMediaInfoTestFile("mediainfo-channels.txt", true); Codec codec; int counter = 1; for (Map<String, String> codecInfo : infosAudio) { codec = MI_TEST.getCodecInfo(CodecType.AUDIO, codecInfo); LOG.debug("{} = {}", counter++, codec.toString()); assertTrue("No channels found!", codec.getCodecChannels() > 0); } }
@Test public void testMultipleAudioCodes() { LOG.info("MultipleAudioCodes"); getMediaInfoTestFile("DTS_AC3_DTS_AC3.txt", true); Movie movie = new Movie(); Codec codec; int counter = 1; for (Map<String, String> codecInfo : infosAudio) { codec = MI_TEST.getCodecInfo(CodecType.AUDIO, codecInfo); movie.addCodec(codec); LOG.debug("{} = {}", counter++, codec.toString()); assertTrue("No channels found!", codec.getCodecChannels() > 0); } for (Codec audio : movie.getCodecs()) { LOG.debug("AudioCodec: {}", audio.toString()); } }