Package entagged.audioformats.mp3.util.id3frames

Examples of entagged.audioformats.mp3.util.id3frames.Id3Frame


            dataset = new DataSet();
        }
        RandomAccessFile raf = null;
        try {
            raf = new RandomAccessFile(file, "r");
            Id3v1Tag tag = new Id3v1TagReader().read(raf);
            if (tag != null) {
                dataset.setTrack(tag.getFirstTrack());
                dataset.setAlbum(tag.getFirstAlbum());
                dataset.setArtist(tag.getFirstArtist());
                dataset.setComment(tag.getFirstComment());
                dataset.setGenre(tag.getFirstGenre());
                dataset.setTitle(tag.getFirstTitle());
                dataset.setYear(tag.getFirstYear());
                return dataset;
            }
        } catch (Exception e) {
            logger.debug("Couldn't read version 1 tag:\n\t" + e);
        } finally {
View Full Code Here


    private boolean setV1Tag(File file, DataSet dataset) {
        RandomAccessFile raf = null;
        try {
            raf = new RandomAccessFile(file, "rw");

            Id3v1Tag tag = new Id3v1Tag();

            tag.setTitle(dataset.getTitle());
            tag.setTrack(dataset.getTrack());
            tag.setArtist(dataset.getArtist());
            tag.setAlbum(dataset.getAlbum());
            tag.setGenre(dataset.getGenre());
            tag.setComment(dataset.getComment());
            tag.setYear(dataset.getYear());

            new Id3v1TagWriter().write(tag, raf);
            return true;
        } catch (Exception e) {
            logger.warn("Couldn't write ID3V1 tag", e);
View Full Code Here

    return b;
  }

  protected Tag getCompatibleTag(Tag tag) {
    if (!(tag instanceof Id3v2Tag)) {
      Id3v2Tag id3Tag = new Id3v2Tag();
      id3Tag.merge(tag);
      return id3Tag;
    }
    return tag;
  }
View Full Code Here

      throws UnsupportedEncodingException {
    // get the tagsize from the buffers size.
    int tagSize = data.limit();
    byte[] b;
    // Create a result object
    Id3v2Tag tag = new Id3v2Tag();
    // ---------------------------------------------------------------------
    // If the flags indicate an extended header to be present, read its
    // size and skip it. (It does not contain any useful information, maybe
    // CRC)
    if ((version == Id3v2Tag.ID3V23 || version == Id3v2Tag.ID3V24)
        && ID3Flags[1]) {
      processExtendedHeader(data, version);
    }
    // ---------------------------------------------------------------------
    /*
     * Now start the extraction of the text frames.
     */
    // The frame names differ in lengths between version 2 to 3
    int specSize = (version == Id3v2Tag.ID3V22) ? 3 : 4;
    // As long as we have unread bytes...
    for (int a = 0; a < tagSize; a++) {
      // Create buffer taking the name of the frame.
      b = new byte[specSize];

      // Do we still have enough bytes for reading the name?
      if (data.remaining() <= specSize)
        break;

      // Read the Name
      data.get(b);

      // Convert the bytes (of the name) into a String.
      String field = new String(b);
      // If byte[0] is zero, we have invalid data
      if (b[0] == 0)
        break;

      // Now we read the length of the current frame
      int frameSize = readSize(data, version);

      // If the framesize is greater than the bytes we've left to read,
      // or the frame length is zero, abort. Invalid data
      if ((frameSize > data.remaining()) || frameSize <= 0) {
        // ignore empty frames
        System.err.println(field
            + " Frame size error, skiping the rest of the tag:"
            + frameSize);
        break;
      }

      b = new byte[frameSize
          + ((version == Id3v2Tag.ID3V23 || version == Id3v2Tag.ID3V24) ? 2
              : 0)];
      // Read the complete frame into the byte array.
      data.get(b);

      // Check the frame name once more
      if (!"".equals(field)) {
        Id3Frame f = null;
        /*
         * Now catch possible errors occuring in the data
         * interpretation. Even if a frame is not valid regarding the
         * spec, the rest of the tag could be read.
         */
        try {
          // Create the Frame upon the byte array data.
          f = createId3Frame(field, b, version);
        } catch (UnsupportedEncodingException uee) {
          throw uee;
        } catch (Exception e) {
          e.printStackTrace();
        }
        // If the frame was successfully parsed, add it to the tag.
        if (f != null)
          tag.add(f);
      }
    }

    return tag;
  }
View Full Code Here

   *             On I/O errors.
   */
  public synchronized Id3v2Tag read(RandomAccessFile raf)
      throws CannotReadException, IOException {
    // Create the Result object
    Id3v2Tag tag = null;

    // Buffer for Identifying the ID3 signature.
    byte[] b = new byte[3];
    raf.read(b);

View Full Code Here

        }

        RandomAccessFile raf = null;
        try {
            raf = new RandomAccessFile(file, "r");
            Id3v2Tag tag = new Id3v2TagReader().read(raf);
            if (tag != null) {
                if (dataset.getAlbum().equals("") || dataset.getAlbum().length() < tag.getFirstAlbum().length()) {
                    dataset.setAlbum(tag.getFirstAlbum());
                }
                if (dataset.getArtist().equals("") || dataset.getArtist().length() < tag.getFirstArtist().length()) {
                    dataset.setArtist(tag.getFirstArtist());
                }
                if (dataset.getComment().equals("") || dataset.getComment().length() < tag.getFirstComment().length()) {
                    dataset.setComment(tag.getFirstComment());
                }
                if (dataset.getComposer().equals("") || dataset.getComposer().length() < getFirst(tag, "TCOM").length()) {
                    dataset.setComposer(getFirst(tag, "TCOM"));
                }
                if (dataset.getCopyright().equals("") || dataset.getCopyright().length() < getFirst(tag, "TCOP").length()) {
                    dataset.setCopyright(getFirst(tag, "TCOP"));
                }
                if (dataset.getEncodedBy().equals("") || dataset.getEncodedBy().length() < getFirst(tag, "TENC").length()) {
                    dataset.setEncodedBy(getFirst(tag, "TENC"));
                }
                if (dataset.getGenre().equals("") || dataset.getGenre().equals("unknown")) {
                    dataset.setGenre(tag.getFirstGenre());
                }
                if (dataset.getOrigArtist().equals("") || dataset.getOrigArtist().length() < getFirst(tag, "TOPE").length()) {
                    dataset.setOrigArtist(getFirst(tag, "TOPE"));
                }
                if (dataset.getTitle().equals("") || dataset.getTitle().length() < tag.getFirstTitle().length()) {
                    dataset.setTitle(tag.getFirstTitle());
                }
                if (dataset.getTrack().equals("") || dataset.getTrack().equals("0")) {
                    dataset.setTrack(tag.getFirstTrack());
                }
                if (dataset.getUrl().equals("") || dataset.getUrl().length() < getFirst(tag, "WXXX").length()) {
                    dataset.setUrl(getFirst(tag, "WXXX"));
                }
                if (dataset.getYear().equals("") || dataset.getYear().length() < getFirst(tag, "TYER").length()) {
                    dataset.setYear(getFirst(tag, "TYER"));
                }
                if (dataset.getYear().length() == 0) {
                    dataset.setYear(tag.getFirstYear());
                }
                dataset.setPartOfSet(getFirst(tag, "TPOS"));
                dataset.setPartOfCompilation("1".equals(getFirst(tag, "TCMP")));

                return dataset;
View Full Code Here

        RandomAccessFile raf = null;
        RandomAccessFile tempRaf = null;
        try {
            raf = new RandomAccessFile(file, "rw");

            Id3v2Tag tag = new Id3v2Tag();

            tag.setTitle(dataset.getTitle());
            tag.setTrack(dataset.getTrack());
            tag.setArtist(dataset.getArtist());
            tag.setAlbum(dataset.getAlbum());
            tag.setComment(dataset.getComment());
            tag.set(createTextFrame("WXXX", dataset.getUrl()));
            tag.set(createTextFrame("TCOM", dataset.getComposer()));
            tag.set(createTextFrame("TCOP", dataset.getCopyright()));
            tag.set(createTextFrame("TENC", dataset.getEncodedBy()));
            tag.set(createTextFrame("TOPE", dataset.getOrigArtist()));
            tag.setYear(dataset.getYear()); // id3 2.4
            tag.set(createTextFrame("TYER", dataset.getYear())); // id3 2.3
            tag.setGenre(dataset.getGenre());
            tag.set(createTextFrame("TCMP", dataset.isPartOfCompilation() ? "1" : "0"));
            tag.set(createTextFrame("TPOS", dataset.getPartOfSet()));

            File tempFile = File.createTempFile("jmp3renamer_mp3", "tmp");
            tempRaf = new RandomAccessFile(tempFile, "rw");
            new Id3v2TagWriter().write(tag, raf, tempRaf);
            return true;
View Full Code Here

  /**
   * Creates the readers and writers.
   */
  private void prepareReadersAndWriters() {
    // Tag Readers
    readers.put("mp3", new Mp3FileReader());
    readers.put("ogg", new OggFileReader());
    readers.put("flac", new FlacFileReader());
    readers.put("wav", new WavFileReader());
    readers.put("mpc", new MpcFileReader());
    readers.put("mp+", readers.get("mpc"));
View Full Code Here

    readers.put("mp+", readers.get("mpc"));
    readers.put("ape", new MonkeyFileReader());
    readers.put("wma", new AsfFileReader());

    // Tag Writers
    writers.put("mp3", new Mp3FileWriter());
    writers.put("ogg", new OggFileWriter());
    writers.put("flac", new FlacFileWriter());
    writers.put("wav", new WavFileWriter());
    writers.put("mpc", new MpcFileWriter());
    writers.put("mp+", writers.get("mpc"));
View Full Code Here

            dataset = new DataSet();
        }
        RandomAccessFile raf = null;
        try {
            raf = new RandomAccessFile(file, "r");
            Id3v1Tag tag = new Id3v1TagReader().read(raf);
            if (tag != null) {
                dataset.setTrack(tag.getFirstTrack());
                dataset.setAlbum(tag.getFirstAlbum());
                dataset.setArtist(tag.getFirstArtist());
                dataset.setComment(tag.getFirstComment());
View Full Code Here

TOP

Related Classes of entagged.audioformats.mp3.util.id3frames.Id3Frame

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.