From a895b5706702ce3d7396ec677888179b07e3c2c5 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 8 Jun 2019 06:10:50 +0700 Subject: [PATCH] Add anime-lists parser * https://github.com/ScudLee/anime-lists --- source/net/filebot/web/AnimeLists.java | 16 ++++++++++------ source/net/filebot/web/Manami.java | 11 ++++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/source/net/filebot/web/AnimeLists.java b/source/net/filebot/web/AnimeLists.java index f4c91be8..775f361d 100644 --- a/source/net/filebot/web/AnimeLists.java +++ b/source/net/filebot/web/AnimeLists.java @@ -73,20 +73,24 @@ public enum AnimeLists { } protected static Cache getCache() { - return Cache.getCache("animelists", CacheType.Monthly); + return Cache.getCache("animelists", CacheType.Persistent); } protected static final Resource MODEL = Resource.lazy(AnimeLists::fetchModel); protected static Model fetchModel() throws Exception { + return (Model) JAXBContext.newInstance(Model.class).createUnmarshaller().unmarshal(new ByteArrayInputStream(request("anime-list.xml"))); + } + + protected static byte[] request(String file) throws Exception { + // NOTE: GitHub only supports If-None-Match (If-Modified-Since is ignored) Cache cache = getCache(); - // NOTE: GitHub only supports If-None-Match (If-Modified-Since is ignored) - byte[] xml = cache.bytes("anime-list.xml", r -> { - return new URL("https://raw.githubusercontent.com/ScudLee/anime-lists/master/" + r); - }).fetch(fetchIfNoneMatch(URL::getFile, cache)).expire(Cache.ONE_MONTH).get(); + return cache.bytes(file, AnimeLists::getResource).fetch(fetchIfNoneMatch(url -> file, cache)).expire(Cache.ONE_MONTH).get(); + } - return (Model) JAXBContext.newInstance(Model.class).createUnmarshaller().unmarshal(new ByteArrayInputStream(xml)); + protected static URL getResource(String file) throws Exception { + return new URL("https://raw.githubusercontent.com/ScudLee/anime-lists/master/" + file); } @XmlRootElement(name = "anime-list") diff --git a/source/net/filebot/web/Manami.java b/source/net/filebot/web/Manami.java index 0d33ce71..43804599 100644 --- a/source/net/filebot/web/Manami.java +++ b/source/net/filebot/web/Manami.java @@ -64,9 +64,14 @@ public enum Manami implements ArtworkProvider { } protected static Object request(String file) throws Exception { - return getCache().json(file, f -> { - return new URL("https://raw.githubusercontent.com/manami-project/anime-offline-database/master/" + f); - }).fetch(fetchIfNoneMatch(URL::getPath, getCache())).expire(Cache.ONE_MONTH).get(); + // NOTE: GitHub only supports If-None-Match (If-Modified-Since is ignored) + Cache cache = getCache(); + + return cache.json(file, Manami::getResource).fetch(fetchIfNoneMatch(url -> file, cache)).expire(Cache.ONE_MONTH).get(); + } + + protected static URL getResource(String file) throws Exception { + return new URL("https://raw.githubusercontent.com/manami-project/anime-offline-database/master/" + file); } protected static final Resource database = Resource.lazy(() -> request("anime-offline-database.json"));