2
* Entagged Audio Tag library
3
* Copyright (c) 2003-2005 Rapha�l Slinckx <raphael@slinckx.net>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
package org.jaudiotagger.tag.vorbiscomment;
21
import org.jaudiotagger.audio.generic.AbstractTag;
22
import org.jaudiotagger.audio.ogg.util.VorbisHeader;
23
import org.jaudiotagger.logging.ErrorMessage;
24
import org.jaudiotagger.tag.FieldDataInvalidException;
25
import org.jaudiotagger.tag.FieldKey;
26
import org.jaudiotagger.tag.KeyNotFoundException;
27
import org.jaudiotagger.tag.TagField;
28
import org.jaudiotagger.tag.datatype.Artwork;
29
import static org.jaudiotagger.tag.vorbiscomment.VorbisCommentFieldKey.ALBUM;
30
import static org.jaudiotagger.tag.vorbiscomment.VorbisCommentFieldKey.VENDOR;
31
import org.jaudiotagger.tag.vorbiscomment.util.Base64Coder;
33
import java.util.ArrayList;
34
import java.util.EnumMap;
35
import java.util.List;
38
* This is the logical representation of Vorbis Comment Data
40
public class VorbisCommentTag extends AbstractTag
42
private static EnumMap<FieldKey, VorbisCommentFieldKey> tagFieldToOggField = new EnumMap<FieldKey, VorbisCommentFieldKey>(FieldKey.class);
46
tagFieldToOggField.put(FieldKey.ARTIST, VorbisCommentFieldKey.ARTIST);
47
tagFieldToOggField.put(FieldKey.ALBUM, VorbisCommentFieldKey.ALBUM);
48
tagFieldToOggField.put(FieldKey.TITLE, VorbisCommentFieldKey.TITLE);
49
tagFieldToOggField.put(FieldKey.TRACK, VorbisCommentFieldKey.TRACKNUMBER);
50
tagFieldToOggField.put(FieldKey.YEAR, VorbisCommentFieldKey.DATE);
51
tagFieldToOggField.put(FieldKey.GENRE, VorbisCommentFieldKey.GENRE);
52
tagFieldToOggField.put(FieldKey.COMMENT, VorbisCommentFieldKey.COMMENT);
53
tagFieldToOggField.put(FieldKey.ALBUM_ARTIST, VorbisCommentFieldKey.ALBUMARTIST);
54
tagFieldToOggField.put(FieldKey.COMPOSER, VorbisCommentFieldKey.COMPOSER);
55
tagFieldToOggField.put(FieldKey.GROUPING, VorbisCommentFieldKey.GROUPING);
56
tagFieldToOggField.put(FieldKey.DISC_NO, VorbisCommentFieldKey.DISCNUMBER);
57
tagFieldToOggField.put(FieldKey.BPM, VorbisCommentFieldKey.BPM);
58
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_ARTISTID, VorbisCommentFieldKey.MUSICBRAINZ_ARTISTID);
59
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_RELEASEID, VorbisCommentFieldKey.MUSICBRAINZ_ALBUMID);
60
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_RELEASEARTISTID, VorbisCommentFieldKey.MUSICBRAINZ_ALBUMARTISTID);
61
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_TRACK_ID, VorbisCommentFieldKey.MUSICBRAINZ_TRACKID);
62
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_DISC_ID, VorbisCommentFieldKey.MUSICBRAINZ_DISCID);
63
tagFieldToOggField.put(FieldKey.MUSICIP_ID, VorbisCommentFieldKey.MUSICIP_PUID);
64
tagFieldToOggField.put(FieldKey.AMAZON_ID, VorbisCommentFieldKey.ASIN);
65
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_RELEASE_STATUS, VorbisCommentFieldKey.MUSICBRAINZ_ALBUMSTATUS);
66
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_RELEASE_TYPE, VorbisCommentFieldKey.MUSICBRAINZ_ALBUMTYPE);
67
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_RELEASE_COUNTRY, VorbisCommentFieldKey.RELEASECOUNTRY);
68
tagFieldToOggField.put(FieldKey.LYRICS, VorbisCommentFieldKey.LYRICS);
69
tagFieldToOggField.put(FieldKey.IS_COMPILATION, VorbisCommentFieldKey.COMPILATION);
70
tagFieldToOggField.put(FieldKey.ARTIST_SORT, VorbisCommentFieldKey.ARTISTSORT);
71
tagFieldToOggField.put(FieldKey.ALBUM_ARTIST_SORT, VorbisCommentFieldKey.ALBUMARTISTSORT);
72
tagFieldToOggField.put(FieldKey.ALBUM_SORT, VorbisCommentFieldKey.ALBUMSORT);
73
tagFieldToOggField.put(FieldKey.TITLE_SORT, VorbisCommentFieldKey.TITLESORT);
74
tagFieldToOggField.put(FieldKey.COMPOSER_SORT, VorbisCommentFieldKey.COMPOSERSORT);
75
tagFieldToOggField.put(FieldKey.ENCODER, VorbisCommentFieldKey.VENDOR); //Known as vendor in VorbisComment
76
tagFieldToOggField.put(FieldKey.ISRC, VorbisCommentFieldKey.ISRC);
77
tagFieldToOggField.put(FieldKey.BARCODE, VorbisCommentFieldKey.BARCODE);
78
tagFieldToOggField.put(FieldKey.CATALOG_NO, VorbisCommentFieldKey.CATALOGNUMBER);
79
tagFieldToOggField.put(FieldKey.RECORD_LABEL, VorbisCommentFieldKey.LABEL);
80
tagFieldToOggField.put(FieldKey.LYRICIST, VorbisCommentFieldKey.LYRICIST);
81
tagFieldToOggField.put(FieldKey.CONDUCTOR, VorbisCommentFieldKey.CONDUCTOR);
82
tagFieldToOggField.put(FieldKey.REMIXER, VorbisCommentFieldKey.REMIXER);
83
tagFieldToOggField.put(FieldKey.MOOD, VorbisCommentFieldKey.MOOD);
84
tagFieldToOggField.put(FieldKey.MEDIA, VorbisCommentFieldKey.MEDIA);
85
tagFieldToOggField.put(FieldKey.URL_DISCOGS_ARTIST_SITE, VorbisCommentFieldKey.URL_DISCOGS_ARTIST_SITE);
86
tagFieldToOggField.put(FieldKey.URL_DISCOGS_RELEASE_SITE, VorbisCommentFieldKey.URL_DISCOGS_RELEASE_SITE);
87
tagFieldToOggField.put(FieldKey.URL_OFFICIAL_ARTIST_SITE, VorbisCommentFieldKey.URL_OFFICIAL_ARTIST_SITE);
88
tagFieldToOggField.put(FieldKey.URL_OFFICIAL_RELEASE_SITE, VorbisCommentFieldKey.URL_OFFICIAL_RELEASE_SITE);
89
tagFieldToOggField.put(FieldKey.URL_WIKIPEDIA_ARTIST_SITE, VorbisCommentFieldKey.URL_WIKIPEDIA_ARTIST_SITE);
90
tagFieldToOggField.put(FieldKey.URL_WIKIPEDIA_RELEASE_SITE, VorbisCommentFieldKey.URL_WIKIPEDIA_RELEASE_SITE);
91
tagFieldToOggField.put(FieldKey.LANGUAGE, VorbisCommentFieldKey.LANGUAGE);
92
tagFieldToOggField.put(FieldKey.KEY, VorbisCommentFieldKey.KEY);
93
tagFieldToOggField.put(FieldKey.URL_LYRICS_SITE, VorbisCommentFieldKey.URL_LYRICS_SITE);
94
tagFieldToOggField.put(FieldKey.TRACK_TOTAL, VorbisCommentFieldKey.TRACKTOTAL);
95
tagFieldToOggField.put(FieldKey.DISC_TOTAL, VorbisCommentFieldKey.DISCTOTAL);
99
//This is the vendor string that will be written if no other is supplied. Should be the name of the software
100
//that actually encoded the file in the first place.
101
public static final String DEFAULT_VENDOR = "jaudiotagger";
104
* Only used within Package, hidden because it doesnt set Vendor
105
* which should be done when created by end user
113
* Use to construct a new tag properly initialized
117
public static VorbisCommentTag createNewTag()
119
VorbisCommentTag tag = new VorbisCommentTag();
120
tag.setVendor(DEFAULT_VENDOR);
124
private String getAlbumId()
130
* @return the vendor, generically known as the encoder
132
public String getVendor()
134
return getFirst(VENDOR.name());
138
* Set the vendor, known as the encoder generally
140
* We dont want this to be blank, when written to file this field is written to a different location
141
* to all other fields but user of library can just reat it as another field
145
public void setVendor(String vendor)
149
vendor = DEFAULT_VENDOR;
151
super.setField(new VorbisCommentTagField(VENDOR.name(), vendor));
154
protected boolean isAllowedEncoding(String enc)
156
return enc.equals(VorbisHeader.CHARSET_UTF_8);
159
public String toString()
161
return "OGG " + super.toString();
165
* Create Tag Field using generic key
168
public TagField createField(FieldKey genericKey, String value) throws KeyNotFoundException,FieldDataInvalidException
170
if (genericKey == null)
172
throw new KeyNotFoundException();
174
return createTagField(tagFieldToOggField.get(genericKey), value);
178
* Create Tag Field using ogg key
180
* @param vorbisCommentFieldKey
183
* @throws org.jaudiotagger.tag.KeyNotFoundException
184
* @throws org.jaudiotagger.tag.FieldDataInvalidException
186
public TagField createTagField(VorbisCommentFieldKey vorbisCommentFieldKey, String value) throws KeyNotFoundException,FieldDataInvalidException
190
throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
192
if (vorbisCommentFieldKey == null)
194
throw new KeyNotFoundException();
197
return new VorbisCommentTagField(vorbisCommentFieldKey.name(), value);
201
* Create Tag Field using ogg key
203
* This method is provided to allow you to create key of any value because VorbisComment allows
206
* @param vorbisCommentFieldKey
210
public TagField createTagField(String vorbisCommentFieldKey, String value)
214
throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
216
return new VorbisCommentTagField(vorbisCommentFieldKey, value);
220
* Maps the generic key to the ogg key and return the list of values for this field
225
public List<TagField> getFields(FieldKey genericKey) throws KeyNotFoundException
227
VorbisCommentFieldKey vorbisCommentFieldKey = tagFieldToOggField.get(genericKey);
228
if (vorbisCommentFieldKey == null)
230
throw new KeyNotFoundException();
232
return super.get(vorbisCommentFieldKey.name());
236
* Retrieve the first value that exists for this vorbis comment key
238
* @param vorbisCommentKey
240
* @throws org.jaudiotagger.tag.KeyNotFoundException
242
public List<TagField> get(VorbisCommentFieldKey vorbisCommentKey) throws KeyNotFoundException
244
if (vorbisCommentKey == null)
246
throw new KeyNotFoundException();
248
return super.get(vorbisCommentKey.name());
252
* Retrieve the first value that exists for this generic key
257
public String getFirst(FieldKey genericKey) throws KeyNotFoundException
259
VorbisCommentFieldKey vorbisCommentFieldKey = tagFieldToOggField.get(genericKey);
260
if (vorbisCommentFieldKey == null)
262
throw new KeyNotFoundException();
264
return super.getFirst(vorbisCommentFieldKey.name());
268
* Retrieve the first value that exists for this vorbis comment key
270
* @param vorbisCommentKey
272
* @throws org.jaudiotagger.tag.KeyNotFoundException
274
public String getFirst(VorbisCommentFieldKey vorbisCommentKey) throws KeyNotFoundException
276
if (vorbisCommentKey == null)
278
throw new KeyNotFoundException();
280
return super.getFirst(vorbisCommentKey.name());
284
* Delete fields with this generic key
288
public void deleteField(FieldKey genericKey) throws KeyNotFoundException
290
if (genericKey == null)
292
throw new KeyNotFoundException();
294
VorbisCommentFieldKey vorbisCommentFieldKey = tagFieldToOggField.get(genericKey);
295
deleteTagField(vorbisCommentFieldKey);
299
* Delete fields with this vorbisCommentFieldKey
301
* @param vorbisCommentFieldKey
302
* @throws org.jaudiotagger.tag.KeyNotFoundException
304
public void deleteTagField(VorbisCommentFieldKey vorbisCommentFieldKey) throws KeyNotFoundException
306
if (vorbisCommentFieldKey == null)
308
throw new KeyNotFoundException();
310
super.deleteField(vorbisCommentFieldKey.name());
314
* Create artwork field
316
* Actually create two fields , the data field and the mimetype
318
* @param data raw image data
319
* @param mimeType mimeType of data
321
* TODO could possibly work out mimetype from data, but unlike mp4 there is nothing to restrict to only png
325
public void setArtworkField(byte[] data, String mimeType)
327
char[] testdata = Base64Coder.encode(data);
328
String base64image = new String(testdata);
329
VorbisCommentTagField dataField = new VorbisCommentTagField(VorbisCommentFieldKey.COVERART.name(), base64image);
330
VorbisCommentTagField mimeField = new VorbisCommentTagField(VorbisCommentFieldKey.COVERARTMIME.name(), mimeType);
338
* Retrieve artwork raw data
342
public byte[] getArtworkBinaryData()
344
String base64data = this.getFirst(VorbisCommentFieldKey.COVERART);
345
byte[] rawdata = Base64Coder.decode(base64data.toCharArray());
352
public String getArtworkMimeType()
354
return this.getFirst(VorbisCommentFieldKey.COVERARTMIME);
360
* <p>Overridden because check for size of one because there is always a vendor tag unless just
361
* created an empty vorbis tag as part of flac tag in which case size could be zero
363
* @see org.jaudiotagger.tag.Tag#isEmpty()
365
public boolean isEmpty()
367
return fields.size() <= 1;
373
* <p>Overidden because there can only be one vendor set
377
public void addField(TagField field)
379
if (field.getId().equals(VorbisCommentFieldKey.VENDOR.name()))
381
super.setField(field);
385
super.addField(field);
389
public TagField getFirstField(FieldKey genericKey) throws KeyNotFoundException
391
if (genericKey == null)
393
throw new KeyNotFoundException();
395
return getFirstField(tagFieldToOggField.get(genericKey).name());
398
public List<Artwork> getArtworkList()
400
List<Artwork> artworkList = new ArrayList<Artwork>(1);
402
if(getArtworkBinaryData()!=null & getArtworkBinaryData().length>0)
404
Artwork artwork=new Artwork();
405
artwork.setMimeType(getArtworkMimeType());
406
artwork.setBinaryData(getArtworkBinaryData());
407
artworkList.add(artwork);
413
* Create artwork field
415
* Not supported because reuire two fields to be created use
418
public TagField createField(Artwork artwork) throws FieldDataInvalidException
420
throw new UnsupportedOperationException("Please use setField instead");
424
* Create artwork field
426
* Actually sets two fields
431
public void setField(Artwork artwork) throws FieldDataInvalidException
433
char[] testdata = Base64Coder.encode(artwork.getBinaryData());
434
String base64image = new String(testdata);
435
TagField imageTagField = createTagField(VorbisCommentFieldKey.COVERART, base64image);
436
TagField imageTypeField = createTagField(VorbisCommentFieldKey.COVERARTMIME, artwork.getMimeType());
438
this.setField(imageTagField);
439
this.setField(imageTypeField);
443
* Delete all instance of artwork Field
445
* @throws KeyNotFoundException
447
public void deleteArtworkField() throws KeyNotFoundException
449
this.deleteTagField(VorbisCommentFieldKey.COVERART);
450
this.deleteTagField(VorbisCommentFieldKey.COVERARTMIME);
2
* Entagged Audio Tag library
3
* Copyright (c) 2003-2005 Rapha�l Slinckx <raphael@slinckx.net>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
package org.jaudiotagger.tag.vorbiscomment;
21
import org.jaudiotagger.audio.flac.metadatablock.MetadataBlockDataPicture;
22
import org.jaudiotagger.audio.generic.AbstractTag;
23
import org.jaudiotagger.audio.generic.Utils;
24
import org.jaudiotagger.audio.ogg.util.VorbisHeader;
25
import org.jaudiotagger.logging.ErrorMessage;
26
import org.jaudiotagger.tag.*;
27
import org.jaudiotagger.tag.datatype.Artwork;
29
import static org.jaudiotagger.tag.vorbiscomment.VorbisCommentFieldKey.VENDOR;
31
import org.jaudiotagger.tag.id3.valuepair.TextEncoding;
32
import org.jaudiotagger.tag.reference.Tagger;
33
import org.jaudiotagger.tag.vorbiscomment.util.Base64Coder;
35
import java.awt.image.BufferedImage;
36
import java.io.IOException;
37
import java.io.UnsupportedEncodingException;
38
import java.nio.ByteBuffer;
39
import java.util.ArrayList;
40
import java.util.EnumMap;
41
import java.util.EnumSet;
42
import java.util.List;
45
* This is the logical representation of Vorbis Comment Data
47
public class VorbisCommentTag extends AbstractTag
49
private static EnumMap<FieldKey, VorbisCommentFieldKey> tagFieldToOggField = new EnumMap<FieldKey, VorbisCommentFieldKey>(FieldKey.class);
53
tagFieldToOggField.put(FieldKey.ALBUM, VorbisCommentFieldKey.ALBUM);
54
tagFieldToOggField.put(FieldKey.ALBUM_ARTIST, VorbisCommentFieldKey.ALBUMARTIST);
55
tagFieldToOggField.put(FieldKey.ALBUM_ARTIST_SORT, VorbisCommentFieldKey.ALBUMARTISTSORT);
56
tagFieldToOggField.put(FieldKey.ALBUM_SORT, VorbisCommentFieldKey.ALBUMSORT);
57
tagFieldToOggField.put(FieldKey.ARTIST, VorbisCommentFieldKey.ARTIST);
58
tagFieldToOggField.put(FieldKey.AMAZON_ID, VorbisCommentFieldKey.ASIN);
59
tagFieldToOggField.put(FieldKey.ARTIST_SORT, VorbisCommentFieldKey.ARTISTSORT);
60
tagFieldToOggField.put(FieldKey.BARCODE, VorbisCommentFieldKey.BARCODE);
61
tagFieldToOggField.put(FieldKey.BPM, VorbisCommentFieldKey.BPM);
62
tagFieldToOggField.put(FieldKey.CATALOG_NO, VorbisCommentFieldKey.CATALOGNUMBER);
63
tagFieldToOggField.put(FieldKey.COMMENT, VorbisCommentFieldKey.COMMENT);
64
tagFieldToOggField.put(FieldKey.COMPOSER, VorbisCommentFieldKey.COMPOSER);
65
tagFieldToOggField.put(FieldKey.COMPOSER_SORT, VorbisCommentFieldKey.COMPOSERSORT);
66
tagFieldToOggField.put(FieldKey.CONDUCTOR, VorbisCommentFieldKey.CONDUCTOR);
67
tagFieldToOggField.put(FieldKey.COVER_ART, VorbisCommentFieldKey.METADATA_BLOCK_PICTURE);
68
tagFieldToOggField.put(FieldKey.CUSTOM1, VorbisCommentFieldKey.CUSTOM1);
69
tagFieldToOggField.put(FieldKey.CUSTOM2, VorbisCommentFieldKey.CUSTOM2);
70
tagFieldToOggField.put(FieldKey.CUSTOM3, VorbisCommentFieldKey.CUSTOM3);
71
tagFieldToOggField.put(FieldKey.CUSTOM4, VorbisCommentFieldKey.CUSTOM4);
72
tagFieldToOggField.put(FieldKey.CUSTOM5, VorbisCommentFieldKey.CUSTOM5);
73
tagFieldToOggField.put(FieldKey.DISC_NO, VorbisCommentFieldKey.DISCNUMBER);
74
tagFieldToOggField.put(FieldKey.DISC_TOTAL, VorbisCommentFieldKey.DISCTOTAL);
75
tagFieldToOggField.put(FieldKey.ENCODER, VorbisCommentFieldKey.VENDOR); //Known as vendor in VorbisComment
76
tagFieldToOggField.put(FieldKey.FBPM, VorbisCommentFieldKey.FBPM);
77
tagFieldToOggField.put(FieldKey.GENRE, VorbisCommentFieldKey.GENRE);
78
tagFieldToOggField.put(FieldKey.GROUPING, VorbisCommentFieldKey.GROUPING);
79
tagFieldToOggField.put(FieldKey.ISRC, VorbisCommentFieldKey.ISRC);
80
tagFieldToOggField.put(FieldKey.IS_COMPILATION, VorbisCommentFieldKey.COMPILATION);
81
tagFieldToOggField.put(FieldKey.KEY, VorbisCommentFieldKey.KEY);
82
tagFieldToOggField.put(FieldKey.LANGUAGE, VorbisCommentFieldKey.LANGUAGE);
83
tagFieldToOggField.put(FieldKey.LYRICIST, VorbisCommentFieldKey.LYRICIST);
84
tagFieldToOggField.put(FieldKey.LYRICS, VorbisCommentFieldKey.LYRICS);
85
tagFieldToOggField.put(FieldKey.MEDIA, VorbisCommentFieldKey.MEDIA);
86
tagFieldToOggField.put(FieldKey.MOOD, VorbisCommentFieldKey.MOOD);
87
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_ARTISTID, VorbisCommentFieldKey.MUSICBRAINZ_ARTISTID);
88
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_DISC_ID, VorbisCommentFieldKey.MUSICBRAINZ_DISCID);
89
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_RELEASEARTISTID, VorbisCommentFieldKey.MUSICBRAINZ_ALBUMARTISTID);
90
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_RELEASEID, VorbisCommentFieldKey.MUSICBRAINZ_ALBUMID);
91
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_RELEASE_GROUP_ID, VorbisCommentFieldKey.MUSICBRAINZ_RELEASEGROUPID);
92
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_RELEASE_COUNTRY, VorbisCommentFieldKey.RELEASECOUNTRY);
93
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_RELEASE_STATUS, VorbisCommentFieldKey.MUSICBRAINZ_ALBUMSTATUS);
94
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_RELEASE_TYPE, VorbisCommentFieldKey.MUSICBRAINZ_ALBUMTYPE);
95
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_TRACK_ID, VorbisCommentFieldKey.MUSICBRAINZ_TRACKID);
96
tagFieldToOggField.put(FieldKey.MUSICBRAINZ_WORK_ID, VorbisCommentFieldKey.MUSICBRAINZ_WORKID);
97
tagFieldToOggField.put(FieldKey.OCCASION, VorbisCommentFieldKey.OCCASION);
98
tagFieldToOggField.put(FieldKey.ORIGINAL_ALBUM, VorbisCommentFieldKey.ORIGINAL_ALBUM);
99
tagFieldToOggField.put(FieldKey.ORIGINAL_ARTIST, VorbisCommentFieldKey.ORIGINAL_ARTIST);
100
tagFieldToOggField.put(FieldKey.ORIGINAL_LYRICIST, VorbisCommentFieldKey.ORIGINAL_LYRICIST);
101
tagFieldToOggField.put(FieldKey.ORIGINAL_YEAR, VorbisCommentFieldKey.ORIGINAL_YEAR);
102
tagFieldToOggField.put(FieldKey.MUSICIP_ID, VorbisCommentFieldKey.MUSICIP_PUID);
103
tagFieldToOggField.put(FieldKey.QUALITY, VorbisCommentFieldKey.QUALITY);
104
tagFieldToOggField.put(FieldKey.RATING, VorbisCommentFieldKey.RATING);
105
tagFieldToOggField.put(FieldKey.RECORD_LABEL, VorbisCommentFieldKey.LABEL);
106
tagFieldToOggField.put(FieldKey.REMIXER, VorbisCommentFieldKey.REMIXER);
107
tagFieldToOggField.put(FieldKey.TAGS, VorbisCommentFieldKey.TAGS);
108
tagFieldToOggField.put(FieldKey.SCRIPT, VorbisCommentFieldKey.SCRIPT);
109
tagFieldToOggField.put(FieldKey.TEMPO, VorbisCommentFieldKey.TEMPO);
110
tagFieldToOggField.put(FieldKey.TITLE, VorbisCommentFieldKey.TITLE);
111
tagFieldToOggField.put(FieldKey.TITLE_SORT, VorbisCommentFieldKey.TITLESORT);
112
tagFieldToOggField.put(FieldKey.TRACK, VorbisCommentFieldKey.TRACKNUMBER);
113
tagFieldToOggField.put(FieldKey.TRACK_TOTAL, VorbisCommentFieldKey.TRACKTOTAL);
114
tagFieldToOggField.put(FieldKey.URL_DISCOGS_ARTIST_SITE, VorbisCommentFieldKey.URL_DISCOGS_ARTIST_SITE);
115
tagFieldToOggField.put(FieldKey.URL_DISCOGS_RELEASE_SITE, VorbisCommentFieldKey.URL_DISCOGS_RELEASE_SITE);
116
tagFieldToOggField.put(FieldKey.URL_LYRICS_SITE, VorbisCommentFieldKey.URL_LYRICS_SITE);
117
tagFieldToOggField.put(FieldKey.URL_OFFICIAL_ARTIST_SITE, VorbisCommentFieldKey.URL_OFFICIAL_ARTIST_SITE);
118
tagFieldToOggField.put(FieldKey.URL_OFFICIAL_RELEASE_SITE, VorbisCommentFieldKey.URL_OFFICIAL_RELEASE_SITE);
119
tagFieldToOggField.put(FieldKey.URL_WIKIPEDIA_ARTIST_SITE, VorbisCommentFieldKey.URL_WIKIPEDIA_ARTIST_SITE);
120
tagFieldToOggField.put(FieldKey.URL_WIKIPEDIA_RELEASE_SITE, VorbisCommentFieldKey.URL_WIKIPEDIA_RELEASE_SITE);
121
tagFieldToOggField.put(FieldKey.YEAR, VorbisCommentFieldKey.DATE);
123
tagFieldToOggField.put(FieldKey.ENGINEER, VorbisCommentFieldKey.ENGINEER);
124
tagFieldToOggField.put(FieldKey.PRODUCER, VorbisCommentFieldKey.PRODUCER);
125
tagFieldToOggField.put(FieldKey.DJMIXER, VorbisCommentFieldKey.DJMIXER);
126
tagFieldToOggField.put(FieldKey.MIXER, VorbisCommentFieldKey.MIXER);
127
tagFieldToOggField.put(FieldKey.ARRANGER, VorbisCommentFieldKey.ARRANGER);
130
//This is the vendor string that will be written if no other is supplied. Should be the name of the software
131
//that actually encoded the file in the first place.
132
public static final String DEFAULT_VENDOR = "jaudiotagger";
135
* Only used within Package, hidden because it doesnt set Vendor
136
* which should be done when created by end user
144
* Use to construct a new tag properly initialized
148
public static VorbisCommentTag createNewTag()
150
VorbisCommentTag tag = new VorbisCommentTag();
151
tag.setVendor(DEFAULT_VENDOR);
156
* @return the vendor, generically known as the encoder
158
public String getVendor()
160
return getFirst(VENDOR.getFieldName());
164
* Set the vendor, known as the encoder generally
166
* We dont want this to be blank, when written to file this field is written to a different location
167
* to all other fields but user of library can just reat it as another field
171
public void setVendor(String vendor)
175
vendor = DEFAULT_VENDOR;
177
super.setField(new VorbisCommentTagField(VENDOR.getFieldName(), vendor));
180
protected boolean isAllowedEncoding(String enc)
182
return enc.equals(VorbisHeader.CHARSET_UTF_8);
185
public String toString()
187
return "OGG " + super.toString();
191
* Create Tag Field using generic key
194
public TagField createField(FieldKey genericKey, String value) throws KeyNotFoundException,FieldDataInvalidException
196
if (genericKey == null)
198
throw new KeyNotFoundException();
200
return createField(tagFieldToOggField.get(genericKey), value);
204
* Create Tag Field using ogg key
206
* @param vorbisCommentFieldKey
209
* @throws org.jaudiotagger.tag.KeyNotFoundException
210
* @throws org.jaudiotagger.tag.FieldDataInvalidException
212
public TagField createField(VorbisCommentFieldKey vorbisCommentFieldKey, String value) throws KeyNotFoundException,FieldDataInvalidException
216
throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
218
if (vorbisCommentFieldKey == null)
220
throw new KeyNotFoundException();
223
return new VorbisCommentTagField(vorbisCommentFieldKey.getFieldName(), value);
227
* Create Tag Field using ogg key
229
* This method is provided to allow you to create key of any value because VorbisComment allows
232
* @param vorbisCommentFieldKey
236
public TagField createField(String vorbisCommentFieldKey, String value)
240
throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
242
return new VorbisCommentTagField(vorbisCommentFieldKey, value);
246
* Maps the generic key to the ogg key and return the list of values for this field
251
public List<TagField> getFields(FieldKey genericKey) throws KeyNotFoundException
253
VorbisCommentFieldKey vorbisCommentFieldKey = tagFieldToOggField.get(genericKey);
254
if (vorbisCommentFieldKey == null)
256
throw new KeyNotFoundException();
258
return super.getFields(vorbisCommentFieldKey.getFieldName());
262
* Retrieve the first value that exists for this vorbis comment key
264
* @param vorbisCommentKey
266
* @throws org.jaudiotagger.tag.KeyNotFoundException
268
public List<TagField> get(VorbisCommentFieldKey vorbisCommentKey) throws KeyNotFoundException
270
if (vorbisCommentKey == null)
272
throw new KeyNotFoundException();
274
return super.getFields(vorbisCommentKey.getFieldName());
277
public String getValue(FieldKey genericKey,int index) throws KeyNotFoundException
279
VorbisCommentFieldKey vorbisCommentFieldKey = tagFieldToOggField.get(genericKey);
280
if (vorbisCommentFieldKey == null)
282
throw new KeyNotFoundException();
284
return super.getItem(vorbisCommentFieldKey.getFieldName(),index);
288
* Retrieve the first value that exists for this vorbis comment key
290
* @param vorbisCommentKey
292
* @throws org.jaudiotagger.tag.KeyNotFoundException
294
public String getFirst(VorbisCommentFieldKey vorbisCommentKey) throws KeyNotFoundException
296
if (vorbisCommentKey == null)
298
throw new KeyNotFoundException();
300
return super.getFirst(vorbisCommentKey.getFieldName());
304
* Delete fields with this generic key
308
public void deleteField(FieldKey genericKey) throws KeyNotFoundException
310
if (genericKey == null)
312
throw new KeyNotFoundException();
314
VorbisCommentFieldKey vorbisCommentFieldKey = tagFieldToOggField.get(genericKey);
315
deleteField(vorbisCommentFieldKey);
319
* Delete fields with this vorbisCommentFieldKey
321
* @param vorbisCommentFieldKey
322
* @throws org.jaudiotagger.tag.KeyNotFoundException
324
public void deleteField(VorbisCommentFieldKey vorbisCommentFieldKey) throws KeyNotFoundException
326
if (vorbisCommentFieldKey == null)
328
throw new KeyNotFoundException();
330
super.deleteField(vorbisCommentFieldKey.getFieldName());
336
* Retrieve artwork raw data when using the deprecated COVERART format
340
public byte[] getArtworkBinaryData()
342
String base64data = this.getFirst(VorbisCommentFieldKey.COVERART);
343
byte[] rawdata = Base64Coder.decode(base64data.toCharArray());
348
* Retrieve artwork mimeType when using deprecated COVERART format
352
public String getArtworkMimeType()
354
return this.getFirst(VorbisCommentFieldKey.COVERARTMIME);
360
* <p>Overridden because check for size of one because there is always a vendor tag unless just
361
* created an empty vorbis tag as part of flac tag in which case size could be zero
363
* @see org.jaudiotagger.tag.Tag#isEmpty()
365
public boolean isEmpty()
367
return fields.size() <= 1;
373
* <p>Overidden because there can only be one vendor set
377
public void addField(TagField field)
379
if (field.getId().equals(VorbisCommentFieldKey.VENDOR.getFieldName()))
381
super.setField(field);
385
super.addField(field);
389
public TagField getFirstField(FieldKey genericKey) throws KeyNotFoundException
391
if (genericKey == null)
393
throw new KeyNotFoundException();
395
return getFirstField(tagFieldToOggField.get(genericKey).getFieldName());
400
* @return list of artwork images
402
public List<Artwork> getArtworkList()
404
List<Artwork> artworkList = new ArrayList<Artwork>(1);
407
if(getArtworkBinaryData()!=null & getArtworkBinaryData().length>0)
409
Artwork artwork=new Artwork();
410
artwork.setMimeType(getArtworkMimeType());
411
artwork.setBinaryData(getArtworkBinaryData());
412
artworkList.add(artwork);
415
//New Format (Supports Multiple Images)
416
List<TagField> metadataBlockPics = this.get(VorbisCommentFieldKey.METADATA_BLOCK_PICTURE);
417
for(TagField tagField:metadataBlockPics)
422
byte[] imageBinaryData = Base64Coder.decode(((TagTextField)tagField).getContent());
423
MetadataBlockDataPicture coverArt = new MetadataBlockDataPicture(ByteBuffer.wrap(imageBinaryData));
424
Artwork artwork=Artwork.createArtworkFromMetadataBlockDataPicture(coverArt);
425
artworkList.add(artwork);
427
catch(IOException ioe)
429
throw new RuntimeException(ioe);
431
catch(InvalidFrameException ife)
433
throw new RuntimeException(ife);
441
* Create MetadataBlockPicture field, this is the preferred way of storing artwork in VorbisComment tag now but
442
* has to be base encoded to be stored in VorbisComment
444
* @return MetadataBlockDataPicture
446
private MetadataBlockDataPicture createMetadataBlockDataPicture(Artwork artwork) throws FieldDataInvalidException
448
if(artwork.isLinked())
450
return new MetadataBlockDataPicture(
451
Utils.getDefaultBytes(artwork.getImageUrl(), TextEncoding.CHARSET_ISO_8859_1),
452
artwork.getPictureType(),
453
MetadataBlockDataPicture.IMAGE_IS_URL,
465
image = artwork.getImage();
467
catch(IOException ioe)
469
throw new FieldDataInvalidException("Unable to create MetadataBlockDataPicture from buffered:"+ioe.getMessage());
472
return new MetadataBlockDataPicture(artwork.getBinaryData(),
473
artwork.getPictureType(),
474
artwork.getMimeType(),
475
artwork.getDescription(),
484
* Create Artwork field
488
* @throws FieldDataInvalidException
490
public TagField createField(Artwork artwork) throws FieldDataInvalidException
494
char[] testdata = Base64Coder.encode(createMetadataBlockDataPicture(artwork).getRawContent());
495
String base64image = new String(testdata);
496
TagField imageTagField = createField(VorbisCommentFieldKey.METADATA_BLOCK_PICTURE, base64image);
497
return imageTagField;
499
catch(UnsupportedEncodingException uee)
501
throw new RuntimeException(uee);
506
* Create and set artwork field
511
public void setField(Artwork artwork) throws FieldDataInvalidException
514
this.setField(createField(artwork));
516
//If worked okay above then that should be first artwork and if we still had old coverart format
517
//that should be removed
518
if(this.getFirst(VorbisCommentFieldKey.COVERART).length()>0)
520
this.deleteField(VorbisCommentFieldKey.COVERART);
521
this.deleteField(VorbisCommentFieldKey.COVERARTMIME);
529
* @throws FieldDataInvalidException
531
public void addField(Artwork artwork) throws FieldDataInvalidException
533
this.addField(createField(artwork));
537
* Create artwork field using the non-standard COVERART tag
540
* Actually create two fields , the data field and the mimetype. Its is not recommended that you use this
543
* @param data raw image data
544
* @param mimeType mimeType of data
549
public void setArtworkField(byte[] data, String mimeType)
551
char[] testdata = Base64Coder.encode(data);
552
String base64image = new String(testdata);
553
VorbisCommentTagField dataField = new VorbisCommentTagField(VorbisCommentFieldKey.COVERART.getFieldName(), base64image);
554
VorbisCommentTagField mimeField = new VorbisCommentTagField(VorbisCommentFieldKey.COVERARTMIME.getFieldName(), mimeType);
562
* Create and set field with name of vorbisCommentkey
564
* @param vorbisCommentKey
566
* @throws KeyNotFoundException
567
* @throws FieldDataInvalidException
569
public void setField(String vorbisCommentKey, String value) throws KeyNotFoundException, FieldDataInvalidException
571
TagField tagfield = createField(vorbisCommentKey,value);
576
* Create and add field with name of vorbisCommentkey
577
* @param vorbisCommentKey
579
* @throws KeyNotFoundException
580
* @throws FieldDataInvalidException
582
public void addField(String vorbisCommentKey, String value) throws KeyNotFoundException, FieldDataInvalidException
584
TagField tagfield = createField(vorbisCommentKey,value);
589
* Delete all instance of artwork Field
591
* @throws KeyNotFoundException
593
public void deleteArtworkField() throws KeyNotFoundException
596
this.deleteField(VorbisCommentFieldKey.METADATA_BLOCK_PICTURE);
599
this.deleteField(VorbisCommentFieldKey.COVERART);
600
this.deleteField(VorbisCommentFieldKey.COVERARTMIME);