Refactor EpisodeMetrics
This commit is contained in:
parent
b64bff0c3e
commit
700239934f
|
@ -92,25 +92,16 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
|||
|
||||
@Override
|
||||
public SimpleDate parse(Object object) {
|
||||
if (object instanceof Episode) {
|
||||
Episode episode = (Episode) object;
|
||||
return episode.getAirdate();
|
||||
}
|
||||
|
||||
if (object instanceof Movie) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (object instanceof Episode) {
|
||||
Episode episode = (Episode) object;
|
||||
|
||||
// use airdate from episode
|
||||
return episode.getAirdate();
|
||||
}
|
||||
|
||||
SimpleDate result = transformCache.get(object);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = super.parse(object);
|
||||
transformCache.put(object, result);
|
||||
return result;
|
||||
return transformCache.computeIfAbsent(object, super::parse);
|
||||
}
|
||||
}),
|
||||
|
||||
|
@ -717,19 +708,8 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
|||
return "";
|
||||
}
|
||||
|
||||
String result = transformCache.get(object);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
String name;
|
||||
if (object instanceof File) {
|
||||
name = getName((File) object);
|
||||
} else if (object instanceof FileInfo) {
|
||||
name = ((FileInfo) object).getName();
|
||||
} else {
|
||||
name = object.toString();
|
||||
}
|
||||
return transformCache.computeIfAbsent(object, o -> {
|
||||
String name = normalizeFileName(o);
|
||||
|
||||
// remove checksums, any [...] or (...)
|
||||
name = removeEmbeddedChecksum(name);
|
||||
|
@ -742,13 +722,17 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
|||
}
|
||||
|
||||
// remove or normalize special characters
|
||||
name = normalizePunctuation(name);
|
||||
return normalizePunctuation(name).toLowerCase();
|
||||
});
|
||||
}
|
||||
|
||||
// normalize to lower case
|
||||
name = name.toLowerCase();
|
||||
|
||||
transformCache.put(object, name);
|
||||
return name;
|
||||
private static String normalizeFileName(Object object) {
|
||||
if (object instanceof File) {
|
||||
return getName((File) object);
|
||||
} else if (object instanceof FileInfo) {
|
||||
return ((FileInfo) object).getName();
|
||||
}
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
public static SimilarityMetric[] defaultSequence(boolean includeFileMetrics) {
|
||||
|
|
Loading…
Reference in New Issue