Factored audio parser tag processing

pull/167/head
luccioman 7 years ago
parent 9a7a353d0e
commit f77f8f40f9

@ -39,6 +39,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.jaudiotagger.audio.AudioFile; import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.AudioFileIO; import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.audio.SupportedFileFormat; import org.jaudiotagger.audio.SupportedFileFormat;
@ -198,6 +199,8 @@ public class audioTagParser extends AbstractParser implements Parser {
/** Map from each supported audio file extensions to a single audio media type */ /** Map from each supported audio file extensions to a single audio media type */
private final Map<String, SupportedAudioMediaType> ext2NormalMediaType; private final Map<String, SupportedAudioMediaType> ext2NormalMediaType;
private static final char SPACE_CHAR = ' ';
public audioTagParser() { public audioTagParser() {
@ -268,35 +271,12 @@ public class audioTagParser extends AbstractParser implements Parser {
// text // text
final List<String> descriptions = new ArrayList<String>(7); final List<String> descriptions = new ArrayList<String>(7);
final StringBuilder text = new StringBuilder(500); final StringBuilder text = new StringBuilder(500);
final char space = ' ';
if(tag != null) { if(tag != null) {
String field = tag.getFirst(FieldKey.ARTIST); final FieldKey[] fieldsToProcess = new FieldKey[] { FieldKey.ARTIST, FieldKey.ALBUM, FieldKey.TITLE,
descriptions.add(FieldKey.ARTIST.name() + ": " + field); FieldKey.COMMENT, FieldKey.LYRICS, FieldKey.TAGS, FieldKey.GENRE };
text.append(field); text.append(space); for (final FieldKey field : fieldsToProcess) {
processTagField(field, tag, descriptions, text);
field = tag.getFirst(FieldKey.ALBUM); }
descriptions.add(FieldKey.ALBUM.name() + ": " + field);
text.append(field); text.append(space);
field = tag.getFirst(FieldKey.TITLE);
descriptions.add(FieldKey.TITLE.name() + ": " + field);
text.append(field); text.append(space);
field = tag.getFirst(FieldKey.COMMENT);
descriptions.add(FieldKey.COMMENT.name() + ": " + field);
text.append(field); text.append(space);
field = tag.getFirst(FieldKey.LYRICS);
descriptions.add(FieldKey.LYRICS.name() + ": " + field);
text.append(field); text.append(space);
field = tag.getFirst(FieldKey.TAGS);
descriptions.add(FieldKey.TAGS.name() + ": " + field);
text.append(field); text.append(space);
field = tag.getFirst(FieldKey.GENRE);
descriptions.add(FieldKey.GENRE.name() + ": " + field);
text.append(field); text.append(space);
} }
text.append(location.toTokens()); text.append(location.toTokens());
@ -376,4 +356,27 @@ public class audioTagParser extends AbstractParser implements Parser {
} }
return docs; return docs;
} }
/**
* Process a tag field : add its value to the descriptions and to text. All
* parameters must not be null.
*
* @param fieldKey
* a field key
* @param tag
* a parsed audio tag
* @param descriptions
* the document descriptions to fill
* @param text
* the document text to fill
*/
private void processTagField(final FieldKey fieldKey, final Tag tag, final List<String> descriptions,
final StringBuilder text) {
final String fieldValue = tag.getFirst(fieldKey);
if(StringUtils.isNotBlank(fieldValue)) {
descriptions.add(fieldKey.name() + ": " + fieldValue);
text.append(fieldValue);
text.append(SPACE_CHAR);
}
}
} }

Loading…
Cancel
Save