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 static String getMimeType(String filePath) {
   try {
     return MimeDetector.getMimeType(FilenameUtils.getExtension(filePath));
   } catch (Throwable e) {
     LOG.log(Level.WARNING, "Failed to read mime type for: " + filePath);
     return MimeDetector.UNKNOWN;
   }
 }
  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);
  }
  public void scan(String filePath) {
    try {
      MediaType mt = MediaType.getMediaTypeForExtension(FilenameUtils.getExtension(filePath));

      if (mt == null) {
        scanDocument(filePath, true);
      } else if (mt.equals(MediaType.getAudioMediaType())) {
        scanAudio(filePath, true);
      } else if (mt.equals(MediaType.getImageMediaType())) {
        scanPictures(filePath, true);
      } else if (mt.equals(MediaType.getVideoMediaType())) {
        scanVideo(
            filePath,
            true); // until we integrate mplayer for video and research metadata extraction
      } else {
        scanDocument(filePath, true);
      }

    } catch (Throwable e) {
      scanDocument(filePath, true);
      LOG.log(Level.WARNING, "Error scanning file, scanned as document: " + filePath, e);
    }
  }
 private void scanVideo(String filePath, boolean shared) {
   String mime = "video/" + FilenameUtils.getExtension(filePath);
   scanBasic(Constants.FILE_TYPE_VIDEOS, filePath, mime, shared);
 }