| 1 | package org.farng.mp3.id3; |
| 2 | |
| 3 | import org.farng.mp3.AbstractMP3Fragment; |
| 4 | import org.farng.mp3.InvalidTagException; |
| 5 | import org.farng.mp3.TagUtility; |
| 6 | |
| 7 | import java.io.IOException; |
| 8 | import java.io.RandomAccessFile; |
| 9 | |
| 10 | /** |
| 11 | * This abstract class is each frame header inside a ID3v2 tag <P> |
| 12 | * |
| 13 | * @author Eric Farng |
| 14 | * @version $Revision: 1.4 $ |
| 15 | */ |
| 16 | public abstract class AbstractID3v2Frame extends AbstractMP3Fragment { |
| 17 | |
| 18 | /** |
| 19 | * Creates a new AbstractID3v2Frame object. |
| 20 | */ |
| 21 | protected AbstractID3v2Frame() { |
| 22 | super(); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Creates a new AbstractID3v2Frame object. |
| 27 | */ |
| 28 | protected AbstractID3v2Frame(final AbstractID3v2FrameBody body) { |
| 29 | super(body); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Creates a new AbstractID3v2Frame object. |
| 34 | */ |
| 35 | protected AbstractID3v2Frame(final AbstractID3v2Frame frame) { |
| 36 | super(frame); |
| 37 | } |
| 38 | |
| 39 | public String getIdentifier() { |
| 40 | String identifier = ""; |
| 41 | if (getBody() != null) { |
| 42 | identifier = getBody().getIdentifier(); |
| 43 | } |
| 44 | return identifier; |
| 45 | } |
| 46 | |
| 47 | public static boolean isValidID3v2FrameIdentifier(final String identifier) { |
| 48 | char character; |
| 49 | boolean valid = true; |
| 50 | for (int i = 0; i < identifier.length(); i++) { |
| 51 | character = identifier.charAt(i); |
| 52 | if (character >= 'A' && character <= 'Z' || (character >= '0' && character <= '9')) { |
| 53 | // nothing |
| 54 | } else { |
| 55 | valid = false; |
| 56 | } |
| 57 | } |
| 58 | return valid; |
| 59 | } |
| 60 | |
| 61 | public String toString() { |
| 62 | String string = ""; |
| 63 | if (getBody() != null) { |
| 64 | string = getBody().toString(); |
| 65 | } |
| 66 | return string; |
| 67 | } |
| 68 | |
| 69 | protected static AbstractID3v2FrameBody readBody(final String identifier, final RandomAccessFile file) |
| 70 | throws IOException, InvalidTagException { |
| 71 | final String frameIdentifier; |
| 72 | final AbstractID3v2FrameBody newBody; |
| 73 | if (TagUtility.isID3v2_2FrameIdentifier(identifier)) { |
| 74 | frameIdentifier = TagUtility.convertFrameID2_2to2_4(identifier); |
| 75 | } else { |
| 76 | frameIdentifier = identifier; |
| 77 | } |
| 78 | if ("APIC".equals(frameIdentifier)) { |
| 79 | newBody = new FrameBodyAPIC(file); |
| 80 | } else if ("COMM".equals(frameIdentifier)) { |
| 81 | newBody = new FrameBodyCOMM(file); |
| 82 | } else if ("ENCR".equals(frameIdentifier)) { |
| 83 | newBody = new FrameBodyENCR(file); |
| 84 | } else if ("GEOB".equals(frameIdentifier)) { |
| 85 | newBody = new FrameBodyGEOB(file); |
| 86 | } else if ("GRID".equals(frameIdentifier)) { |
| 87 | newBody = new FrameBodyGRID(file); |
| 88 | } else if ("MCDI".equals(frameIdentifier)) { |
| 89 | newBody = new FrameBodyMCDI(file); |
| 90 | } else if ("PCNT".equals(frameIdentifier)) { |
| 91 | newBody = new FrameBodyPCNT(file); |
| 92 | } else if ("POPM".equals(frameIdentifier)) { |
| 93 | newBody = new FrameBodyPOPM(file); |
| 94 | } else if ("PRIV".equals(frameIdentifier)) { |
| 95 | newBody = new FrameBodyPRIV(file); |
| 96 | } else if ("RVAD".equals(frameIdentifier)) { |
| 97 | newBody = new FrameBodyRVAD(file); |
| 98 | } else if ("SYLT".equals(frameIdentifier)) { |
| 99 | newBody = new FrameBodySYLT(file); |
| 100 | } else if ("TALB".equals(frameIdentifier)) { |
| 101 | newBody = new FrameBodyTALB(file); |
| 102 | } else if ("TBPM".equals(frameIdentifier)) { |
| 103 | newBody = new FrameBodyTBPM(file); |
| 104 | } else if ("TCOM".equals(frameIdentifier)) { |
| 105 | newBody = new FrameBodyTCOM(file); |
| 106 | } else if ("TCON".equals(frameIdentifier)) { |
| 107 | newBody = new FrameBodyTCON(file); |
| 108 | } else if ("TCOP".equals(frameIdentifier)) { |
| 109 | newBody = new FrameBodyTCOP(file); |
| 110 | } else if ("TDAT".equals(frameIdentifier)) { |
| 111 | newBody = new FrameBodyTDAT(file); // Deprecated |
| 112 | } else if ("TDEN".equals(frameIdentifier)) { |
| 113 | newBody = new FrameBodyTDEN(file); |
| 114 | } else if ("TDLY".equals(frameIdentifier)) { |
| 115 | newBody = new FrameBodyTDLY(file); |
| 116 | } else if ("TDOR".equals(frameIdentifier)) { |
| 117 | newBody = new FrameBodyTDOR(file); |
| 118 | } else if ("TDRC".equals(frameIdentifier)) { |
| 119 | newBody = new FrameBodyTDRC(file); |
| 120 | } else if ("TDRL".equals(frameIdentifier)) { |
| 121 | newBody = new FrameBodyTDRL(file); |
| 122 | } else if ("TDTG".equals(frameIdentifier)) { |
| 123 | newBody = new FrameBodyTDTG(file); |
| 124 | } else if ("TENC".equals(frameIdentifier)) { |
| 125 | newBody = new FrameBodyTENC(file); |
| 126 | } else if ("TEXT".equals(frameIdentifier)) { |
| 127 | newBody = new FrameBodyTEXT(file); |
| 128 | } else if ("TFLT".equals(frameIdentifier)) { |
| 129 | newBody = new FrameBodyTFLT(file); |
| 130 | } else if ("TIME".equals(frameIdentifier)) { |
| 131 | newBody = new FrameBodyTIME(file); // Deprecated |
| 132 | } else if ("TIPL".equals(frameIdentifier)) { |
| 133 | newBody = new FrameBodyTIPL(file); |
| 134 | } else if ("TIT1".equals(frameIdentifier)) { |
| 135 | newBody = new FrameBodyTIT1(file); |
| 136 | } else if ("TIT2".equals(frameIdentifier)) { |
| 137 | newBody = new FrameBodyTIT2(file); |
| 138 | } else if ("TIT3".equals(frameIdentifier)) { |
| 139 | newBody = new FrameBodyTIT3(file); |
| 140 | } else if ("TKEY".equals(frameIdentifier)) { |
| 141 | newBody = new FrameBodyTKEY(file); |
| 142 | } else if ("TLAN".equals(frameIdentifier)) { |
| 143 | newBody = new FrameBodyTLAN(file); |
| 144 | } else if ("TLEN".equals(frameIdentifier)) { |
| 145 | newBody = new FrameBodyTLEN(file); |
| 146 | } else if ("TMCL".equals(frameIdentifier)) { |
| 147 | newBody = new FrameBodyTMCL(file); |
| 148 | } else if ("TMED".equals(frameIdentifier)) { |
| 149 | newBody = new FrameBodyTMED(file); |
| 150 | } else if ("TMOO".equals(frameIdentifier)) { |
| 151 | newBody = new FrameBodyTMOO(file); |
| 152 | } else if ("TOAL".equals(frameIdentifier)) { |
| 153 | newBody = new FrameBodyTOAL(file); |
| 154 | } else if ("TOFN".equals(frameIdentifier)) { |
| 155 | newBody = new FrameBodyTOFN(file); |
| 156 | } else if ("TOLY".equals(frameIdentifier)) { |
| 157 | newBody = new FrameBodyTOLY(file); |
| 158 | } else if ("TOPE".equals(frameIdentifier)) { |
| 159 | newBody = new FrameBodyTOPE(file); |
| 160 | } else if ("TORY".equals(frameIdentifier)) { |
| 161 | newBody = new FrameBodyTORY(file); // Deprecated |
| 162 | } else if ("TOWN".equals(frameIdentifier)) { |
| 163 | newBody = new FrameBodyTOWN(file); |
| 164 | } else if ("TPE1".equals(frameIdentifier)) { |
| 165 | newBody = new FrameBodyTPE1(file); |
| 166 | } else if ("TPE2".equals(frameIdentifier)) { |
| 167 | newBody = new FrameBodyTPE2(file); |
| 168 | } else if ("TPE3".equals(frameIdentifier)) { |
| 169 | newBody = new FrameBodyTPE3(file); |
| 170 | } else if ("TPE4".equals(frameIdentifier)) { |
| 171 | newBody = new FrameBodyTPE4(file); |
| 172 | } else if ("TPOS".equals(frameIdentifier)) { |
| 173 | newBody = new FrameBodyTPOS(file); |
| 174 | } else if ("TPRO".equals(frameIdentifier)) { |
| 175 | newBody = new FrameBodyTPRO(file); |
| 176 | } else if ("TPUB".equals(frameIdentifier)) { |
| 177 | newBody = new FrameBodyTPUB(file); |
| 178 | } else if ("TRCK".equals(frameIdentifier)) { |
| 179 | newBody = new FrameBodyTRCK(file); |
| 180 | } else if ("TRDA".equals(frameIdentifier)) { |
| 181 | newBody = new FrameBodyTRDA(file); // Deprecated |
| 182 | } else if ("TRSN".equals(frameIdentifier)) { |
| 183 | newBody = new FrameBodyTRSN(file); |
| 184 | } else if ("TRSO".equals(frameIdentifier)) { |
| 185 | newBody = new FrameBodyTRSO(file); |
| 186 | } else if ("TSIZ".equals(frameIdentifier)) { |
| 187 | newBody = new FrameBodyTSIZ(file); // Deprecated |
| 188 | } else if ("TSOA".equals(frameIdentifier)) { |
| 189 | newBody = new FrameBodyTSOA(file); |
| 190 | } else if ("TSOP".equals(frameIdentifier)) { |
| 191 | newBody = new FrameBodyTSOP(file); |
| 192 | } else if ("TSOT".equals(frameIdentifier)) { |
| 193 | newBody = new FrameBodyTSOT(file); |
| 194 | } else if ("TSRC".equals(frameIdentifier)) { |
| 195 | newBody = new FrameBodyTSRC(file); |
| 196 | } else if ("TSSE".equals(frameIdentifier)) { |
| 197 | newBody = new FrameBodyTSSE(file); |
| 198 | } else if ("TSST".equals(frameIdentifier)) { |
| 199 | newBody = new FrameBodyTSST(file); |
| 200 | } else if ("TXXX".equals(frameIdentifier)) { |
| 201 | newBody = new FrameBodyTXXX(file); |
| 202 | } else if ("TYER".equals(frameIdentifier)) { |
| 203 | newBody = new FrameBodyTYER(file); // Deprecated |
| 204 | } else if ("UFID".equals(frameIdentifier)) { |
| 205 | newBody = new FrameBodyUFID(file); |
| 206 | } else if ("USLT".equals(frameIdentifier)) { |
| 207 | newBody = new FrameBodyUSLT(file); |
| 208 | } else if ("WCOM".equals(frameIdentifier)) { |
| 209 | newBody = new FrameBodyWCOM(file); |
| 210 | } else if ("WCOP".equals(frameIdentifier)) { |
| 211 | newBody = new FrameBodyWCOP(file); |
| 212 | } else if ("WOAF".equals(frameIdentifier)) { |
| 213 | newBody = new FrameBodyWOAF(file); |
| 214 | } else if ("WOAR".equals(frameIdentifier)) { |
| 215 | newBody = new FrameBodyWOAR(file); |
| 216 | } else if ("WOAS".equals(frameIdentifier)) { |
| 217 | newBody = new FrameBodyWOAS(file); |
| 218 | } else if ("WORS".equals(frameIdentifier)) { |
| 219 | newBody = new FrameBodyWORS(file); |
| 220 | } else if ("WPAY".equals(frameIdentifier)) { |
| 221 | newBody = new FrameBodyWPAY(file); |
| 222 | } else if ("WPUB".equals(frameIdentifier)) { |
| 223 | newBody = new FrameBodyWPUB(file); |
| 224 | } else if ("WXXX".equals(frameIdentifier)) { |
| 225 | newBody = new FrameBodyWXXX(file); |
| 226 | } else { |
| 227 | newBody = new FrameBodyUnsupported(file); |
| 228 | } |
| 229 | return newBody; |
| 230 | } |
| 231 | } |