Refactor
This commit is contained in:
parent
b38b1046ed
commit
0ac71b9c7d
|
@ -2,14 +2,15 @@ package net.filebot;
|
|||
|
||||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Language implements Serializable {
|
||||
|
||||
|
@ -96,43 +97,23 @@ public class Language implements Serializable {
|
|||
}
|
||||
|
||||
try {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
|
||||
String[] values = bundle.getString(code).split("\\t", 3);
|
||||
return new Language(code, values[0], values[1], values[2].split("\\t"));
|
||||
String[] values = TAB.split(getProperty(code), 3);
|
||||
return new Language(code, values[0], values[1], TAB.split(values[2]));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Language> getLanguages(String... codes) {
|
||||
Language[] languages = new Language[codes.length];
|
||||
|
||||
for (int i = 0; i < codes.length; i++) {
|
||||
languages[i] = getLanguage(codes[i]);
|
||||
}
|
||||
|
||||
return asList(languages);
|
||||
return stream(codes).map(Language::getLanguage).collect(toList());
|
||||
}
|
||||
|
||||
public static Language getLanguage(Locale locale) {
|
||||
if (locale != null) {
|
||||
String code = locale.getLanguage();
|
||||
for (Language it : availableLanguages()) {
|
||||
if (it.matches(code)) {
|
||||
return it;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return locale == null ? null : findLanguage(locale.getLanguage());
|
||||
}
|
||||
|
||||
public static Language findLanguage(String lang) {
|
||||
for (Language it : availableLanguages()) {
|
||||
if (it.matches(lang)) {
|
||||
return it;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
public static Language findLanguage(String language) {
|
||||
return availableLanguages().stream().filter(it -> it.matches(language)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static String getStandardLanguageCode(String lang) {
|
||||
|
@ -144,26 +125,27 @@ public class Language implements Serializable {
|
|||
}
|
||||
|
||||
public static List<Language> availableLanguages() {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
|
||||
return getLanguages(bundle.getString("languages.ui").split(","));
|
||||
String languages = getProperty("languages.ui");
|
||||
return getLanguages(COMMA.split(languages));
|
||||
}
|
||||
|
||||
public static List<Language> commonLanguages() {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
|
||||
return getLanguages(bundle.getString("languages.common").split(","));
|
||||
String languages = getProperty("languages.common");
|
||||
return getLanguages(COMMA.split(languages));
|
||||
}
|
||||
|
||||
public static List<Language> preferredLanguages() {
|
||||
Set<String> codes = new LinkedHashSet<String>();
|
||||
|
||||
// English | System language | common languages
|
||||
codes.add("en");
|
||||
codes.add(Locale.getDefault().getLanguage());
|
||||
Stream<String> codes = Stream.of("en", Locale.getDefault().getLanguage());
|
||||
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
|
||||
addAll(codes, bundle.getString("languages.common").split(","));
|
||||
// append common languages
|
||||
codes = Stream.concat(codes, stream(COMMA.split(getProperty("languages.common")))).distinct();
|
||||
|
||||
return getLanguages(codes.toArray(new String[0]));
|
||||
return codes.map(Language::getLanguage).collect(toList());
|
||||
}
|
||||
|
||||
private static String getProperty(String key) {
|
||||
return ResourceBundle.getBundle(Language.class.getName()).getString(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package net.filebot.archive;
|
||||
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.*;
|
||||
import static java.util.Arrays.*;
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.filebot.cli;
|
||||
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -41,7 +42,7 @@ public class BindingsHandler extends MapOptionHandler {
|
|||
return pos;
|
||||
}
|
||||
|
||||
String[] nv = params.getParameter(pos).split("=", 2);
|
||||
String[] nv = EQUALS.split(params.getParameter(pos), 2);
|
||||
if (nv.length < 2) {
|
||||
return pos;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import static net.filebot.media.MediaSize.*;
|
|||
import static net.filebot.media.XattrMetaInfo.*;
|
||||
import static net.filebot.subtitle.SubtitleUtilities.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package net.filebot.cli;
|
||||
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
|
@ -47,8 +49,8 @@ public class ScriptShell {
|
|||
|
||||
// default imports
|
||||
ImportCustomizer imports = new ImportCustomizer();
|
||||
imports.addStarImports(bundle.getString("starImport").split(", "));
|
||||
imports.addStaticStars(bundle.getString("starStaticImport").split(", "));
|
||||
imports.addStarImports(COMMA.split(bundle.getString("starImport")));
|
||||
imports.addStaticStars(COMMA.split(bundle.getString("starStaticImport")));
|
||||
config.addCompilationCustomizers(imports);
|
||||
|
||||
GroovyClassLoader classLoader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader(), config);
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
package net.filebot.format;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import groovy.lang.Closure;
|
||||
|
@ -51,9 +53,9 @@ public class ExpressionFormatFunctions {
|
|||
|
||||
public static Map<String, String> csv(String path) throws IOException {
|
||||
Map<String, String> map = new LinkedHashMap<String, String>();
|
||||
for (String line : Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8)) {
|
||||
for (String delim : new String[] { "\t", ";" }) {
|
||||
String[] field = line.split(delim, 2);
|
||||
for (String line : Files.readAllLines(Paths.get(path), UTF_8)) {
|
||||
for (Pattern delim : new Pattern[] { TAB, SEMICOLON }) {
|
||||
String[] field = delim.split(line, 2);
|
||||
if (field.length >= 2) {
|
||||
map.put(field[0], field[1]);
|
||||
break;
|
||||
|
@ -64,7 +66,7 @@ public class ExpressionFormatFunctions {
|
|||
}
|
||||
|
||||
public static List<String> readLines(String path) throws IOException {
|
||||
return Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8);
|
||||
return Files.readAllLines(Paths.get(path), UTF_8);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import static net.filebot.media.XattrMetaInfo.*;
|
|||
import static net.filebot.similarity.Normalization.*;
|
||||
import static net.filebot.subtitle.SubtitleUtilities.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
import static net.filebot.web.EpisodeFormat.*;
|
||||
|
||||
|
@ -364,10 +365,10 @@ public class MediaBindingBean {
|
|||
|
||||
@Define("channels")
|
||||
public String getAudioChannelPositions() {
|
||||
String[] channels = getMediaInfo(StreamKind.Audio, 0, "ChannelPositions/String2", "Channel(s)_Original", "Channel(s)").split("/");
|
||||
String channels = getMediaInfo(StreamKind.Audio, 0, "ChannelPositions/String2", "Channel(s)_Original", "Channel(s)");
|
||||
|
||||
// e.g. 5.1
|
||||
return stream(channels).map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(1).toPlainString();
|
||||
return SLASH.splitAsStream(channels).map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(1).toPlainString();
|
||||
}
|
||||
|
||||
@Define("resolution")
|
||||
|
@ -834,7 +835,8 @@ public class MediaBindingBean {
|
|||
|
||||
@Define("mediaType")
|
||||
public List<String> getMediaType() throws Exception {
|
||||
return asList(MediaTypes.getDefault().getMediaType(getExtension()).split("/")); // format engine does not allow / in binding value
|
||||
// format engine does not allow / in binding value
|
||||
return SLASH.splitAsStream(MediaTypes.getDefault().getMediaType(getExtension())).collect(toList());
|
||||
}
|
||||
|
||||
@Define("file")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.filebot.media;
|
||||
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.regex.Pattern.*;
|
||||
|
@ -10,6 +11,7 @@ import static net.filebot.media.XattrMetaInfo.*;
|
|||
import static net.filebot.similarity.CommonSequenceMatcher.*;
|
||||
import static net.filebot.similarity.Normalization.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
|
||||
import java.io.File;
|
||||
|
|
|
@ -9,6 +9,7 @@ import static java.util.regex.Pattern.*;
|
|||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.similarity.Normalization.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
@ -400,37 +401,35 @@ public class ReleaseInfo {
|
|||
}
|
||||
|
||||
public List<File> getMediaRoots() {
|
||||
List<File> roots = new ArrayList<File>();
|
||||
for (String it : getProperty("folder.media.roots").split(":")) {
|
||||
roots.add(new File(it));
|
||||
}
|
||||
return roots;
|
||||
String roots = getProperty("folder.media.roots");
|
||||
return COMMA.splitAsStream(roots).map(File::new).collect(toList());
|
||||
}
|
||||
|
||||
public String[] getSubtitleCategoryTags() {
|
||||
return getProperty("pattern.subtitle.tags").split("\\|");
|
||||
String tags = getProperty("pattern.subtitle.tags");
|
||||
return PIPE.split(tags);
|
||||
}
|
||||
|
||||
protected final Resource<Map<Pattern, String>> seriesMappings = resource("url.series-mappings", Cache.ONE_WEEK, Function.identity(), String[]::new).transform(lines -> {
|
||||
private final Resource<Map<Pattern, String>> seriesMappings = resource("url.series-mappings", Cache.ONE_WEEK, Function.identity(), String[]::new).transform(lines -> {
|
||||
Map<Pattern, String> map = new LinkedHashMap<Pattern, String>(lines.length);
|
||||
stream(lines).map(s -> s.split("\t", 2)).filter(v -> v.length == 2).forEach(v -> {
|
||||
stream(lines).map(s -> TAB.split(s, 2)).filter(v -> v.length == 2).forEach(v -> {
|
||||
Pattern pattern = compile("(?<!\\p{Alnum})(" + v[0] + ")(?!\\p{Alnum})", CASE_INSENSITIVE);
|
||||
map.put(pattern, v[1]);
|
||||
});
|
||||
return unmodifiableMap(map);
|
||||
}).memoize();
|
||||
|
||||
protected final Resource<String[]> releaseGroup = lines("url.release-groups", Cache.ONE_WEEK);
|
||||
protected final Resource<String[]> queryBlacklist = lines("url.query-blacklist", Cache.ONE_WEEK);
|
||||
protected final Resource<String[]> excludeBlacklist = lines("url.exclude-blacklist", Cache.ONE_WEEK);
|
||||
private final Resource<String[]> releaseGroup = lines("url.release-groups", Cache.ONE_WEEK);
|
||||
private final Resource<String[]> queryBlacklist = lines("url.query-blacklist", Cache.ONE_WEEK);
|
||||
private final Resource<String[]> excludeBlacklist = lines("url.exclude-blacklist", Cache.ONE_WEEK);
|
||||
|
||||
protected final Resource<SearchResult[]> tvdbIndex = tsv("url.thetvdb-index", Cache.ONE_WEEK, this::parseSeries, SearchResult[]::new);
|
||||
protected final Resource<SearchResult[]> anidbIndex = tsv("url.anidb-index", Cache.ONE_WEEK, this::parseSeries, SearchResult[]::new);
|
||||
private final Resource<SearchResult[]> tvdbIndex = tsv("url.thetvdb-index", Cache.ONE_WEEK, this::parseSeries, SearchResult[]::new);
|
||||
private final Resource<SearchResult[]> anidbIndex = tsv("url.anidb-index", Cache.ONE_WEEK, this::parseSeries, SearchResult[]::new);
|
||||
|
||||
protected final Resource<Movie[]> movieIndex = tsv("url.movie-list", Cache.ONE_MONTH, this::parseMovie, Movie[]::new);
|
||||
protected final Resource<SubtitleSearchResult[]> osdbIndex = tsv("url.osdb-index", Cache.ONE_MONTH, this::parseSubtitle, SubtitleSearchResult[]::new);
|
||||
private final Resource<Movie[]> movieIndex = tsv("url.movie-list", Cache.ONE_MONTH, this::parseMovie, Movie[]::new);
|
||||
private final Resource<SubtitleSearchResult[]> osdbIndex = tsv("url.osdb-index", Cache.ONE_MONTH, this::parseSubtitle, SubtitleSearchResult[]::new);
|
||||
|
||||
protected final SystemProperty<Duration> refreshDuration = SystemProperty.of("url.refresh", Duration::parse, null);
|
||||
private final SystemProperty<Duration> refreshDuration = SystemProperty.of("url.refresh", Duration::parse, null);
|
||||
|
||||
private SearchResult parseSeries(String[] v) {
|
||||
int id = parseInt(v[0]);
|
||||
|
@ -463,7 +462,7 @@ public class ReleaseInfo {
|
|||
}
|
||||
|
||||
protected <A> Resource<A[]> tsv(String name, Duration expirationTime, Function<String[], A> parse, IntFunction<A[]> generator) {
|
||||
return resource(name, expirationTime, s -> parse.apply(s.split("\t")), generator).memoize();
|
||||
return resource(name, expirationTime, s -> parse.apply(TAB.split(s)), generator).memoize();
|
||||
}
|
||||
|
||||
protected <A> Resource<A[]> resource(String name, Duration expirationTime, Function<String, A> parse, IntFunction<A[]> generator) {
|
||||
|
|
|
@ -2,7 +2,7 @@ package net.filebot.similarity;
|
|||
|
||||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
|
||||
import java.text.CollationKey;
|
||||
import java.text.Collator;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.filebot.similarity;
|
||||
|
||||
import static java.util.regex.Pattern.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.filebot.similarity;
|
||||
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.filebot.similarity;
|
|||
import static java.util.Collections.*;
|
||||
import static java.util.regex.Pattern.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
|
||||
import java.io.File;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.filebot.subtitle;
|
||||
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package net.filebot.ui.rename;
|
||||
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.MediaTypes.*;
|
||||
import static net.filebot.UserFiles.*;
|
||||
import static net.filebot.media.XattrMetaInfo.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
import static net.filebot.util.ui.SwingUI.*;
|
||||
|
||||
import java.awt.Color;
|
||||
|
@ -15,7 +17,6 @@ import java.awt.event.WindowEvent;
|
|||
import java.io.File;
|
||||
import java.text.Format;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -210,8 +211,8 @@ class BindingDialog extends JDialog {
|
|||
}
|
||||
|
||||
private List<String> getSampleExpressions() {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(getClass().getName());
|
||||
return Arrays.asList(bundle.getString("expressions").split(","));
|
||||
String expressions = ResourceBundle.getBundle(getClass().getName()).getString("expressions");
|
||||
return COMMA.splitAsStream(expressions).collect(toList());
|
||||
}
|
||||
|
||||
public boolean submit() {
|
||||
|
|
|
@ -9,7 +9,7 @@ import static net.filebot.Logging.*;
|
|||
import static net.filebot.Settings.*;
|
||||
import static net.filebot.UserFiles.*;
|
||||
import static net.filebot.media.XattrMetaInfo.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
import static net.filebot.util.ui.SwingUI.*;
|
||||
|
||||
import java.awt.Color;
|
||||
|
|
|
@ -3,7 +3,9 @@ package net.filebot.ui.subtitle;
|
|||
import static java.awt.Font.*;
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.regex.Pattern.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.similarity.Normalization.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
import static net.filebot.util.ui.SwingUI.*;
|
||||
|
||||
import java.awt.Color;
|
||||
|
@ -196,15 +198,7 @@ public class SubtitleViewer extends JFrame {
|
|||
|
||||
private void setTableFilter(String filter) {
|
||||
// filter by words
|
||||
List<SubtitleFilter> filterList = new ArrayList<SubtitleFilter>();
|
||||
|
||||
if (filter != null) {
|
||||
for (String word : filter.split("\\s+")) {
|
||||
if (word.length() > 0) {
|
||||
filterList.add(new SubtitleFilter(word));
|
||||
}
|
||||
}
|
||||
}
|
||||
List<SubtitleFilter> filterList = filter == null ? emptyList() : SPACE.splitAsStream(filter).filter(s -> s.length() > 0).map(SubtitleFilter::new).collect(toList());
|
||||
|
||||
TableRowSorter sorter = (TableRowSorter) subtitleTable.getRowSorter();
|
||||
sorter.setRowFilter(filterList.isEmpty() ? null : RowFilter.andFilter(filterList));
|
||||
|
|
|
@ -4,7 +4,7 @@ import static java.nio.charset.StandardCharsets.*;
|
|||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
|
@ -621,14 +621,12 @@ public final class FileUtilities {
|
|||
return path.replace('\\', '/');
|
||||
}
|
||||
|
||||
private static final Pattern PATH_SEPARATORS = Pattern.compile("\\s*[\\\\/]+\\s*");
|
||||
|
||||
public static String replacePathSeparators(CharSequence path) {
|
||||
return replacePathSeparators(path, " ");
|
||||
}
|
||||
|
||||
public static String replacePathSeparators(CharSequence path, String replacement) {
|
||||
return PATH_SEPARATORS.matcher(path).replaceAll(replacement);
|
||||
return SLASH.matcher(path).replaceAll(replacement);
|
||||
}
|
||||
|
||||
public static String md5(String string) {
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package net.filebot.util;
|
||||
|
||||
import static java.util.regex.Pattern.*;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class RegularExpressions {
|
||||
|
||||
public static final Pattern DIGIT = compile("\\d+");
|
||||
public static final Pattern NON_DIGIT = compile("\\D+");
|
||||
|
||||
public static final Pattern PIPE = compile("|", LITERAL);
|
||||
public static final Pattern EQUALS = compile("=", LITERAL);
|
||||
public static final Pattern TAB = compile("\t", LITERAL);
|
||||
public static final Pattern SEMICOLON = compile(";", LITERAL);
|
||||
|
||||
public static final Pattern COMMA = compile("\\s*[,;:]\\s*", UNICODE_CHARACTER_CLASS);
|
||||
public static final Pattern SLASH = compile("\\s*[\\\\/]+\\s*", UNICODE_CHARACTER_CLASS);
|
||||
public static final Pattern SPACE = compile("\\s+", UNICODE_CHARACTER_CLASS); // French No-Break Space U+00A0
|
||||
|
||||
}
|
|
@ -3,22 +3,17 @@ package net.filebot.util;
|
|||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class StringUtilities {
|
||||
|
||||
public static final Pattern DIGIT = Pattern.compile("\\d+");
|
||||
public static final Pattern NON_DIGIT = Pattern.compile("\\D+");
|
||||
public static final Pattern PIPE = Pattern.compile("|", Pattern.LITERAL);
|
||||
public static final Pattern SPACE = Pattern.compile("\\s+", Pattern.UNICODE_CHARACTER_CLASS); // French No-Break Space U+00A0
|
||||
|
||||
public static List<Integer> matchIntegers(CharSequence s) {
|
||||
if (s == null || s.length() == 0) {
|
||||
return emptyList();
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.filebot.web;
|
|||
import static java.nio.charset.StandardCharsets.*;
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.util.JsonUtilities.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
import static net.filebot.web.WebRequest.*;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -204,8 +205,7 @@ public class AcoustIDClient implements MusicIdentificationService {
|
|||
|
||||
try {
|
||||
while (scanner.hasNextLine()) {
|
||||
String[] value = scanner.nextLine().split("=", 2);
|
||||
|
||||
String[] value = EQUALS.split(scanner.nextLine(), 2);
|
||||
if (value.length != 2)
|
||||
continue;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.filebot.web;
|
|||
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
import static net.filebot.util.XPathUtilities.*;
|
||||
import static net.filebot.web.EpisodeUtilities.*;
|
||||
|
@ -98,14 +99,10 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||
continue;
|
||||
}
|
||||
|
||||
List<String> aliasNames = new ArrayList<String>();
|
||||
for (Node aliasNode : selectNodes("AliasNames", node)) {
|
||||
for (String aliasName : getTextContent(aliasNode).split("\\|")) {
|
||||
if (aliasName.trim().length() > 0) {
|
||||
aliasNames.add(aliasName.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
// collect alias names
|
||||
List<String> aliasNames = streamNodes("AliasNames", node).flatMap(it -> {
|
||||
return PIPE.splitAsStream(getTextContent(it));
|
||||
}).map(String::trim).filter(s -> s.length() > 0).collect(toList());
|
||||
|
||||
if (!resultSet.containsKey(sid)) {
|
||||
resultSet.put(sid, new SearchResult(sid, seriesName, aliasNames));
|
||||
|
|
|
@ -49,8 +49,8 @@ public class SeriesNameMatcherTest {
|
|||
|
||||
@Test
|
||||
public void firstCommonSequence() {
|
||||
String[] seq1 = "Common Name 1 Any Title".split("\\s");
|
||||
String[] seq2 = "abc xyz Common Name 2 Any Title".split("\\s");
|
||||
String[] seq1 = "Common Name 1 Any Title".split(" ");
|
||||
String[] seq2 = "abc xyz Common Name 2 Any Title".split(" ");
|
||||
|
||||
// check if common sequence can be determined
|
||||
assertArrayEquals(new String[] { "Common", "Name" }, matcher.firstCommonSequence(seq1, seq2, 2, String.CASE_INSENSITIVE_ORDER));
|
||||
|
|
Loading…
Reference in New Issue