| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
package org.jaudiotagger.tag.id3; |
| 26 | |
|
| 27 | |
import java.io.IOException; |
| 28 | |
import java.io.RandomAccessFile; |
| 29 | |
import java.nio.ByteBuffer; |
| 30 | |
import java.nio.channels.FileChannel; |
| 31 | |
import java.util.logging.Logger; |
| 32 | |
import java.util.regex.Pattern; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
abstract public class AbstractID3v1Tag extends AbstractID3Tag |
| 41 | |
{ |
| 42 | |
|
| 43 | |
|
| 44 | 4 | public static Logger logger = Logger.getLogger("org.jaudiotagger.tag.id3"); |
| 45 | |
|
| 46 | |
|
| 47 | |
public AbstractID3v1Tag() |
| 48 | 5112 | { |
| 49 | 5112 | } |
| 50 | |
|
| 51 | |
public AbstractID3v1Tag(AbstractID3v1Tag copyObject) |
| 52 | |
{ |
| 53 | 0 | super(copyObject); |
| 54 | 0 | } |
| 55 | |
|
| 56 | |
|
| 57 | |
protected static final byte END_OF_FIELD = (byte) 0; |
| 58 | |
|
| 59 | |
|
| 60 | 4 | protected static Pattern endofStringPattern = Pattern.compile("\\x00"); |
| 61 | |
|
| 62 | |
|
| 63 | 4 | protected static final byte[] TAG_ID = {(byte) 'T', (byte) 'A', (byte) 'G'}; |
| 64 | |
|
| 65 | |
|
| 66 | |
protected static final int TAG_LENGTH = 128; |
| 67 | |
protected static final int TAG_DATA_LENGTH = 125; |
| 68 | |
protected static final int FIELD_TAGID_LENGTH = 3; |
| 69 | |
protected static final int FIELD_TITLE_LENGTH = 30; |
| 70 | |
protected static final int FIELD_ARTIST_LENGTH = 30; |
| 71 | |
protected static final int FIELD_ALBUM_LENGTH = 30; |
| 72 | |
protected static final int FIELD_YEAR_LENGTH = 4; |
| 73 | |
protected static final int FIELD_GENRE_LENGTH = 1; |
| 74 | |
|
| 75 | |
|
| 76 | |
protected static final int FIELD_TAGID_POS = 0; |
| 77 | |
protected static final int FIELD_TITLE_POS = 3; |
| 78 | |
protected static final int FIELD_ARTIST_POS = 33; |
| 79 | |
protected static final int FIELD_ALBUM_POS = 63; |
| 80 | |
protected static final int FIELD_YEAR_POS = 93; |
| 81 | |
protected static final int FIELD_GENRE_POS = 127; |
| 82 | |
|
| 83 | |
|
| 84 | |
protected static final String TYPE_TITLE = "title"; |
| 85 | |
protected static final String TYPE_ARTIST = "artist"; |
| 86 | |
protected static final String TYPE_ALBUM = "album"; |
| 87 | |
protected static final String TYPE_YEAR = "year"; |
| 88 | |
protected static final String TYPE_GENRE = "genre"; |
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
public int getSize() |
| 96 | |
{ |
| 97 | 0 | return TAG_LENGTH; |
| 98 | |
} |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
public void delete(RandomAccessFile file) throws IOException |
| 108 | |
{ |
| 109 | |
|
| 110 | 1239 | logger.info("Deleting ID3v1 from file if exists"); |
| 111 | |
|
| 112 | |
FileChannel fc; |
| 113 | |
ByteBuffer byteBuffer; |
| 114 | |
|
| 115 | |
|
| 116 | 1239 | fc = file.getChannel(); |
| 117 | 1239 | fc.position(file.length() - TAG_LENGTH); |
| 118 | 1239 | byteBuffer = ByteBuffer.allocate(TAG_LENGTH); |
| 119 | 1239 | fc.read(byteBuffer); |
| 120 | 1239 | byteBuffer.rewind(); |
| 121 | 1239 | if (seek(byteBuffer)) |
| 122 | |
{ |
| 123 | 241 | logger.info("Deleted ID3v1 tag "); |
| 124 | 241 | file.setLength(file.length() - TAG_LENGTH); |
| 125 | |
} |
| 126 | |
else |
| 127 | |
{ |
| 128 | 998 | logger.info("Unable to find ID3v1 tag to deleteField"); |
| 129 | |
} |
| 130 | 1239 | } |
| 131 | |
|
| 132 | |
|
| 133 | |
} |