示例#1
0
 public synchronized void update(String title, String url) {
   album.setAlbumTitle(title);
   if (foreground) {
     browserController.updateBookmarks();
     browserController.updateInputBox(url);
   }
 }
  @Override
  public void run() {
    FilenameFilter filter = new FlacFilter();
    boolean atBeginningOfLibrary = true;
    boolean okToUseTags;
    TagReader tr;
    String path = "";
    Album rippedDisc = new Album();

    parentWindow.setStatus("Recursing directories to find music files");
    try {
      sleep(1);
    } catch (InterruptedException ie) {
    }

    this.files = RecurseDirectory.listFilesAsArray(options.getLibraryRoot(), filter, true);
    for (File file : files) {
      if (options.isUseEmbeddedTags()
          && ((file.getName().toLowerCase()).endsWith(".flac")
              || (file.getName().toLowerCase()).endsWith(".mp3"))) okToUseTags = true;
      else okToUseTags = false;

      File parentDirectory = file.getParentFile();

      String[] splitPath = (file.toString()).split("\\\\");
      if (parentDirectory.getPath().equals(path) == false) {
        // new album
        path = parentDirectory.getPath();
        parentWindow.setStatus("Processing " + path);
        try {
          sleep(1);
        } catch (InterruptedException ie) {
        }

        // add current Album first
        if (atBeginningOfLibrary == false) {
          rippedDiscs.add(rippedDisc);
        }
        atBeginningOfLibrary = false;

        rippedDisc = new Album();

        // Get General Artist - Album information
        if (okToUseTags) {
          try {
            tr = new TagReader(file);
            tr.processSong();
            rippedDisc.setAlbumTitle(tr.getAlbum());
            rippedDisc.setDate(tr.getDate());

            if (tr.getAlbumArtist() != null && !tr.getAlbumArtist().isEmpty())
              rippedDisc.setArtist(tr.getAlbumArtist());
            else rippedDisc.setArtist(tr.getArtist());

            if (options.isSubstituteComposer()) {
              if (tr.getComposer() != null
                  && !tr.getComposer().isEmpty()
                  && tr.getGenre().startsWith("Classical")) {
                rippedDisc.setGenre(tr.getComposer());
              } else {
                rippedDisc.setGenre(tr.getGenre());
              }
            } else {
              rippedDisc.setGenre(tr.getGenre());
            }
          } catch (Exception e) {
            rippedDisc.setAlbumTitle(splitPath[splitPath.length - 2]);
            rippedDisc.setArtist(splitPath[splitPath.length - 3]);
            parentWindow.setStatus(e.getMessage());
            System.out.println(e.getStackTrace());
          }

        } else {
          if (options.isParseTagsFromSingleFolder()) {
            try {
              rippedDisc.setAlbumTitle(
                  getAlbumNameFromSingleFolder(splitPath[splitPath.length - 2]));
            } catch (Exception e) {
              System.out.println("Can't parse album name from single folder name.");
              System.out.println(
                  "You will need to manually edit " + splitPath[splitPath.length - 2]);
              System.out.println(e.getMessage());
              System.out.println(e.getStackTrace());
              rippedDisc.setAlbumTitle(splitPath[splitPath.length - 2]);
            }
            try {
              rippedDisc.setArtist(getArtistNameFromSingleFolder(splitPath[splitPath.length - 2]));
            } catch (Exception e) {
              System.out.println("Can't parse artist from single folder name.");
              System.out.println(
                  "You will need to manually edit " + splitPath[splitPath.length - 2]);
              System.out.println(e.getMessage());
              System.out.println(e.getStackTrace());
              rippedDisc.setArtist(splitPath[splitPath.length - 2]);
            }
          } else {
            rippedDisc.setAlbumTitle(splitPath[splitPath.length - 2]);
            rippedDisc.setArtist(splitPath[splitPath.length - 3]);
          }

          // write genre if using genre - artist - album folder structure
          if (options.getFoldersInCueSheetName() == 3) {
            try {
              rippedDisc.setGenre(splitPath[splitPath.length - 4]);
            } catch (Exception e) {
              System.out.println(e.getMessage());
            }
          }
        }

        rippedDisc.setDirectoryOnDisc(parentDirectory);
      }

      if (okToUseTags) {
        try {
          tr = new TagReader(file);
          tr.processSong();
          if (options.isArtistInTrackTitle()
              && (tr.getArtist() != null && !tr.getArtist().isEmpty())
              && (rippedDisc.getArtist() != null && !rippedDisc.getArtist().isEmpty())
              && (!tr.getArtist().equalsIgnoreCase(rippedDisc.getArtist()))) {
            rippedDisc.addTrack(
                new Track(
                    splitPath[splitPath.length - 1],
                    tr.getArtist() + " - " + tr.getTitle(),
                    tr.getArtist()));

          } else {
            if ((tr.getArtist() != null && !tr.getArtist().isEmpty())) {
              rippedDisc.addTrack(
                  new Track(splitPath[splitPath.length - 1], tr.getTitle(), tr.getArtist()));
            } else {
              rippedDisc.addTrack(new Track(splitPath[splitPath.length - 1], tr.getTitle()));
            }
          }
        } catch (Exception e) {
          rippedDisc.addTrack(
              new Track(splitPath[splitPath.length - 1], splitPath[splitPath.length - 1]));
          parentWindow.setStatus(e.getMessage());
          System.out.println(e.getStackTrace());
        }
      } else {
        String trackTitle;
        if (options.isParseTitle()) {
          trackTitle = parseTrackTitle(splitPath[splitPath.length - 1]);
        } else {
          trackTitle = splitPath[splitPath.length - 1];
        }
        rippedDisc.addTrack(new Track(splitPath[splitPath.length - 1], trackTitle));
      }

      okToUseTags = false;
    }
    // add last album
    rippedDiscs.add(rippedDisc);

    // write cue files
    writeCueFiles();
    parentWindow.setStatus("Cue creation complete");
  }
示例#3
0
 @Override
 public void setAlbumTitle(String title) {
   album.setAlbumTitle(title);
 }
示例#4
0
 private synchronized void initAlbum() {
   album.setAlbumCover(null);
   album.setAlbumTitle(context.getString(R.string.album_untitled));
   album.setBrowserController(browserController);
 }