コード例 #1
0
  /**
   * Method for generating the new File name of the music file, after the tag was completed
   *
   * @param musicFile the music file
   * @return new Filename
   */
  public static void generateNewFileName(MusicFile musicFile) {
    MusicTag tag = musicFile.getTag();

    if (!tag.getArtist().equals("")
        && tag.getArtist() != null
        && !tag.getTitlename().equals("")
        && tag.getTitlename() != null) {
      // Clearing artist and title
      int track;
      try {
        track = Integer.parseInt(tag.getRelease().getTrackNumber());
      } catch (NumberFormatException e) {
        track = 0;
      }

      String artist = cleanString(tag.getArtist());
      String title = cleanString(tag.getTitlename());
      artist = clearForbiddenCharacters(artist);
      title = clearForbiddenCharacters(title);

      if (track != 0) {
        musicFile.setNewFileName(
            track
                + " - "
                + artist
                + " - "
                + title
                + "."
                + MusicFileType.getFileExtension(musicFile.getFileType()));
      } else {
        musicFile.setNewFileName(
            artist + " - " + title + "." + MusicFileType.getFileExtension(musicFile.getFileType()));
      }

      musicFile.setNewFileNameIsSet(true);
    } else {
      musicFile.setNewFileNameIsSet(false);
    }
  }
コード例 #2
0
  /**
   * Checks for a certain file if there is already a music file in the library
   *
   * @param musicFile to be checked
   * @return boolean indicating whether there is a duplicate already
   */
  public static boolean checkForDuplicates(MusicFile musicFile)
      throws CannotReadException, IOException, TagException, ReadOnlyFileException,
          InvalidAudioFrameException {
    // The Directories
    File firstLevelDir;
    File secondLevelDir;
    File thridLevelDir;

    // The direcotryPaths
    String firstLevelDir_path;
    String secondLevelDir_path;
    String thridLevelDir_path;

    // Clearing the readFiles list
    readFiles.clear();

    // Reading the tag
    MusicTag tag = musicFile.getTag();
    boolean duplicate = false;

    // Reading the path to the music library and ordering Mode
    String pathToLibrary = PropertiesUtils.getProperty(LibraryProperties.FILEPATH);
    OrderingProperty orderingMode = PropertiesUtils.getOrderingProperty();

    // Cleaning the Strings
    String artist =
        MusicFileUtils.clearForbiddenCharacters(MusicFileUtils.cleanString(tag.getArtist()));
    String album =
        MusicFileUtils.clearForbiddenCharacters(MusicFileUtils.cleanString(tag.getAlbum()));
    String titlename =
        MusicFileUtils.clearForbiddenCharacters(MusicFileUtils.cleanString(tag.getTitlename()));
    String genre =
        MusicFileUtils.clearForbiddenCharacters(MusicFileUtils.cleanString(tag.getGenre()));

    if (orderingMode == OrderingProperty.AAA || orderingMode == OrderingProperty.GAA) {
      // Building the Directorystrings
      // Ordering: A - Artist - Album
      if (orderingMode == OrderingProperty.AAA) {
        firstLevelDir_path = pathToLibrary + "\\" + artist.substring(0, 1).toUpperCase();
        secondLevelDir_path =
            firstLevelDir_path
                + "\\"
                + artist.substring(0, 1).toUpperCase()
                + artist.substring(1, artist.length());
        thridLevelDir_path =
            secondLevelDir_path
                + "\\"
                + album.substring(0, 1).toUpperCase()
                + album.substring(1, album.length());
        // Genre - Artist - Album
      } else {
        firstLevelDir_path =
            pathToLibrary
                + "\\"
                + genre.substring(0, 1).toUpperCase()
                + genre.substring(1, genre.length()).toUpperCase();
        secondLevelDir_path =
            firstLevelDir_path
                + "\\"
                + artist.substring(0, 1).toUpperCase()
                + artist.substring(1, artist.length());
        thridLevelDir_path =
            secondLevelDir_path
                + "\\"
                + album.substring(0, 1).toUpperCase()
                + album.substring(1, album.length());
      }

      // First checking whether there is a Directory for the music file
      firstLevelDir = new File(firstLevelDir_path);
      secondLevelDir = new File(secondLevelDir_path);
      thridLevelDir = new File(thridLevelDir_path);

      // The artist subFolder exists
      if (firstLevelDir.exists()) {
        if (secondLevelDir.exists()) {
          if (thridLevelDir.exists()) {
            // Reading the files of the directory:
            addDirContent(thridLevelDir);

            // Checking for the similar file:
            for (File file : readFiles) {
              System.out.println(file.getAbsolutePath());
              if (compareAcousticIds(new MusicFile(file.getAbsolutePath(), true), musicFile)
                  >= 90.0) {
                musicFile.setPossibleDuplicate(true);
                duplicate = true;
                break;
              } else if (file.getAbsolutePath().contains(titlename)) {
                duplicate = true;
                break;
              }
            }
          } else {
            // Reading the files of the directory:
            addDirContent(secondLevelDir);

            // Checking for the similar file:
            for (File file : readFiles) {
              if (compareAcousticIds(new MusicFile(file.getAbsolutePath(), true), musicFile)
                  >= 90.0) {
                musicFile.setPossibleDuplicate(true);
                duplicate = true;
                break;
              } else if (file.getAbsolutePath().contains(titlename)) {
                duplicate = true;
                break;
              }
            }
          }
        } else {
          duplicate = false;
        }
      } else {
        duplicate = false;
      }

      // Artist - Album
    } else {
      firstLevelDir_path =
          pathToLibrary
              + "\\"
              + artist.substring(0, 1).toUpperCase()
              + artist.substring(1, artist.length());
      secondLevelDir_path =
          firstLevelDir_path
              + "\\"
              + album.substring(0, 1).toUpperCase()
              + album.substring(1, album.length());

      // First checking whether there is a Directory for the music file
      firstLevelDir = new File(firstLevelDir_path);
      secondLevelDir = new File(secondLevelDir_path);

      // The artist subFolder exists
      if (firstLevelDir.exists()) {
        if (secondLevelDir.exists()) {
          // Reading the files of the directory:
          addDirContent(secondLevelDir);

          // Checking for the similar file:
          for (File file : readFiles) {

            // Compare the AcoustID's
            if (compareAcousticIds(new MusicFile(file.getAbsolutePath()), musicFile) >= 90.0) {
              musicFile.setPossibleDuplicate(true);
              duplicate = true;
              break;
            } else if (file.getAbsolutePath().contains(titlename)) {
              duplicate = true;
              break;
            }
          }
        } else {

          // Reading the files of the directory:
          addDirContent(firstLevelDir);

          // Checking for the similar file:
          for (File file : readFiles) {
            if (compareAcousticIds(new MusicFile(file.getAbsolutePath(), true), musicFile)
                >= 90.0) {
              musicFile.setPossibleDuplicate(true);
              duplicate = true;
              break;
            } else if (file.getAbsolutePath().contains(titlename)) {
              duplicate = true;
              break;
            }
          }
        }
      } else {
        duplicate = false;
      }
    }

    return duplicate;
  }