Generate index file
This commit is contained in:
parent
10e513be4a
commit
ea583295f3
|
@ -39,6 +39,9 @@ import javax.swing.Icon;
|
|||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import com.bulenkov.iconloader.util.CenteredIcon;
|
||||
import com.bulenkov.iconloader.util.EmptyIcon;
|
||||
|
||||
import net.filebot.Cache;
|
||||
import net.filebot.Cache.TypedCache;
|
||||
import net.filebot.CacheType;
|
||||
|
@ -300,7 +303,9 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
|
|||
Map<SearchResult, Icon> icons = new HashMap<>(ids.length);
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
if (thumbnails[i].length > 0) {
|
||||
icons.put(options.get(i), new ImageIcon(thumbnails[i]));
|
||||
icons.put(options.get(i), new CenteredIcon(new ImageIcon(thumbnails[i]), 48, 48, false));
|
||||
} else {
|
||||
icons.put(options.get(i), new EmptyIcon(48, 48));
|
||||
}
|
||||
}
|
||||
if (icons.size() > 0) {
|
||||
|
|
|
@ -1,29 +1,45 @@
|
|||
package net.filebot.web;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
import static net.filebot.util.RegularExpressions.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.net.http.HttpResponse.BodyHandlers;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.tukaani.xz.XZInputStream;
|
||||
|
||||
import net.filebot.Cache;
|
||||
import net.filebot.CacheType;
|
||||
import net.filebot.Resource;
|
||||
|
||||
public enum ThumbnailProvider {
|
||||
|
||||
TheTVDB, TheMovieDB;
|
||||
|
||||
public String getThumbnailResource(int id) {
|
||||
return "https://api.filebot.net/images/" + name().toLowerCase() + "/thumb/poster/" + id + ".png";
|
||||
protected String getResourceLocation(String file) {
|
||||
return "https://api.filebot.net/images/" + name().toLowerCase() + "/thumb/poster/" + file;
|
||||
}
|
||||
|
||||
public synchronized byte[][] getThumbnails(int[] ids) throws Exception {
|
||||
HttpClient http = HttpClient.newHttpClient();
|
||||
protected Set<Integer> getIndex() throws Exception {
|
||||
byte[] bytes = cache.bytes("index.txt.xz", n -> new URL(getResourceLocation(n)), XZInputStream::new).expire(Cache.ONE_MONTH).get();
|
||||
|
||||
// all data files are UTF-8 encoded XZ compressed text files
|
||||
return NEWLINE.splitAsStream(UTF_8.decode(ByteBuffer.wrap(bytes))).filter(s -> s.length() > 0).map(Integer::parseInt).collect(toSet());
|
||||
}
|
||||
|
||||
private final Resource<Set<Integer>> index = Resource.lazy(this::getIndex);
|
||||
|
||||
public synchronized byte[][] getThumbnails(int[] ids) throws Exception {
|
||||
CompletableFuture<HttpResponse<byte[]>>[] request = new CompletableFuture[ids.length];
|
||||
byte[][] response = new byte[ids.length][];
|
||||
|
||||
|
@ -32,10 +48,13 @@ public enum ThumbnailProvider {
|
|||
response[i] = (byte[]) cache.get(ids[i]);
|
||||
}
|
||||
|
||||
// create if necessary
|
||||
Resource<HttpClient> http = Resource.lazy(HttpClient::newHttpClient);
|
||||
|
||||
for (int i = 0; i < response.length; i++) {
|
||||
if (response[i] == null) {
|
||||
HttpRequest r = HttpRequest.newBuilder(URI.create(getThumbnailResource(ids[i]))).build();
|
||||
request[i] = http.sendAsync(r, BodyHandlers.ofByteArray());
|
||||
if (response[i] == null && index.get().contains(ids[i])) {
|
||||
HttpRequest r = HttpRequest.newBuilder(URI.create(getResourceLocation(ids[i] + ".png"))).build();
|
||||
request[i] = http.get().sendAsync(r, BodyHandlers.ofByteArray());
|
||||
|
||||
debug.fine(format("Fetch resource: %s", r.uri()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue