001    package helliker.id3;
002    
003    import java.util.HashMap;
004    import java.util.Iterator;
005    /*
006     *  Copyright (C) 2001 Jonathan Hilliker
007     *  2004, Moritz Ringler. (Major changes in javadoc)
008     *
009     *  This library is free software; you can redistribute it and/or
010     *  modify it under the terms of the GNU Lesser General Public
011     *  License as published by the Free Software Foundation; either
012     *  version 2.1 of the License, or (at your option) any later version.
013     *
014     *  This library is distributed in the hope that it will be useful,
015     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
016     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017     *  Lesser General Public License for more details.
018     *
019     *  You should have received a copy of the GNU Lesser General Public
020     *  License along with this library; if not, write to the Free Software
021     *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022     */
023    
024    
025    
026    
027    /**
028     * This class is a collection that is used to hold the ID3v2Frames.
029     */
030    
031    /** Frame definitions according to
032     *  <a href="http://www.id3.org/id3v2.4.0-frames.txt">Martin Nilsson,
033     *  ID3 tag version 2.4.0 - Native Frames,  2000-11-01</a>
034     *  from <a href="http://www.id3.org">the ID3v2 web site</a>.
035     **/
036    public class ID3v2Frames extends HashMap {
037    
038      //
039      /** Album/Movie/Show title.
040       *  The 'Album/Movie/Show title' frame is intended for the title of the
041       *  recording (or source of sound) from which the audio in the file is
042       *  taken.
043       **/
044      public static String ALBUM = "TALB";
045      /** BPM (beats per minute).
046       *  The 'BPM' frame contains the number of beats per minute in the
047       *  main part of the audio. The BPM is an integer and represented as a
048       *  numerical string.
049       **/
050      public static String BPM = "TBPM";
051      /** Composer.
052       *  The 'Composer' frame is intended for the name of the composer.
053       **/
054      public static String COMPOSER = "TCOM";
055      /** Content type (Genre).
056       * The 'Content type', which ID3v1 was stored as a one byte numeric
057       * value only, is now a string. You may use one or several of the ID3v1
058       * types as numerical strings, or, since the category list would be
059       * impossible to maintain with accurate and up to date categories,
060       * define your own. Example: "21" $00 "Eurodisco" $00
061       *
062       * You may also use any of the following keywords:
063       *
064       * RX  Remix
065       * CR  Cover
066       **/
067      public static String CONTENT_TYPE = "TCON";
068      /** Copyright message.
069       *  The 'Copyright message' frame, in which the string must begin with a
070       *  year and a space character (making five characters), is intended for
071       *  the copyright holder of the original sound, not the audio file
072       *  itself. The absence of this frame means only that the copyright
073       *  information is unavailable or has been removed, and must not be
074       *  interpreted to mean that the audio is public domain. Every time this
075       *  field is displayed the field must be preceded with "Copyright " (C) "
076       * ", where (C) is one character showing a C in a circle.
077       **/
078      public static String COPYRIGHT_MESSAGE = "TCOP";
079      /** Encoding time **/
080      public static String ENCODING_TIME = "TDEN";
081      /** Playlist delay **/
082      public static String PLAYLIST_DELAY = "TDLY";
083      /** Original release time **/
084      public static String ORIGINAL_RELEASE_TIME = "TDOR";
085      /** Recording time **/
086      public static String RECORDING_TIME = "TDRC";
087      /** Release time **/
088      public static String RELEASE_TIME = "TDRL";
089      /** Tagging time **/
090      public static String TAGGING_TIME = "TDTG";
091      public static String ENCODED_BY = "TENC";
092      public static String LYRICIST = "TEXT";
093      public static String FILE_TYPE = "TFLT";
094      public static String INVOLVED_PEOPLE = "TIPL";
095      public static String CONTENT_GROUP = "TIT1";
096      public static String TITLE = "TIT2";
097      public static String SUBTITLE = "TIT3";
098      public static String INITIAL_KEY = "TKEY";
099      public static String LANGUAGE = "TLAN";
100      public static String LENGTH = "TLEN";
101      public static String MUSICIAN_CREDITS = "TMCL";
102      public static String MEDIA_TYPE = "TMED";
103      public static String MOOD = "TMOO";
104      public static String ORIGINAL_ALBUM = "TOAL";
105      public static String ORIGINAL_FILENAME = "TOFN";
106      public static String ORIGINAL_LYRICIST = "TOLY";
107      public static String ORIGINAL_ARTIST = "TOPE";
108      public static String FILE_OWNER = "TOWN";
109      public static String LEAD_PERFORMERS = "TPE1";
110      public static String ACCOMPANIMENT = "TPE2";
111      public static String CONDUCTOR = "TPE3";
112      public static String REMIXED_BY = "TPE4";
113      public static String PART_OF_SET = "TPOS";
114      public static String PRODUCED_NOTICE = "TPRO";
115      public static String PUBLISHER = "TPUB";
116      public static String TRACK_NUMBER = "TRCK";
117      public static String INTERNET_RADIO_STATION_NAME = "TRSN";
118      public static String INTERNET_RADIO_STATION_OWNER = "TRSO";
119      public static String ALBUM_SORT_ORDER = "TSOA";
120      public static String PERFORMER_SORT_ORDER = "TSOP";
121      public static String TITLE_SORT_ORDER = "TSOT";
122      public static String ISRC = "TSRC";
123      public static String SOFTWARE_HARDWARE_SETTINGS = "TSSE";
124      public static String SET_SUBTITLE = "TSST";
125      public static String USER_DEFINED_TEXT_INFO = "TXXX";
126      public static String YEAR = "TYER";
127      public static String COMMERCIAL_INFO_URL = "WCOM";
128      public static String COPYRIGHT_INFO_URL = "WCOP";
129      public static String OFFICIAL_FILE_WEBPAGE_URL = "WOAF";
130      public static String OFFICIAL_ARTIST_WEBPAGE_URL = "WOAR";
131      public static String OFFICIAL_SOURCE_WEBPAGE_URL = "WOAS";
132      public static String OFFICIAL_INTERNET_RADIO_WEBPAGE_URL = "WOAS";
133      public static String PAYMENT_URL = "WPAY";
134      public static String OFFICIAL_PUBLISHER_WEBPAGE_URL = "WPUB";
135      public static String USER_DEFINED_URL = "WXXX";
136      public static String AUDIO_ENCRYPTION = "AENC";
137      public static String ATTACHED_PICTURE = "APIC";
138      public static String AUDIO_SEEK_POINT_INDEX = "ASPI";
139      public static String COMMENTS = "COMM";
140      public static String COMMERCIAL_FRAME = "COMR";
141      public static String ENCRYPTION_METHOD_REGISTRATION = "ENCR";
142      public static String EQUALISATION = "EQU2";
143      public static String EVENT_TIMING_CODES = "ETCO";
144      public static String GENERAL_ENCAPSULATED_OBJECT = "GEOB";
145      public static String GROUP_IDENTIFICATION_REGISTRATION = "GRID";
146      public static String LINKED_INFORMATION = "LINK";
147      public static String MUSIC_CD_IDENTIFIER = "MCDI";
148      public static String MPEG_LOCATION_LOOKUP_TABLE = "MLLT";
149      public static String OWNERSHIP_FRAME = "OWNE";
150      public static String PRIVATE_FRAME = "PRIV";
151      public static String PLAY_COUNTER = "PCNT";
152      public static String POPULARIMETER = "POPM";
153      public static String POSITION_SYNCHRONISATION_FRAME = "POSS";
154      public static String RECOMMENDED_BUFFER_SIZE = "RBUF";
155      public static String RELATIVE_VOLUME_ADJUSTMENT = "RVA2";
156      public static String REVERB = "RVRB";
157      public static String SEEK_FRAME = "SEEK";
158      public static String SIGNATURE_FRAME = "SIGN";
159      public static String SYNCHRONISED_LYRIC = "SYLT";
160      public static String SYNCHRONISED_TEMPO_CODES = "SYTC";
161      public static String UNIQUE_FILE_IDENTIFIER = "UFID";
162      public static String TERMS_OF_USE = "USER";
163      public static String UNSYNCHRONISED_LYRIC_TRANSCRIPTION = "USLT";
164    
165    
166      /** Returns the length in bytes of all the frames contained in this object.
167       * Empty frames are dropped from this calculation.
168       *
169       * @return the length of all the frames contained in this object.
170       */
171      public int getLength() {
172        int length = 0;
173    
174        Iterator it = this.values().iterator();
175        while (it.hasNext()) {
176          ID3v2Frame frame = (ID3v2Frame) it.next();
177    
178          if (!frame.isEmpty()) {
179            length += frame.getFrameLength();
180          }
181        }
182    
183        return length;
184      }
185    
186    
187      /** Return an array bytes containing all frames contained in this object. This
188       * can be used to easily write the frames to a file. Empty frames are dropped
189       * to save space.
190       *
191       * @return an array of bytes contain all frames contained in this object
192       */
193      public byte[] getBytes() {
194        byte b[] = new byte[getLength()];
195        int bytesCopied = 0;
196    
197        Iterator it = this.values().iterator();
198        while (it.hasNext()) {
199          ID3v2Frame frame = (ID3v2Frame) it.next();
200    
201          if (!frame.isEmpty()) {
202            System.arraycopy(frame.getFrameBytes(), 0, b, bytesCopied,
203              frame.getFrameLength());
204            bytesCopied += frame.getFrameLength();
205          }
206        }
207    
208        return b;
209      }
210    
211    
212      /** Returns a string representation of this object. Returns the toStrings of
213       * all the frames contained within seperated by line breaks.
214       *
215       * @return a string representation of this object
216       */
217      public String toString() {
218        String str = new String();
219    
220        Iterator it = this.values().iterator();
221        while (it.hasNext()) {
222          str += it.next().toString() + "\n";
223        }
224    
225        return str;
226      }
227    
228    }
229