[Schmitzm-commits] r2364 - in trunk/schmitzm-mp3/src/main: java/de/schmitzm/mp3/id3 java/de/schmitzm/mp3/id3/gui resources/de/schmitzm/mp3/id3/resource/locales
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Fri Jul 19 11:12:55 CEST 2013
Author: mojays
Date: 2013-07-19 11:12:55 +0200 (Fri, 19 Jul 2013)
New Revision: 2364
Added:
trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/AlbumIsSamplerInformationFrame.java
Modified:
trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/AudioCDInformationFrame.java
trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagField.java
trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagUtil.java
trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagPanel.java
trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagV2Panel.java
trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle.properties
trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle_de.properties
Log:
New field "Album is sampler" for ID3v2
Added: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/AlbumIsSamplerInformationFrame.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/AlbumIsSamplerInformationFrame.java (rev 0)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/AlbumIsSamplerInformationFrame.java 2013-07-19 09:12:55 UTC (rev 2364)
@@ -0,0 +1,117 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.mp3.id3;
+
+import org.blinkenlights.jid3.ID3Exception;
+import org.blinkenlights.jid3.v2.TXXXTextInformationID3V2Frame;
+
+/**
+ * User defined frame which is used to indicate that the album is a
+ * sampler (contains multiple artists).
+ * Instead if the super class {@link TXXXTextInformationID3V2Frame} this
+ * implementation allows {@code null} information!
+ * @author Martin O.J. Schmitz
+ */
+public class AlbumIsSamplerInformationFrame extends TXXXTextInformationID3V2Frame {
+ /** Static ID used as description for the frame. */
+ public static final String FRAME_ID = "ALBUM_SAMPLER";
+ /** Static identifier used to indicate empty information. */
+ public static final String EMPTY_INFO = "<ALBUM_SAMPLER empty>";
+
+
+ /**
+ * Creates a frame.
+ */
+ public AlbumIsSamplerInformationFrame(boolean albumSampler) throws ID3Exception {
+ super(FRAME_ID, EMPTY_INFO);
+ setAlbumSampler(albumSampler);
+ }
+
+ /**
+ * Creates an empty frame.
+ */
+ public AlbumIsSamplerInformationFrame() throws ID3Exception {
+ this(true);
+ }
+
+ /**
+ * Creates a frame.
+ */
+ public AlbumIsSamplerInformationFrame(TXXXTextInformationID3V2Frame frame) throws ID3Exception {
+ this();
+ setDescriptionAndInformation(null, frame.getInformation());
+ }
+
+ /**
+ * Returns whether the album is a sampler (with multiple artists).
+ * @return always {@code TRUE} or {@code FALSE} (as String)
+ */
+ @Override
+ public String getInformation() {
+ String info = super.getInformation();
+ if ( EMPTY_INFO.equals(info) )
+ return Boolean.FALSE.toString();
+ try {
+ return Boolean.valueOf(info).toString();
+ } catch (Exception err){
+ return Boolean.FALSE.toString();
+ }
+ }
+
+ /**
+ * Returns whether the album is a sampler (with multiple artists).
+ */
+ public boolean getAlbumSampler() {
+ return Boolean.TRUE.toString().equals(getInformation());
+ }
+
+ /**
+ * Sets whether the album is a sampler (with multiple artists). The parameter {@code desc} is ignored.
+ * Always the static id {@link #FRAME_ID} is used!
+ * @param albumSamplerStr String which can be parsed to Boolean
+ */
+ @Override
+ public void setDescriptionAndInformation(String desc, String albumSamplerStr) throws ID3Exception {
+ Boolean albumSampler = false;
+ try {
+ albumSampler = Boolean.valueOf(albumSamplerStr);
+ } catch (Exception err){
+ }
+ super.setDescriptionAndInformation(FRAME_ID, albumSampler.toString());
+ }
+
+ /**
+ * Sets whether the album is a sampler (with multiple artists).
+ */
+ public void setAlbumSampler(boolean albumSampler) throws ID3Exception {
+ setDescriptionAndInformation(FRAME_ID, ""+albumSampler);
+ }
+
+}
Modified: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/AudioCDInformationFrame.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/AudioCDInformationFrame.java 2013-07-18 21:29:18 UTC (rev 2363)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/AudioCDInformationFrame.java 2013-07-19 09:12:55 UTC (rev 2364)
@@ -31,7 +31,6 @@
import org.apache.commons.lang.StringUtils;
import org.blinkenlights.jid3.ID3Exception;
-import org.blinkenlights.jid3.v2.MCDIID3V2Frame;
import org.blinkenlights.jid3.v2.TXXXTextInformationID3V2Frame;
/**
Modified: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagField.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagField.java 2013-07-18 21:29:18 UTC (rev 2363)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagField.java 2013-07-19 09:12:55 UTC (rev 2364)
@@ -28,8 +28,10 @@
GENRE,
/** Comment for file. */
COMMENT,
- /** Audio CD information from MCDI frame (only ID3v2). */
- AUDIOCD;
+ /** Audio CD information from TXXX frame (only ID3v2). */
+ AUDIOCD,
+ /** Flag whether album is sampler (with multiple artists) from TXXX frame (only ID3v2). */
+ ALBUM_IS_SAMPLER;
/**
* Returns a title for ID3-Tag field.
@@ -52,6 +54,7 @@
case YEAR: return ID3TagUtil.R("ID3Tag.Year");
case COMMENT: return ID3TagUtil.R("ID3Tag.Comment");
case AUDIOCD: return ID3TagUtil.R("ID3Tag.AudioCD");
+ case ALBUM_IS_SAMPLER: return ID3TagUtil.R("ID3Tag.AlbumSampler");
}
throw new UnsupportedOperationException("Unknown enum: "+field);
}
Modified: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagUtil.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagUtil.java 2013-07-18 21:29:18 UTC (rev 2363)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagUtil.java 2013-07-19 09:12:55 UTC (rev 2364)
@@ -70,10 +70,15 @@
public static String R(String key, Object... values) {
return RESOURCE.getString(key, values);
}
+
+ /**
+ * Some applications (e.g. WinAmp) store the genre index in combination
+ * with the textual information (e.g. "(19)Industrial"). This pattern can be
+ * used to parse the genre index and name from combined string.
+ */
+ public static final Pattern GENRE_PATTERN = Pattern.compile("(\\(([\\d]+)\\))?(.*)");
-
-
/** Contains all available ID3 v1 genres as array. */
public static final Genre[] ALL_GENRE_ID3V1;
static {
@@ -305,7 +310,8 @@
/**
- * Returns the content of the MCDI frame of the ID3v2 tag.
+ * Returns the content of the special {@link AudioCDInformationFrame} (TXXX frame)
+ * of the ID3v2 tag.
* @return {@code null} if given tag is not {@link ID3V2_3_0Tag}
*/
public static String getAudioCDInformation(ID3V2Tag tag) {
@@ -328,9 +334,35 @@
return null;
return audioCDFrame.getAudioCDInformation();
}
- public static final Pattern GENRE_PATTERN = Pattern.compile("(\\(([\\d]+)\\))?(.*)");
/**
+ * Returns the content of the special {@link AlbumIsSamplerInformationFrame} (TXXX frame)
+ * of the ID3v2 tag, which indicates whether the album is a sampler with
+ * multiple artists.
+ * @return {@code null} if given tag is not {@link ID3V2_3_0Tag}
+ */
+ public static Boolean getAlbumIsSampler(ID3V2Tag tag) {
+ if ( !(tag instanceof ID3V2_3_0Tag) )
+ return null;
+ AlbumIsSamplerInformationFrame albumSamplerFrame = null;
+ for (TXXXTextInformationID3V2Frame frame : ((ID3V2_3_0Tag)tag).getTXXXTextInformationFrames()) {
+ if ( frame instanceof AlbumIsSamplerInformationFrame ) {
+ albumSamplerFrame = (AlbumIsSamplerInformationFrame)frame;
+ break;
+ }
+ if ( AlbumIsSamplerInformationFrame.FRAME_ID.equals(frame.getDescription()) )
+ try {
+ albumSamplerFrame = new AlbumIsSamplerInformationFrame(frame);
+ break;
+ } catch (ID3Exception e) {
+ }
+ }
+ if ( albumSamplerFrame == null )
+ return false;
+ return albumSamplerFrame.getAlbumSampler();
+ }
+
+ /**
* Some applications (e.g. WinAmp) store the genre index in combination
* with the textual information (e.g. "(19)Industrial"). This method parses
* the genre string and returns the textual genre name.
@@ -437,6 +469,11 @@
case AUDIOCD: if ( tag instanceof ID3V2_3_0Tag )
return getAudioCDInformation( (ID3V2_3_0Tag)tag );
return null;
+ case ALBUM_IS_SAMPLER: if ( tag instanceof ID3V2_3_0Tag ) {
+ Boolean albumIsSampler = getAlbumIsSampler( (ID3V2_3_0Tag)tag );
+ return albumIsSampler != null ? albumIsSampler.toString() : null;
+ }
+ return null;
}
return null;
}
@@ -586,14 +623,15 @@
}
/**
- * Sets the MCDI frame of the ID3v2 tag.
- * @param tag
- * @param info
+ * Sets the content of the special {@link AudioCDInformationFrame} (TXXX frame)
+ * of the ID3v2 tag.
* @throws ID3Exception if given tag is not {@link ID3V2_3_0Tag}
*/
public static void setAudioCDInformation(ID3V2Tag tag, String info) throws ID3Exception {
if ( info != null && !(tag instanceof ID3V2_3_0Tag) )
throw new ID3Exception("ID3 tag does not support audio CD information: "+LangUtil.getSimpleClassName(tag));
+ if ( !(tag instanceof ID3V2_3_0Tag) )
+ return;
ID3V2_3_0Tag id3v2 = (ID3V2_3_0Tag)tag;
id3v2.removeTXXXTextInformationFrame( AudioCDInformationFrame.FRAME_ID );
if ( !StringUtils.isBlank(info) )
@@ -601,6 +639,23 @@
}
/**
+ * Sets the content of the special {@link AlbumIsSamplerInformationFrame} (TXXX frame)
+ * of the ID3v2 tag, which indicates whether the album is a sampler with
+ * multiple artists.
+ * @throws ID3Exception if given tag is not {@link ID3V2_3_0Tag}
+ */
+ public static void setAlbumIsSampler(ID3V2Tag tag, Boolean albumIsSampler) throws ID3Exception {
+ if ( albumIsSampler != null && !(tag instanceof ID3V2_3_0Tag) )
+ throw new ID3Exception("ID3 tag does not support album is sampler information: "+LangUtil.getSimpleClassName(tag));
+ if ( !(tag instanceof ID3V2_3_0Tag) )
+ return;
+ ID3V2_3_0Tag id3v2 = (ID3V2_3_0Tag)tag;
+ id3v2.removeTXXXTextInformationFrame( AlbumIsSamplerInformationFrame.FRAME_ID );
+ if ( albumIsSampler != null )
+ id3v2.addTXXXTextInformationFrame( new AlbumIsSamplerInformationFrame(albumIsSampler) );
+ }
+
+ /**
* Sets a basic field from ID3-Tag regardless of the ID3Tag version.
* @param tag ID3-Tag to set the field for
* @param field field to set
@@ -652,6 +707,11 @@
case AUDIOCD: if ( tag instanceof ID3V2_3_0Tag )
setAudioCDInformation((ID3V2Tag) tag, value);
break;
+ case ALBUM_IS_SAMPLER: if ( tag instanceof ID3V2_3_0Tag ) {
+ Boolean albumIsSampler = (value != null) ? Boolean.valueOf(value) : null;
+ setAlbumIsSampler((ID3V2Tag) tag, albumIsSampler);
+ }
+ break;
}
}
@@ -758,6 +818,8 @@
setYear(newTag, tag.getYear() );
setTrackNumber(newTag, tag.getTrackNumber() );
setTotalTracks(newTag, tag.getTotalTracks() );
+ setAudioCDInformation(newTag, getAudioCDInformation(tag));
+ setAlbumIsSampler(newTag, getAlbumIsSampler(tag));
return newTag;
}
Modified: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagPanel.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagPanel.java 2013-07-18 21:29:18 UTC (rev 2363)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagPanel.java 2013-07-19 09:12:55 UTC (rev 2364)
@@ -72,7 +72,7 @@
protected ManualInputOption.Text comment;
public ID3TagPanel() {
- super( new MigLayout("wrap 2","[][grow]","[top]") );
+ super( new MigLayout("wrap 2","[][grow]","top") );
title = new ManualInputOption.Text(null);
titleCheckbox = new BooleanInputOption(ID3TagUtil.R("ID3Tag.Title"), false);
Modified: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagV2Panel.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagV2Panel.java 2013-07-18 21:29:18 UTC (rev 2363)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagV2Panel.java 2013-07-19 09:12:55 UTC (rev 2364)
@@ -53,6 +53,9 @@
protected BooleanInputOption audioCDInfoCheckbox;
protected ManualInputOption.Text audioCDInfo;
+ protected BooleanInputOption albumIsSamplerCheckbox;
+ protected BooleanInputOption albumIsSampler;
+
/**
* Creates a new panel.
*/
@@ -70,12 +73,20 @@
audioCDInfoCheckbox = new BooleanInputOption(ID3TagUtil.R("ID3Tag.AudioCD"), false);
audioCDInfoCheckbox.connectInputOptions(true,audioCDInfo);
+ albumIsSamplerCheckbox = new BooleanInputOption(ID3TagUtil.R("ID3Tag.AlbumSampler"));
+ albumIsSampler = new BooleanInputOption(ID3TagUtil.R("ID3Tag.AlbumSampler.desc"));
+ albumIsSamplerCheckbox.connectInputOptions(true, albumIsSampler);
+
+
add(totalTracksCaption,"aligny center, cell 1 3, gap 7! 7!");
add(totalTracksCheckbox,"cell 1 3");
add(totalTracks,"cell 1 3, w 50");
add(audioCDInfoCheckbox,"");
add(audioCDInfo,"growx");
+
+ add(albumIsSamplerCheckbox,"");
+ add(albumIsSampler,"growx");
}
/**
@@ -125,6 +136,7 @@
genre.setValue( null );
comment.setValue( null );
audioCDInfo.setValue( null );
+ albumIsSampler.setValue( false );
// TODO: add more ID3v2 options
return;
}
@@ -146,6 +158,8 @@
comment.setValue( tag.getComment() );
if ( force || audioCDInfoCheckbox.getValue() )
audioCDInfo.setValue( ID3TagUtil.getAudioCDInformation(tag) );
+ if ( force || albumIsSamplerCheckbox.getValue() )
+ albumIsSampler.setValue( ID3TagUtil.getAlbumIsSampler(tag) );
// TODO: add more ID3v2 options
}
@@ -175,6 +189,8 @@
ID3TagUtil.setComment(tag, comment.getValue());
if ( audioCDInfoCheckbox.getValue() )
ID3TagUtil.setAudioCDInformation(tag, audioCDInfo.getValue());
+ if ( albumIsSamplerCheckbox.getValue() )
+ ID3TagUtil.setAlbumIsSampler(tag, albumIsSampler.getValue());
// TODO: add more ID3v2 options
}
@@ -214,6 +230,8 @@
tag2.setComment( tag1.getComment() );
if ( audioCDInfoCheckbox.getValue() )
ID3TagUtil.setAudioCDInformation(tag2, ID3TagUtil.getAudioCDInformation(tag1));
+ if ( albumIsSamplerCheckbox.getValue() )
+ ID3TagUtil.setAlbumIsSampler(tag2, ID3TagUtil.getAlbumIsSampler(tag1));
// TODO: add more ID3v2 options
}
}
Modified: trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle.properties
===================================================================
--- trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle.properties 2013-07-18 21:29:18 UTC (rev 2363)
+++ trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle.properties 2013-07-19 09:12:55 UTC (rev 2364)
@@ -41,6 +41,8 @@
ID3Tag.TotalTracks=Total tracks
ID3Tag.of=of
ID3Tag.AudioCD=Audio CD
+ID3Tag.AlbumSampler=Sampler
+ID3Tag.AlbumSampler.desc=Multiple artists on album
ID3TagUtil.mp3filter.desc=mp3 files
Modified: trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle_de.properties
===================================================================
--- trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle_de.properties 2013-07-18 21:29:18 UTC (rev 2363)
+++ trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle_de.properties 2013-07-19 09:12:55 UTC (rev 2364)
@@ -39,6 +39,8 @@
ID3Tag.TotalTracks=Gesamt Tracks
ID3Tag.of=von
ID3Tag.AudioCD=Audio-CD
+ID3Tag.AlbumSampler=Sampler
+ID3Tag.AlbumSampler.desc=Mehrere Interpreten auf Album
ID3TagUtil.mp3filter.desc=mp3 Dateien
More information about the Schmitzm-commits
mailing list