package dnb.analyze.nfo;
import static dnb.analyze.nfo.NfoLyzer.ARTIST;
import static dnb.analyze.nfo.NfoLyzer.GENRE;
import static dnb.analyze.nfo.NfoLyzer.LINE_BEGIN;
import static dnb.analyze.nfo.NfoLyzer.LINE_END;
import static dnb.analyze.nfo.NfoLyzer.PATTERN_FLAGS;
import static dnb.analyze.nfo.NfoLyzer.TITLE;
import static dnb.analyze.nfo.NfoLyzer.WS;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import dnb.analyze.MatchResult;
public class DefNfoParser extends AbstractNfoParser {
// ۲ �۲ ...artist : SPY �۲ ۲
private static final String DOTS = Pattern.quote(".")+ "+";
private static Pattern createDefPattern(String entry) {
return Pattern.compile(LINE_BEGIN + DOTS + entry + WS + ":" + "\\s+"
+ "(.*?)\\s{2,}" + LINE_END,
PATTERN_FLAGS);
}
private static final String SOURCE = "source";
private static final String RELEASE_DATE = "rls.date";
private static final String LABEL = "label";
private static final String LABEL_CODE = "cat.num";
private static final Pattern PATTERN_ARTIST = createDefPattern(ARTIST);
private static final Pattern PATTERN_TITLE = createDefPattern(TITLE);
private static final Pattern PATTERN_GENRE = createDefPattern(GENRE);
private static final Pattern PATTERN_RLS_DATE = createDefPattern(RELEASE_DATE);
@Override protected Pattern getArtistPattern() { return PATTERN_ARTIST; }
@Override protected Pattern getTitlePattern() { return PATTERN_TITLE; }
@Override protected Pattern getGenrePattern() { return PATTERN_GENRE; }
@Override protected Pattern getReleaseDatePattern() { return PATTERN_RLS_DATE; }
@Override protected Pattern getStreetDatePattern() { return null; }
private static final Pattern PATTERN_MEDIATYPE = createDefPattern(SOURCE);
private static final Pattern PATTERN_LABEL = createDefPattern(LABEL);
private static final Pattern PATTERN_LABEL_CODE = createDefPattern(LABEL_CODE);
/* (non-Javadoc)
* @see dnb.analyze.nfo.NfoParser#parse(java.lang.String)
*/
public void parse(String nfo, Map<NfoField, MatchResult> result) {
// general, easy stuff
super.parse(nfo, result);
// DEF specialties
Matcher m = PATTERN_LABEL_CODE.matcher(nfo);
if(m.find()) {
parseLabelcode(m.group(1), m.start(1), result);
}
m = PATTERN_LABEL.matcher(nfo);
if(m.find()) {
result.put(NfoField.RECORD_LABEL, new MatchResult(m.start(1), m.end(1), m.group(1),
MatchResult.Source.NFO));
}
m = PATTERN_MEDIATYPE.matcher(nfo);
if(m.find()) { // find the whole option record => store groups as separate & KNOWN fields
result.put(NfoField.MEDIA_TYPE, new MatchResult(m.start(1), m.end(1), m.group(1),
MatchResult.Source.NFO));
}
}
}