diff --git a/source/net/sourceforge/filebot/format/ExpressionFormat.global.js b/source/net/sourceforge/filebot/format/ExpressionFormat.global.js index d8eb83ea..aaee0cb8 100644 --- a/source/net/sourceforge/filebot/format/ExpressionFormat.global.js +++ b/source/net/sourceforge/filebot/format/ExpressionFormat.global.js @@ -11,3 +11,8 @@ String.prototype.pad = Number.prototype.pad = function(length, padding) { return s; } + + +String.prototype.space = function(replacement) { + return this.replace(/\s/g, replacement); +} diff --git a/source/net/sourceforge/filebot/ui/EpisodeFormatDialog.properties b/source/net/sourceforge/filebot/ui/EpisodeFormatDialog.properties index 8fd964af..ac3ec5e2 100644 --- a/source/net/sourceforge/filebot/ui/EpisodeFormatDialog.properties +++ b/source/net/sourceforge/filebot/ui/EpisodeFormatDialog.properties @@ -10,4 +10,4 @@ example[1]: {n} - {s+'x'}{e.pad(2)} example[2]: {n} - {'S'+s.pad(2)}E{e.pad(2)} # uglyfy name -example[3]: {n.replace(/\\s/g,'.').toLowerCase()} +example[3]: {n.space('.').toLowerCase()} diff --git a/source/net/sourceforge/filebot/ui/panel/rename/MatchAction.java b/source/net/sourceforge/filebot/ui/panel/rename/MatchAction.java index 3de8fe05..6f3ecffa 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/MatchAction.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/MatchAction.java @@ -27,6 +27,7 @@ import net.sourceforge.filebot.similarity.LengthEqualsMetric; import net.sourceforge.filebot.similarity.Match; import net.sourceforge.filebot.similarity.Matcher; import net.sourceforge.filebot.similarity.NameSimilarityMetric; +import net.sourceforge.filebot.similarity.NumericSimilarityMetric; import net.sourceforge.filebot.similarity.SeasonEpisodeSimilarityMetric; import net.sourceforge.filebot.similarity.SimilarityMetric; import net.sourceforge.filebot.similarity.SeasonEpisodeMatcher.SxE; @@ -55,7 +56,7 @@ class MatchAction extends AbstractAction { protected Collection createMetrics() { - SimilarityMetric[] metrics = new SimilarityMetric[3]; + SimilarityMetric[] metrics = new SimilarityMetric[4]; // 1. pass: match by file length (fast, but only works when matching torrents or files) metrics[0] = new LengthEqualsMetric() { @@ -94,6 +95,28 @@ class MatchAction extends AbstractAction { // 3. pass: match by generic name similarity (slow, but most matches will have been determined in second pass) metrics[2] = new NameSimilarityMetric() { + @Override + public float getSimilarity(Object o1, Object o2) { + // normalize absolute similarity to similarity rank (20 ranks in total), + // so we are less likely to fall for false positives + return (float) (Math.floor(super.getSimilarity(o1, o2) * 20) / 20); + } + + + @Override + protected String normalize(Object object) { + if (object instanceof File) { + // compare to filename without extension + object = FileUtilities.getName((File) object); + } + + return super.normalize(object); + } + }; + + // 4. pass: match by generic numeric similarity + metrics[3] = new NumericSimilarityMetric() { + @Override protected String normalize(Object object) { if (object instanceof File) {