Example #1
0
  /**
   * Write this representation of tag to the file indicated
   *
   * @param file that this tag should be written to
   * @throws IOException thrown if there were problems writing to the file
   */
  public void write(RandomAccessFile file) throws IOException {
    logger.info("Saving ID3v11 tag to file");
    byte[] buffer = new byte[TAG_LENGTH];
    int i;
    String str;
    delete(file);
    file.seek(file.length());
    System.arraycopy(TAG_ID, FIELD_TAGID_POS, buffer, FIELD_TAGID_POS, TAG_ID.length);
    int offset = FIELD_TITLE_POS;
    if (TagOptionSingleton.getInstance().isId3v1SaveTitle()) {
      str = ID3Tags.truncate(title, FIELD_TITLE_LENGTH);
      for (i = 0; i < str.length(); i++) {
        buffer[i + offset] = (byte) str.charAt(i);
      }
    }
    offset = FIELD_ARTIST_POS;
    if (TagOptionSingleton.getInstance().isId3v1SaveArtist()) {
      str = ID3Tags.truncate(artist, FIELD_ARTIST_LENGTH);
      for (i = 0; i < str.length(); i++) {
        buffer[i + offset] = (byte) str.charAt(i);
      }
    }
    offset = FIELD_ALBUM_POS;
    if (TagOptionSingleton.getInstance().isId3v1SaveAlbum()) {
      str = ID3Tags.truncate(album, FIELD_ALBUM_LENGTH);
      for (i = 0; i < str.length(); i++) {
        buffer[i + offset] = (byte) str.charAt(i);
      }
    }
    offset = FIELD_YEAR_POS;
    if (TagOptionSingleton.getInstance().isId3v1SaveYear()) {
      str = ID3Tags.truncate(year, FIELD_YEAR_LENGTH);
      for (i = 0; i < str.length(); i++) {
        buffer[i + offset] = (byte) str.charAt(i);
      }
    }
    offset = FIELD_COMMENT_POS;
    if (TagOptionSingleton.getInstance().isId3v1SaveComment()) {
      str = ID3Tags.truncate(comment, FIELD_COMMENT_LENGTH);
      for (i = 0; i < str.length(); i++) {
        buffer[i + offset] = (byte) str.charAt(i);
      }
    }
    offset = FIELD_TRACK_POS;
    buffer[offset] = track; // skip one byte extra blank for 1.1 definition
    offset = FIELD_GENRE_POS;
    if (TagOptionSingleton.getInstance().isId3v1SaveGenre()) {
      buffer[offset] = genre;
    }
    file.write(buffer);

    logger.info("Saved ID3v11 tag to file");
  }
Example #2
0
 /**
  * Set Comment
  *
  * @param comment
  */
 public void setComment(String comment) {
   if (comment == null) {
     throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
   }
   this.comment = ID3Tags.truncate(comment, FIELD_COMMENT_LENGTH);
 }
Example #3
0
  /**
   * Creates a new ID3v11 datatype from a non v11 tag
   *
   * @param mp3tag
   * @throws UnsupportedOperationException
   */
  public ID3v11Tag(AbstractTag mp3tag) {
    if (mp3tag != null) {
      if (mp3tag instanceof ID3v1Tag) {
        if (mp3tag instanceof ID3v11Tag) {
          throw new UnsupportedOperationException(
              "Copy Constructor not called. Please type cast the argument");
        }
        // id3v1_1 objects are also id3v1 objects
        ID3v1Tag id3old = (ID3v1Tag) mp3tag;
        this.title = id3old.title;
        this.artist = id3old.artist;
        this.album = id3old.album;
        this.comment = id3old.comment;
        this.year = id3old.year;
        this.genre = id3old.genre;
      } else {
        ID3v24Tag id3tag;
        // first change the tag to ID3v2_4 tag if not one already
        if (!(mp3tag instanceof ID3v24Tag)) {
          id3tag = new ID3v24Tag(mp3tag);
        } else {
          id3tag = (ID3v24Tag) mp3tag;
        }
        ID3v24Frame frame;
        String text;
        if (id3tag.hasFrame(ID3v24Frames.FRAME_ID_TITLE)) {
          frame = (ID3v24Frame) id3tag.getFrame(ID3v24Frames.FRAME_ID_TITLE);
          text = ((FrameBodyTIT2) frame.getBody()).getText();
          this.title = ID3Tags.truncate(text, FIELD_TITLE_LENGTH);
        }
        if (id3tag.hasFrame(ID3v24Frames.FRAME_ID_ARTIST)) {
          frame = (ID3v24Frame) id3tag.getFrame(ID3v24Frames.FRAME_ID_ARTIST);
          text = ((FrameBodyTPE1) frame.getBody()).getText();
          this.artist = ID3Tags.truncate(text, FIELD_ARTIST_LENGTH);
        }
        if (id3tag.hasFrame(ID3v24Frames.FRAME_ID_ALBUM)) {
          frame = (ID3v24Frame) id3tag.getFrame(ID3v24Frames.FRAME_ID_ALBUM);
          text = ((FrameBodyTALB) frame.getBody()).getText();
          this.album = ID3Tags.truncate(text, FIELD_ALBUM_LENGTH);
        }
        if (id3tag.hasFrame(ID3v24Frames.FRAME_ID_YEAR)) {
          frame = (ID3v24Frame) id3tag.getFrame(ID3v24Frames.FRAME_ID_YEAR);
          text = ((FrameBodyTDRC) frame.getBody()).getText();
          this.year = ID3Tags.truncate(text, FIELD_YEAR_LENGTH);
        }

        if (id3tag.hasFrame(ID3v24Frames.FRAME_ID_COMMENT)) {
          Iterator iterator = id3tag.getFrameOfType(ID3v24Frames.FRAME_ID_COMMENT);
          text = "";
          while (iterator.hasNext()) {
            frame = (ID3v24Frame) iterator.next();
            text += (((FrameBodyCOMM) frame.getBody()).getText() + " ");
          }
          this.comment = ID3Tags.truncate(text, FIELD_COMMENT_LENGTH);
        }
        if (id3tag.hasFrame(ID3v24Frames.FRAME_ID_GENRE)) {
          frame = (ID3v24Frame) id3tag.getFrame(ID3v24Frames.FRAME_ID_GENRE);
          text = ((FrameBodyTCON) frame.getBody()).getText();
          try {
            this.genre = (byte) ID3Tags.findNumber(text);
          } catch (TagException ex) {
            logger.log(
                Level.WARNING,
                getLoggingFilename()
                    + ":"
                    + "Unable to convert TCON frame to format suitable for v11 tag",
                ex);
            this.genre = (byte) ID3v1Tag.GENRE_UNDEFINED;
          }
        }
        if (id3tag.hasFrame(ID3v24Frames.FRAME_ID_TRACK)) {
          frame = (ID3v24Frame) id3tag.getFrame(ID3v24Frames.FRAME_ID_TRACK);
          this.track = (byte) ((FrameBodyTRCK) frame.getBody()).getTrackNo().intValue();
        }
      }
    }
  }
Example #4
0
 /**
  * Set year
  *
  * @param year
  */
 public void setYear(String year) {
   this.year = ID3Tags.truncate(year, FIELD_YEAR_LENGTH);
 }
Example #5
0
 /**
  * Set Title
  *
  * @param title
  */
 public void setTitle(String title) {
   if (title == null) {
     throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
   }
   this.title = ID3Tags.truncate(title, FIELD_TITLE_LENGTH);
 }
Example #6
0
 /**
  * Set Artist
  *
  * @param artist
  */
 public void setArtist(String artist) {
   if (artist == null) {
     throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
   }
   this.artist = ID3Tags.truncate(artist, FIELD_ARTIST_LENGTH);
 }
Example #7
0
 /**
  * Set Album
  *
  * @param album
  */
 public void setAlbum(String album) {
   if (album == null) {
     throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
   }
   this.album = ID3Tags.truncate(album, FIELD_ALBUM_LENGTH);
 }