private void scanAudio(String filePath, boolean shared) { File file = new File(filePath); ContentValues values = new ContentValues(); String mime = "audio/" + FilenameUtils.getExtension(filePath); fillCommonValues(values, Constants.FILE_TYPE_AUDIO, filePath, file, mime, shared); try { AudioMetaData mt = new AudioMetaData(file); values.put(Columns.TITLE, mt.getTitle()); values.put(Columns.ARTIST, mt.getArtist()); values.put(Columns.ALBUM, mt.getAlbum()); values.put(Columns.YEAR, mt.getYear()); } catch (Throwable e) { String displayName = FilenameUtils.getBaseName(file.getName()); values.put(Columns.TITLE, displayName); values.put(Columns.ARTIST, ""); values.put(Columns.ALBUM, ""); values.put(Columns.YEAR, ""); } ShareFilesDB db = ShareFilesDB.intance(); db.insert(values); }
private void scanPictures(String filePath, boolean shared) { File file = new File(filePath); ContentValues values = new ContentValues(); String mime = "image/" + FilenameUtils.getExtension(filePath); fillCommonValues(values, Constants.FILE_TYPE_PICTURES, filePath, file, mime, shared); try { Metadata metadata = ImageMetadataReader.readMetadata(file); ExifIFD0Directory dir = metadata.getDirectory(ExifIFD0Directory.class); ExifIFD0Descriptor desc = new ExifIFD0Descriptor(dir); String title = desc.getWindowsTitleDescription(); if (StringUtils.isNullOrEmpty(title, true)) { title = FilenameUtils.getBaseName(file.getName()); } String artist = desc.getWindowsAuthorDescription(); if (StringUtils.isNullOrEmpty(artist, true)) { artist = dir.getString(ExifIFD0Directory.TAG_ARTIST, "UTF-8"); } if (StringUtils.isNullOrEmpty(artist, true)) { artist = ""; } String album = ""; String year = dir.getString(ExifIFD0Directory.TAG_DATETIME); if (StringUtils.isNullOrEmpty(year, true)) { year = ""; } values.put(Columns.TITLE, title); values.put(Columns.ARTIST, artist); values.put(Columns.ALBUM, album); values.put(Columns.YEAR, year); } catch (Throwable e) { String displayName = FilenameUtils.getBaseName(file.getName()); values.put(Columns.TITLE, displayName); values.put(Columns.ARTIST, ""); values.put(Columns.ALBUM, ""); values.put(Columns.YEAR, ""); } ShareFilesDB db = ShareFilesDB.intance(); db.insert(values); }
private void scanBasic(byte fileType, String filePath, String mime, boolean shared) { File file = new File(filePath); String displayName = FilenameUtils.getBaseName(file.getName()); ContentValues values = new ContentValues(); fillCommonValues(values, fileType, filePath, file, mime, shared); values.put(Columns.TITLE, displayName); values.put(Columns.ARTIST, ""); values.put(Columns.ALBUM, ""); values.put(Columns.YEAR, ""); ShareFilesDB db = ShareFilesDB.intance(); db.insert(values); }
private void fillCommonValues( ContentValues values, byte fileType, String filePath, File file, String mime, boolean shared) { values.put(Columns.FILE_TYPE, fileType); values.put(Columns.FILE_PATH, filePath); values.put(Columns.FILE_SIZE, file.length()); values.put(Columns.MIME, mime); values.put(Columns.DATE_ADDED, System.currentTimeMillis() / 1000); values.put(Columns.DATE_MODIFIED, file.lastModified()); values.put(Columns.SHARED, shared); }