diff --git a/source/net/filebot/cli/ArgumentProcessor.java b/source/net/filebot/cli/ArgumentProcessor.java index 2eeb96f9..98a1a347 100644 --- a/source/net/filebot/cli/ArgumentProcessor.java +++ b/source/net/filebot/cli/ArgumentProcessor.java @@ -200,10 +200,8 @@ public class ArgumentProcessor { return uri.getSchemeSpecificPart(); } - // remote script + // check remote script for updates (weekly for stable and daily for devel branches) Cache cache = Cache.getCache(NAME, CacheType.Persistent); - - // fetch remote script only if modified return cache.text(uri.toString(), s -> { return new URL(resolveTemplate(uri)); }).expire(SCHEME_REMOTE_DEVEL.equals(uri.getScheme()) ? Cache.ONE_DAY : Cache.ONE_WEEK).get(); diff --git a/source/net/filebot/format/ExpressionFormatMethods.java b/source/net/filebot/format/ExpressionFormatMethods.java index 4a8a00f7..0cb70252 100644 --- a/source/net/filebot/format/ExpressionFormatMethods.java +++ b/source/net/filebot/format/ExpressionFormatMethods.java @@ -328,11 +328,11 @@ public class ExpressionFormatMethods { /** * Join non-empty String values and prepend prefix / append suffix values - * + * * e.g. (1..3).join('-', '[', ']') - * + * * Unwind if list is empty - * + * * e.g. [].join('-', '[', ']') => Exception: List is empty */ public static String join(Collection self, String delimiter, String prefix, String suffix) throws Exception { diff --git a/source/net/filebot/format/MediaBindingBean.java b/source/net/filebot/format/MediaBindingBean.java index 043f4d4c..8da9ab34 100644 --- a/source/net/filebot/format/MediaBindingBean.java +++ b/source/net/filebot/format/MediaBindingBean.java @@ -447,7 +447,7 @@ public class MediaBindingBean { // calculate checksum from file Cache cache = Cache.getCache("crc32", CacheType.Ephemeral); - return (String) cache.computeIfAbsent(inferredMediaFile.getCanonicalPath(), it -> crc32(inferredMediaFile)); + return (String) cache.computeIf(inferredMediaFile.getCanonicalPath(), Cache.isAbsent(), it -> crc32(inferredMediaFile)); } @Define("fn") diff --git a/source/net/filebot/util/JsonUtilities.java b/source/net/filebot/util/JsonUtilities.java index 73d7e365..68f7d75f 100644 --- a/source/net/filebot/util/JsonUtilities.java +++ b/source/net/filebot/util/JsonUtilities.java @@ -96,11 +96,11 @@ public class JsonUtilities { return null; } - public static > EnumMap mapStringValues(Object node, Class cls) { - return mapValues(node, cls, StringUtilities::asNonEmptyString); + public static > EnumMap getEnumMap(Object node, Class cls) { + return getEnumMap(node, cls, StringUtilities::asNonEmptyString); } - public static , V> EnumMap mapValues(Object node, Class cls, Function converter) { + public static , V> EnumMap getEnumMap(Object node, Class cls, Function converter) { Map values = asMap(node); EnumMap map = new EnumMap(cls); for (K key : cls.getEnumConstants()) { @@ -115,4 +115,8 @@ public class JsonUtilities { return map; } + private JsonUtilities() { + throw new UnsupportedOperationException(); + } + } diff --git a/source/net/filebot/util/XPathUtilities.java b/source/net/filebot/util/XPathUtilities.java index 3acac261..3cb4489b 100644 --- a/source/net/filebot/util/XPathUtilities.java +++ b/source/net/filebot/util/XPathUtilities.java @@ -1,6 +1,7 @@ package net.filebot.util; import java.util.ArrayList; +import java.util.EnumMap; import java.util.List; import java.util.stream.IntStream; import java.util.stream.Stream; @@ -143,6 +144,17 @@ public final class XPathUtilities { return IntStream.range(0, nodes.getLength()).mapToObj(nodes::item); } + public static > EnumMap getEnumMap(Node node, Class cls) { + EnumMap map = new EnumMap(cls); + for (K key : cls.getEnumConstants()) { + String value = getTextContent(key.name(), node); + if (value != null && value.length() > 0) { + map.put(key, value); + } + } + return map; + } + private XPathUtilities() { throw new UnsupportedOperationException(); } diff --git a/source/net/filebot/web/FanartTVClient.java b/source/net/filebot/web/FanartTVClient.java index 050ca8ec..bee54657 100644 --- a/source/net/filebot/web/FanartTVClient.java +++ b/source/net/filebot/web/FanartTVClient.java @@ -1,6 +1,5 @@ package net.filebot.web; -import static java.util.Collections.*; import static java.util.stream.Collectors.*; import static net.filebot.util.JsonUtilities.*; @@ -49,13 +48,13 @@ public class FanartTVClient implements Datasource { Cache cache = Cache.getCache(getName(), CacheType.Weekly); Object json = cache.json(path, s -> getResource(s)).expire(Cache.ONE_WEEK); - return asMap(json).entrySet().stream().flatMap(it -> { - return streamJsonObjects(it.getValue()).map(item -> { - Map map = mapStringValues(item, FanartProperty.class); - map.put(FanartProperty.type, it.getKey().toString()); + return asMap(json).entrySet().stream().flatMap(type -> { + return streamJsonObjects(type.getValue()).map(item -> { + Map map = getEnumMap(item, FanartProperty.class); + map.put(FanartProperty.type, type.getKey().toString()); return new FanartDescriptor(map); - }).filter(a -> a.getProperties().size() > 1); + }).filter(art -> art.getUrl() != null); }).collect(toList()); } @@ -80,10 +79,6 @@ public class FanartTVClient implements Datasource { this.properties = new EnumMap(fields); } - public Map getProperties() { - return unmodifiableMap(properties); - } - public String get(Object key) { return properties.get(FanartProperty.valueOf(key.toString())); }