001: /*
002: * This file is part of DrFTPD, Distributed FTP Daemon.
003: *
004: * DrFTPD is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * DrFTPD is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with DrFTPD; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package org.drftpd.id3;
019:
020: import java.io.Serializable;
021:
022: /**
023: * @author Teflon
024: * @version $Id: ID3Tag.java 1056 2005-02-26 11:36:35Z mog $
025: */
026: public class ID3Tag implements Serializable {
027: String artist = "";
028: String album = "";
029: String title = "";
030: String comment = "";
031: String year = "";
032: byte genre = 0;
033: byte track = 0;
034:
035: /** Constructor to create an empty tag -> insert your own data */
036: public ID3Tag() {
037: }
038:
039: public String getTitle() {
040: return title;
041: }
042:
043: public void setTitle(String title) {
044: this .title = title;
045: }
046:
047: public String getArtist() {
048: return artist;
049: }
050:
051: public void setArtist(String artist) {
052: this .artist = artist;
053: }
054:
055: public String getAlbum() {
056: return album;
057: }
058:
059: public void setAlbum(String album) {
060: this .album = album;
061: }
062:
063: public String getComment() {
064: return comment;
065: }
066:
067: public void setComment(String comment) {
068: this .comment = comment;
069: }
070:
071: public String getYear() {
072: return year;
073: }
074:
075: public void setYear(String year) {
076: this .year = year;
077: }
078:
079: public byte getTrack() {
080: return track;
081: }
082:
083: public void setTrack(byte track) {
084: this .track = track;
085: }
086:
087: public String getGenre() {
088: return ID3GenreList.getGenre(genre);
089: }
090:
091: public void setGenre(byte genre) {
092: this .genre = genre;
093: }
094:
095: /** Converts the whole tag to a byte array, so we can write it to a file or elsewhere...*/
096: byte[] toByteArray() {
097: byte[] tag = new byte[128];
098:
099: tag[0] = (byte) 'T';
100: tag[1] = (byte) 'A';
101: tag[2] = (byte) 'G';
102:
103: byte[] tempTitle = title.getBytes();
104: byte[] tempArtist = artist.getBytes();
105: byte[] tempAlbum = album.getBytes();
106: byte[] tempYear = year.getBytes();
107: byte[] tempComment = comment.getBytes();
108:
109: tag = writeToTag(tag, tempTitle, 3, 30);
110: tag = writeToTag(tag, tempArtist, 33, 30);
111: tag = writeToTag(tag, tempAlbum, 63, 30);
112: tag = writeToTag(tag, tempYear, 93, 4);
113: tag = writeToTag(tag, tempComment, 97, 28);
114:
115: tag[126] = track;
116: tag[127] = genre;
117:
118: return tag;
119: }
120:
121: /** Writes the array "bytes" to the array "tag" at given position "start" */
122: private byte[] writeToTag(byte[] tag, byte[] bytes, int start,
123: int length) {
124: for (int i = start; ((i - start) < bytes.length)
125: && (i < (start + length)); i++) {
126: tag[i] = bytes[i - start];
127: }
128:
129: return tag;
130: }
131:
132: public String toString() {
133: return "Artist=" + artist + "\n" + "Title=" + title + "\n"
134: + "Album=" + album + "\n" + "Track=" + track + "\n"
135: + "Year=" + year + "\n" + "Genre=" + getGenre() + "\n"
136: + "Comment=" + comment;
137: }
138: }
|