public ArrayList<DLNAMediaInfo> getData(String name, long modified) { ArrayList<DLNAMediaInfo> list = new ArrayList<>(); Connection conn = null; ResultSet rs = null; PreparedStatement stmt = null; try { conn = getConnection(); stmt = conn.prepareStatement("SELECT * FROM FILES WHERE FILENAME = ? AND MODIFIED = ?"); stmt.setString(1, name); stmt.setTimestamp(2, new Timestamp(modified)); rs = stmt.executeQuery(); while (rs.next()) { DLNAMediaInfo media = new DLNAMediaInfo(); int id = rs.getInt("ID"); media.setDuration(toDouble(rs, "DURATION")); media.setBitrate(rs.getInt("BITRATE")); media.setWidth(rs.getInt("WIDTH")); media.setHeight(rs.getInt("HEIGHT")); media.setSize(rs.getLong("SIZE")); media.setCodecV(rs.getString("CODECV")); media.setFrameRate(rs.getString("FRAMERATE")); media.setAspectRatioDvdIso(rs.getString("ASPECT")); media.setAspectRatioContainer(rs.getString("ASPECTRATIOCONTAINER")); media.setAspectRatioVideoTrack(rs.getString("ASPECTRATIOVIDEOTRACK")); media.setReferenceFrameCount(rs.getByte("REFRAMES")); media.setAvcLevel(rs.getString("AVCLEVEL")); media.setBitsPerPixel(rs.getInt("BITSPERPIXEL")); media.setThumb(rs.getBytes("THUMB")); media.setContainer(rs.getString("CONTAINER")); media.setModel(rs.getString("MODEL")); if (media.getModel() != null && !FormatConfiguration.JPG.equals(media.getContainer())) { media.setExtrasAsString(media.getModel()); } media.setExposure(rs.getInt("EXPOSURE")); media.setOrientation(rs.getInt("ORIENTATION")); media.setIso(rs.getInt("ISO")); media.setMuxingMode(rs.getString("MUXINGMODE")); media.setFrameRateMode(rs.getString("FRAMERATEMODE")); media.setStereoscopy(rs.getString("STEREOSCOPY")); media.setMatrixCoefficients(rs.getString("MATRIXCOEFFICIENTS")); media.setFileTitleFromMetadata(rs.getString("TITLECONTAINER")); media.setVideoTrackTitleFromMetadata(rs.getString("TITLEVIDEOTRACK")); media.setVideoTrackCount(rs.getInt("VIDEOTRACKCOUNT")); media.setImageCount(rs.getInt("IMAGECOUNT")); media.setVideoBitDepth(rs.getInt("BITDEPTH")); media.setMediaparsed(true); ResultSet subrs; try (PreparedStatement audios = conn.prepareStatement("SELECT * FROM AUDIOTRACKS WHERE FILEID = ?")) { audios.setInt(1, id); subrs = audios.executeQuery(); while (subrs.next()) { DLNAMediaAudio audio = new DLNAMediaAudio(); audio.setId(subrs.getInt("ID")); audio.setLang(subrs.getString("LANG")); audio.setAudioTrackTitleFromMetadata(subrs.getString("TITLE")); audio.getAudioProperties().setNumberOfChannels(subrs.getInt("NRAUDIOCHANNELS")); audio.setSampleFrequency(subrs.getString("SAMPLEFREQ")); audio.setCodecA(subrs.getString("CODECA")); audio.setBitsperSample(subrs.getInt("BITSPERSAMPLE")); audio.setAlbum(subrs.getString("ALBUM")); audio.setArtist(subrs.getString("ARTIST")); audio.setSongname(subrs.getString("SONGNAME")); audio.setGenre(subrs.getString("GENRE")); audio.setYear(subrs.getInt("YEAR")); audio.setTrack(subrs.getInt("TRACK")); audio.getAudioProperties().setAudioDelay(subrs.getInt("DELAY")); audio.setMuxingModeAudio(subrs.getString("MUXINGMODE")); audio.setBitRate(subrs.getInt("BITRATE")); media.getAudioTracksList().add(audio); } subrs.close(); } try (PreparedStatement subs = conn.prepareStatement("SELECT * FROM SUBTRACKS WHERE FILEID = ?")) { subs.setInt(1, id); subrs = subs.executeQuery(); while (subrs.next()) { DLNAMediaSubtitle sub = new DLNAMediaSubtitle(); sub.setId(subrs.getInt("ID")); sub.setLang(subrs.getString("LANG")); sub.setSubtitlesTrackTitleFromMetadata(subrs.getString("TITLE")); sub.setType(SubtitleType.valueOfStableIndex(subrs.getInt("TYPE"))); media.getSubtitleTracksList().add(sub); } subrs.close(); } list.add(media); } } catch (SQLException se) { LOGGER.error(null, se); return null; } finally { close(rs); close(stmt); close(conn); } return list; }
private static synchronized boolean browseFolderForSubtitles( File subFolder, File file, DLNAMediaInfo media, boolean usecache) { boolean found = false; if (!usecache) { cache = null; } if (cache == null) { cache = new HashMap<>(); } final Set<String> supported = SubtitleType.getSupportedFileExtensions(); File[] allSubs = cache.get(subFolder); if (allSubs == null) { allSubs = subFolder.listFiles( new FilenameFilter() { @Override public boolean accept(File dir, String name) { String ext = FilenameUtils.getExtension(name).toLowerCase(); if ("sub".equals(ext)) { // Avoid microdvd/vobsub confusion by ignoring sub+idx pairs here since // they'll come in unambiguously as vobsub via the idx file anyway return isFileExists(new File(dir, name), "idx") == null; } return supported.contains(ext); } }); if (allSubs != null) { cache.put(subFolder, allSubs); } } String fileName = getFileNameWithoutExtension(file.getName()).toLowerCase(); if (allSubs != null) { for (File f : allSubs) { if (f.isFile() && !f.isHidden()) { String fName = f.getName().toLowerCase(); for (String ext : supported) { if (fName.length() > ext.length() && fName.startsWith(fileName) && endsWithIgnoreCase(fName, "." + ext)) { int a = fileName.length(); int b = fName.length() - ext.length() - 1; String code = ""; if (a <= b) { // handling case with several dots: <video>..<extension> code = fName.substring(a, b); } if (code.startsWith(".")) { code = code.substring(1); } boolean exists = false; if (media != null) { for (DLNAMediaSubtitle sub : media.getSubtitleTracksList()) { if (f.equals(sub.getExternalFile())) { exists = true; } else if (equalsIgnoreCase(ext, "idx") && sub.getType() == SubtitleType.MICRODVD) { // sub+idx => VOBSUB sub.setType(SubtitleType.VOBSUB); exists = true; } else if (equalsIgnoreCase(ext, "sub") && sub.getType() == SubtitleType.VOBSUB) { // VOBSUB try { sub.setExternalFile(f); } catch (FileNotFoundException ex) { LOGGER.warn("Exception during external subtitles scan.", ex); } exists = true; } } } if (!exists) { DLNAMediaSubtitle sub = new DLNAMediaSubtitle(); sub.setId( 100 + (media == null ? 0 : media.getSubtitleTracksList().size())); // fake id, not used if (code.length() == 0 || !Iso639.getCodeList().contains(code)) { sub.setLang(DLNAMediaSubtitle.UND); sub.setType(SubtitleType.valueOfFileExtension(ext)); if (code.length() > 0) { sub.setFlavor(code); if (sub.getFlavor().contains("-")) { String flavorLang = sub.getFlavor().substring(0, sub.getFlavor().indexOf('-')); String flavorTitle = sub.getFlavor().substring(sub.getFlavor().indexOf('-') + 1); if (Iso639.getCodeList().contains(flavorLang)) { sub.setLang(flavorLang); sub.setFlavor(flavorTitle); } } } } else { sub.setLang(code); sub.setType(SubtitleType.valueOfFileExtension(ext)); } try { sub.setExternalFile(f); } catch (FileNotFoundException ex) { LOGGER.warn("Exception during external subtitles scan.", ex); } found = true; if (media != null) { media.getSubtitleTracksList().add(sub); } } } } } } } return found; }