Experiment with artwork thumbnail support

This commit is contained in:
Reinhard Pointner 2019-05-18 20:48:36 +07:00
parent 45e491e962
commit ed1a0fa09c
3 changed files with 97 additions and 1 deletions

View File

@ -82,6 +82,7 @@ void build(ids, section, db, query) {
artwork?.findResult{ a ->
return retry(2, 60000) {
sleep(2000)
try {
log.fine "Fetch $a"
return a.url.saveAs(original)
@ -118,5 +119,6 @@ void build(ids, section, db, query) {
build(MediaDetection.animeIndex.object.id as HashSet, 'anidb', AniDB, 'poster')
build(MediaDetection.seriesIndex.object.id as HashSet, 'thetvdb', TheTVDB, 'poster')
build(MediaDetection.movieIndex.object.tmdbId as HashSet, 'themoviedb', TheMovieDB, 'posters')

View File

@ -8,6 +8,7 @@ import static net.filebot.Settings.*;
import static net.filebot.media.MediaDetection.*;
import static net.filebot.util.FileUtilities.*;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
@ -15,6 +16,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -28,11 +30,14 @@ import net.filebot.media.LocalDatasource;
import net.filebot.similarity.MetricAvg;
import net.filebot.web.AcoustIDClient;
import net.filebot.web.AnidbClient;
import net.filebot.web.Artwork;
import net.filebot.web.ArtworkProvider;
import net.filebot.web.Datasource;
import net.filebot.web.EpisodeListProvider;
import net.filebot.web.FanartTVClient;
import net.filebot.web.ID3Lookup;
import net.filebot.web.LocalSearch;
import net.filebot.web.MinamiDB;
import net.filebot.web.Movie;
import net.filebot.web.MovieIdentificationService;
import net.filebot.web.MusicIdentificationService;
@ -240,7 +245,7 @@ public final class WebServices {
}
}
public static class AnidbClientWithLocalSearch extends AnidbClient {
public static class AnidbClientWithLocalSearch extends AnidbClient implements ArtworkProvider {
public AnidbClientWithLocalSearch(String client, int clientver) {
super(client, clientver);
@ -250,6 +255,16 @@ public final class WebServices {
public SearchResult[] getAnimeTitles() throws Exception {
return releaseInfo.getAnidbIndex();
}
@Override
public List<Artwork> getArtwork(int id, String category, Locale locale) throws Exception {
Optional<URI> poster = MinamiDB.INSTANCE.getPicture(MinamiDB.Source.AniDB.getURI(id));
if (poster.isPresent()) {
Artwork artwork = new Artwork(Stream.of("picture"), poster.get().toURL(), null, null);
return singletonList(artwork);
}
return emptyList();
}
}
public static class OpenSubtitlesClientWithLocalSearch extends OpenSubtitlesClient {

View File

@ -0,0 +1,79 @@
package net.filebot.web;
import static java.util.Arrays.*;
import static net.filebot.CachedResource.*;
import static net.filebot.util.JsonUtilities.*;
import java.net.URI;
import java.net.URL;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
import javax.swing.Icon;
import net.filebot.Cache;
import net.filebot.CacheType;
import net.filebot.Resource;
public class MinamiDB implements Datasource {
public static final MinamiDB INSTANCE = new MinamiDB();
@Override
public String getIdentifier() {
return "Minami";
}
@Override
public Icon getIcon() {
return null;
}
protected Cache getCache() {
return Cache.getCache(getIdentifier(), CacheType.Persistent);
}
protected Object request(String file) throws Exception {
return getCache().json(file, this::getResource).fetch(fetchIfNoneMatch(URL::getPath, getCache())).expire(Cache.ONE_MONTH).get();
}
protected URL getResource(String file) throws Exception {
return new URL("https://raw.githubusercontent.com/manami-project/anime-offline-database/master/" + file);
}
protected Object getDatabase() throws Exception {
return request("anime-offline-database.json");
}
private final Resource<Object> db = Resource.lazy(this::getDatabase);
public Stream<Map<?, ?>> getRecords() throws Exception {
return streamJsonObjects(db.get(), "data");
}
public Optional<Map<?, ?>> getRecord(String uri) throws Exception {
return getRecords().filter(r -> {
return stream(getArray(r, "sources")).anyMatch(uri::equals);
}).findFirst();
}
public Optional<URI> getPicture(String uri) throws Exception {
return getRecord(uri).map(r -> getStringValue(r, "picture", URI::create));
}
public enum Source {
AniDB;
public String getURI(int id) {
switch (this) {
case AniDB:
return "https://anidb.net/a" + id;
}
return null;
}
}
}