diff --git a/source/net/sourceforge/filebot/format/ExpressionFormat.global.js b/source/net/sourceforge/filebot/format/ExpressionFormat.global.js index c22b95ab..ff4f6a09 100644 --- a/source/net/sourceforge/filebot/format/ExpressionFormat.global.js +++ b/source/net/sourceforge/filebot/format/ExpressionFormat.global.js @@ -4,6 +4,9 @@ importPackage(java.lang); // Collection, Scanner, Random, UUID, etc. importPackage(java.util); +// SeriesNameMatcher +importClass(net.sourceforge.filebot.similarity.SeriesNameMatcher); + /** * Convenience methods for String.toLowerCase() and String.toUpperCase(). @@ -115,3 +118,39 @@ String.prototype.replacePart = function (replacement) { // no pattern matches, nothing to replace return this; } + + +/** + * Upper-case all initials. + * + * e.g. "The Day a new Demon was born" -> "The Day A New Demon Was Born" + */ +String.prototype.upperInitial = function() { + return this.replace(/\b[a-z]/g, function(letter) { return letter.toUpperCase() }); +} + + +/** + * Lower-case all letters that are not initials. + * + * e.g. "Gundam SEED" -> "Gundam Seed" + */ +String.prototype.lowerTrail = function() { + return this.replace(/\b([a-z])([a-z]+)\b/gi, function(match, initial, trail) { return initial + trail.toLowerCase() }); +} + + +/** + * Return first common word sequence. + * + * e.g. "Kidou Senshi Gundam Seed" intersect "Mobile Suite Gundam Seed") -> "Gundam Seed" + */ +String.prototype.intersect = function (other) { + var matcher = new SeriesNameMatcher(); + + // find common word sequence + var common = matcher.matchByFirstCommonWordSequence(this, other); + + // return common word sequence, if there is one + return common != null ? common : this; +} diff --git a/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java b/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java index 5408f03e..6191c6d2 100644 --- a/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java +++ b/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java @@ -24,10 +24,10 @@ public class SeasonEpisodeMatcher { patterns[0] = new SeasonEpisodePattern("(? process(MatchResult match) { diff --git a/source/net/sourceforge/filebot/subtitle/SubStationAlphaReader.java b/source/net/sourceforge/filebot/subtitle/SubStationAlphaReader.java index e9588518..48082451 100644 --- a/source/net/sourceforge/filebot/subtitle/SubStationAlphaReader.java +++ b/source/net/sourceforge/filebot/subtitle/SubStationAlphaReader.java @@ -89,15 +89,8 @@ public class SubStationAlphaReader extends SubtitleReader { private enum EventProperty { - Layer, Start, End, - Style, - Name, - MarginL, - MarginR, - MarginV, - Effect, Text } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/NamesListTransferablePolicy.java b/source/net/sourceforge/filebot/ui/panel/rename/NamesListTransferablePolicy.java index c9df3236..8fef54dc 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/NamesListTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/NamesListTransferablePolicy.java @@ -82,9 +82,9 @@ class NamesListTransferablePolicy extends FileTransferablePolicy { Scanner scanner = new Scanner(string); while (scanner.hasNextLine()) { - String line = scanner.nextLine(); + String line = scanner.nextLine().trim(); - if (line.trim().length() > 0) { + if (line.length() > 0) { values.add(line); } } @@ -126,9 +126,9 @@ class NamesListTransferablePolicy extends FileTransferablePolicy { Scanner scanner = new Scanner(new FileInputStream(file), "UTF-8"); while (scanner.hasNextLine()) { - String line = scanner.nextLine(); + String line = scanner.nextLine().trim(); - if (line.trim().length() > 0) { + if (line.length() > 0) { values.add(line); } } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/RenameModel.java b/source/net/sourceforge/filebot/ui/panel/rename/RenameModel.java index c8c79bba..e788d16d 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/RenameModel.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/RenameModel.java @@ -51,7 +51,7 @@ public class RenameModel extends MatchModel { @Override public String format(Match match) { - return String.valueOf(match.getValue()); + return String.valueOf(match.getValue()).trim(); } };