I would like to request that more robust tag handling be added to give the ability for it to properly identify the year off of files which have a date stamp in the tag rather than just the year. As a quick fix for simple plug into the existing JaudioTaggerParser class I added a couple private methods, as seen below, and then modified the call for setting the year from:
metaData.setYear(parseInteger(getTagField(tag, FieldKey.YEAR)));
To:
metaData.setYear(parseInteger(dateToYear(getTagField(tag, FieldKey.YEAR))));
If this were to be put in place I would recommend that on the version released that a util be run on initial install to rerun tags and update the year field for existing entries (I haven't coded that up yet as I just decided to clear out and recreate that part of the database).
- Code: Select all
/**
* Try and retrieve a valid year from a date tag, since most taggers put full release date
* Will only try to grab a different date if the length of the string is > 4
*/
private String dateToYear(String date) {
String yr = date;
if (date.length() > 4) {
try {
if (date.matches("^\\d{4}.*")) {
int i = Integer.parseInt(date.substring(0,4));
if (isValidYear(i)) {
yr = date.substring(0,4);
}
}
if (date.matches(".*\\d{4}$") && yr.equals(date)){
int i = Integer.parseInt(date.substring(date.length()-4));
if (isValidYear(i)) {
yr = date.substring(date.length()-4);
}
}
}
catch (NumberFormatException nfe) {
// Ignore NFEs
// nfe.printStackTrace();
}
}
return yr;
}
/**
* Return true if integer appears to be a valid year
*/
private boolean isValidYear(Integer i) {
boolean val = false;
if (i>1900 && i<2100) {
val = true;
}
return val;
}
