This commit is contained in:
Reinhard Pointner 2016-03-09 10:32:49 +00:00
parent 67431e1745
commit bf2571f04f
6 changed files with 29 additions and 20 deletions

View File

@ -200,10 +200,8 @@ public class ArgumentProcessor {
return uri.getSchemeSpecificPart(); 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); Cache cache = Cache.getCache(NAME, CacheType.Persistent);
// fetch remote script only if modified
return cache.text(uri.toString(), s -> { return cache.text(uri.toString(), s -> {
return new URL(resolveTemplate(uri)); return new URL(resolveTemplate(uri));
}).expire(SCHEME_REMOTE_DEVEL.equals(uri.getScheme()) ? Cache.ONE_DAY : Cache.ONE_WEEK).get(); }).expire(SCHEME_REMOTE_DEVEL.equals(uri.getScheme()) ? Cache.ONE_DAY : Cache.ONE_WEEK).get();

View File

@ -447,7 +447,7 @@ public class MediaBindingBean {
// calculate checksum from file // calculate checksum from file
Cache cache = Cache.getCache("crc32", CacheType.Ephemeral); 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") @Define("fn")

View File

@ -96,11 +96,11 @@ public class JsonUtilities {
return null; return null;
} }
public static <K extends Enum<K>> EnumMap<K, String> mapStringValues(Object node, Class<K> cls) { public static <K extends Enum<K>> EnumMap<K, String> getEnumMap(Object node, Class<K> cls) {
return mapValues(node, cls, StringUtilities::asNonEmptyString); return getEnumMap(node, cls, StringUtilities::asNonEmptyString);
} }
public static <K extends Enum<K>, V> EnumMap<K, V> mapValues(Object node, Class<K> cls, Function<Object, V> converter) { public static <K extends Enum<K>, V> EnumMap<K, V> getEnumMap(Object node, Class<K> cls, Function<Object, V> converter) {
Map<?, ?> values = asMap(node); Map<?, ?> values = asMap(node);
EnumMap<K, V> map = new EnumMap<K, V>(cls); EnumMap<K, V> map = new EnumMap<K, V>(cls);
for (K key : cls.getEnumConstants()) { for (K key : cls.getEnumConstants()) {
@ -115,4 +115,8 @@ public class JsonUtilities {
return map; return map;
} }
private JsonUtilities() {
throw new UnsupportedOperationException();
}
} }

View File

@ -1,6 +1,7 @@
package net.filebot.util; package net.filebot.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List; import java.util.List;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -143,6 +144,17 @@ public final class XPathUtilities {
return IntStream.range(0, nodes.getLength()).mapToObj(nodes::item); return IntStream.range(0, nodes.getLength()).mapToObj(nodes::item);
} }
public static <K extends Enum<K>> EnumMap<K, String> getEnumMap(Node node, Class<K> cls) {
EnumMap<K, String> map = new EnumMap<K, String>(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() { private XPathUtilities() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@ -1,6 +1,5 @@
package net.filebot.web; package net.filebot.web;
import static java.util.Collections.*;
import static java.util.stream.Collectors.*; import static java.util.stream.Collectors.*;
import static net.filebot.util.JsonUtilities.*; import static net.filebot.util.JsonUtilities.*;
@ -49,13 +48,13 @@ public class FanartTVClient implements Datasource {
Cache cache = Cache.getCache(getName(), CacheType.Weekly); Cache cache = Cache.getCache(getName(), CacheType.Weekly);
Object json = cache.json(path, s -> getResource(s)).expire(Cache.ONE_WEEK); Object json = cache.json(path, s -> getResource(s)).expire(Cache.ONE_WEEK);
return asMap(json).entrySet().stream().flatMap(it -> { return asMap(json).entrySet().stream().flatMap(type -> {
return streamJsonObjects(it.getValue()).map(item -> { return streamJsonObjects(type.getValue()).map(item -> {
Map<FanartProperty, String> map = mapStringValues(item, FanartProperty.class); Map<FanartProperty, String> map = getEnumMap(item, FanartProperty.class);
map.put(FanartProperty.type, it.getKey().toString()); map.put(FanartProperty.type, type.getKey().toString());
return new FanartDescriptor(map); return new FanartDescriptor(map);
}).filter(a -> a.getProperties().size() > 1); }).filter(art -> art.getUrl() != null);
}).collect(toList()); }).collect(toList());
} }
@ -80,10 +79,6 @@ public class FanartTVClient implements Datasource {
this.properties = new EnumMap<FanartProperty, String>(fields); this.properties = new EnumMap<FanartProperty, String>(fields);
} }
public Map<FanartProperty, String> getProperties() {
return unmodifiableMap(properties);
}
public String get(Object key) { public String get(Object key) {
return properties.get(FanartProperty.valueOf(key.toString())); return properties.get(FanartProperty.valueOf(key.toString()));
} }