/**
   * Method to generate the new file path
   *
   * @throws IOException Gets thrown if the directory can't be made
   */
  public static void generateNewFilePath(MusicFile file) throws IOException {
    MusicTag tag = file.getTag();
    OrderingProperty orderingProperty = PropertiesUtils.getOrderingProperty();

    if (!tag.getArtist().equals("") && !tag.getAlbum().equals("")) {
      if (orderingProperty == OrderingProperty.GAA && !tag.getGenre().equals("")
          || orderingProperty == OrderingProperty.AA
          || orderingProperty == OrderingProperty.AAA) {
        file.setNewFilePathIsSet(true);
        file.setNewFilePath(MusicFileUtils.makeFileDir(file));
      } else {
        file.setNewFilePathIsSet(false);
        file.setNewFilePath("");
      }
    } else {
      file.setNewFilePathIsSet(false);
      file.setNewFilePath("");
    }
  }
  /**
   * Method for making the directory for the imported file
   *
   * @param musicFile
   * @return path to the directory
   * @throws IOException
   */
  public static String makeFileDir(MusicFile musicFile) throws IOException {
    File level_1;
    File level_2;
    File level_3;

    String pathToMusicLibrary;

    pathToMusicLibrary = PropertiesUtils.getProperty(LibraryProperties.FILEPATH);
    OrderingProperty orderingMode = PropertiesUtils.getOrderingProperty();

    // Cleaning artist and album
    String artist = cleanString(musicFile.getTag().getArtist());
    String album = cleanString(musicFile.getTag().getAlbum());
    artist = clearForbiddenCharacters(artist);
    album = clearForbiddenCharacters(album);

    // Ordering: A - Artist - Album
    if (orderingMode == OrderingProperty.AAA) {
      if (NUMBERS.contains(artist.substring(0, 1))) {
        level_1 = new File(pathToMusicLibrary + "\\" + "123");
        level_2 = new File(pathToMusicLibrary + "\\" + "123" + "\\" + artist);
        level_3 = new File(pathToMusicLibrary + "\\" + "123" + "\\" + artist + "\\" + album);
      } else {
        level_1 = new File(pathToMusicLibrary + "\\" + artist.substring(0, 1).toUpperCase());
        level_2 =
            new File(
                pathToMusicLibrary
                    + "\\"
                    + artist.toUpperCase().substring(0, 1).toUpperCase()
                    + "\\"
                    + (artist.toUpperCase()).substring(0, 1).toUpperCase()
                    + artist.substring(1, artist.length()));
        level_3 =
            new File(
                pathToMusicLibrary
                    + "\\"
                    + artist.toUpperCase().substring(0, 1).toUpperCase()
                    + "\\"
                    + (artist.toUpperCase()).substring(0, 1).toUpperCase()
                    + artist.substring(1, artist.length())
                    + "\\"
                    + (album.toUpperCase()).substring(0, 1).toUpperCase()
                    + album.substring(1, album.length()));
      }

      if (level_1.exists() == false) {
        level_1.mkdir();
      }

      if (level_2.exists() == false) {
        level_2.mkdir();
      }

      if (level_3.exists() == false) {
        level_3.mkdir();
      }

      return level_3.getAbsolutePath();

      // Genre - Artist - Album
    } else if (orderingMode == OrderingProperty.GAA) {
      String genre = cleanString(musicFile.getTag().getGenre());
      genre = clearForbiddenCharacters(genre);

      level_1 =
          new File(
              pathToMusicLibrary
                  + "\\"
                  + genre.substring(0, 1).toUpperCase()
                  + genre.substring(1, genre.length()));
      level_2 =
          new File(
              pathToMusicLibrary
                  + "\\"
                  + genre.substring(0, 1).toUpperCase()
                  + genre.substring(1, genre.length())
                  + "\\"
                  + artist.substring(0, 1).toUpperCase()
                  + artist.substring(1, artist.length()));
      level_3 =
          new File(
              pathToMusicLibrary
                  + "\\"
                  + genre.substring(0, 1).toUpperCase()
                  + genre.substring(1, genre.length())
                  + "\\"
                  + artist.substring(0, 1).toUpperCase()
                  + artist.substring(1, artist.length())
                  + "\\"
                  + album.substring(0, 1).toUpperCase()
                  + album.substring(1, album.length()));

      if (level_1.exists() == false) {
        level_1.mkdir();
      }

      if (level_2.exists() == false) {
        level_2.mkdir();
      }

      if (level_3.exists() == false) {
        level_3.mkdir();
      }

      return level_3.getAbsolutePath();

      // Artist - Album
    } else if (orderingMode == OrderingProperty.AA) {
      level_1 =
          new File(
              pathToMusicLibrary
                  + "\\"
                  + artist.toUpperCase().charAt(0)
                  + artist.substring(1, artist.length()));
      level_2 =
          new File(
              pathToMusicLibrary
                  + "\\"
                  + artist.toUpperCase().charAt(0)
                  + artist.substring(1, artist.length())
                  + "\\"
                  + album.substring(0, 1).toUpperCase()
                  + album.substring(1, album.length()));

      if (level_1.exists() == false) {
        level_1.mkdir();
      }

      if (level_2.exists() == false) {
        level_2.mkdir();
      }

      return level_2.getAbsolutePath();
    }

    return "";
  }
  /**
   * 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;
  }