Permalink
Browse files

Factored audio parser tag processing

  • Loading branch information...
luccioman committed Feb 28, 2018
1 parent 9a7a353 commit f77f8f40f905e5f27b6fbc38c6e5dd6fa334f8c2
Showing with 31 additions and 28 deletions.
  1. +31 −28 source/net/yacy/document/parser/audioTagParser.java
@@ -39,6 +39,7 @@
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.audio.SupportedFileFormat;
@@ -198,6 +199,8 @@ public String getMediaType() {
/** Map from each supported audio file extensions to a single audio media type */
private final Map<String, SupportedAudioMediaType> ext2NormalMediaType;
private static final char SPACE_CHAR = ' ';
public audioTagParser() {
@@ -268,35 +271,12 @@ public audioTagParser() {
// text
final List<String> descriptions = new ArrayList<String>(7);
final StringBuilder text = new StringBuilder(500);
final char space = ' ';
if(tag != null) {
String field = tag.getFirst(FieldKey.ARTIST);
descriptions.add(FieldKey.ARTIST.name() + ": " + field);
text.append(field); text.append(space);
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);
final FieldKey[] fieldsToProcess = new FieldKey[] { FieldKey.ARTIST, FieldKey.ALBUM, FieldKey.TITLE,
FieldKey.COMMENT, FieldKey.LYRICS, FieldKey.TAGS, FieldKey.GENRE };
for (final FieldKey field : fieldsToProcess) {
processTagField(field, tag, descriptions, text);
}
}
text.append(location.toTokens());
@@ -376,4 +356,27 @@ public audioTagParser() {
}
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);
}
}
}

0 comments on commit f77f8f4

Please sign in to comment.