* added upperInitial(), lowerTrail() and intersect() to ExpressionFormat.global.js
* some minor refactoring
This commit is contained in:
parent
9f047e67a5
commit
014c668cdd
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@ public class SeasonEpisodeMatcher {
|
|||
patterns[0] = new SeasonEpisodePattern("(?<!\\p{Alnum})[Ss](\\d{1,2})[^\\p{Alnum}]{0,3}[Ee](\\d{1,3})(?!\\p{Digit})");
|
||||
|
||||
// match patterns like 1x01, 1.02, ..., 1x01a, 10x01, 10.02, ...
|
||||
patterns[1] = new SeasonEpisodePattern("(?<!\\p{Alnum})(\\d{1,2})[x\\.](\\d{1,3})(?!\\p{Digit})");
|
||||
patterns[1] = new SeasonEpisodePattern("(?<!\\p{Alnum})(\\d{1,2})[x.](\\d{1,3})(?!\\p{Digit})");
|
||||
|
||||
// match patterns like 01, 102, 1003 (enclosed in separators)
|
||||
patterns[2] = new SeasonEpisodePattern("(?<=^|[\\._ ])([0-1]?\\d?)(\\d{2})(?=[\\._ ]|$)") {
|
||||
patterns[2] = new SeasonEpisodePattern("(?<=^|[._ ])([0-1]?\\d?)(\\d{2})(?=[._ ]|$)") {
|
||||
|
||||
@Override
|
||||
protected Collection<SxE> process(MatchResult match) {
|
||||
|
|
|
@ -89,15 +89,8 @@ public class SubStationAlphaReader extends SubtitleReader {
|
|||
|
||||
|
||||
private enum EventProperty {
|
||||
Layer,
|
||||
Start,
|
||||
End,
|
||||
Style,
|
||||
Name,
|
||||
MarginL,
|
||||
MarginR,
|
||||
MarginV,
|
||||
Effect,
|
||||
Text
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public class RenameModel extends MatchModel<Object, File> {
|
|||
|
||||
@Override
|
||||
public String format(Match<?, ?> match) {
|
||||
return String.valueOf(match.getValue());
|
||||
return String.valueOf(match.getValue()).trim();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue