Add support for OMDb API key

This commit is contained in:
Reinhard Pointner 2017-05-22 20:44:50 +08:00
parent c22d91c4d9
commit 63834d31d7
4 changed files with 12 additions and 4 deletions

View File

@ -33,6 +33,7 @@ link.help.mas: https://www.filebot.net/mac/support.html
apikey.fanart.tv: 780b986b22c35e6f7a134a2f392c2deb apikey.fanart.tv: 780b986b22c35e6f7a134a2f392c2deb
apikey.thetvdb: 694FAD89942D3827 apikey.thetvdb: 694FAD89942D3827
apikey.themoviedb: 66308fb6e3fd850dde4c7d21df2e8306 apikey.themoviedb: 66308fb6e3fd850dde4c7d21df2e8306
apikey.omdb: 49d311ec
apikey.acoustid: 0B3qZnQc apikey.acoustid: 0B3qZnQc
apikey.anidb: filebot apikey.anidb: filebot
apikey.opensubtitles: FileBot apikey.opensubtitles: FileBot

View File

@ -48,7 +48,7 @@ import net.filebot.web.VideoHashSubtitleService;
public final class WebServices { public final class WebServices {
// movie sources // movie sources
public static final OMDbClient OMDb = new OMDbClient(); public static final OMDbClient OMDb = new OMDbClient(getApiKey("omdb"));
public static final TMDbClient TheMovieDB = new TMDbClient(getApiKey("themoviedb"), SystemProperty.of("net.filebot.WebServices.TheMovieDB.adult", Boolean::parseBoolean, false).get()); public static final TMDbClient TheMovieDB = new TMDbClient(getApiKey("themoviedb"), SystemProperty.of("net.filebot.WebServices.TheMovieDB.adult", Boolean::parseBoolean, false).get());
// episode sources // episode sources

View File

@ -36,6 +36,12 @@ public class OMDbClient implements MovieIdentificationService {
private static final FloodLimit REQUEST_LIMIT = new FloodLimit(2, 1, TimeUnit.SECONDS); private static final FloodLimit REQUEST_LIMIT = new FloodLimit(2, 1, TimeUnit.SECONDS);
private String apikey;
public OMDbClient(String apikey) {
this.apikey = apikey;
}
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return "OMDb"; return "OMDb";
@ -126,9 +132,10 @@ public class OMDbClient implements MovieIdentificationService {
public Object request(Map<String, Object> parameters) throws Exception { public Object request(Map<String, Object> parameters) throws Exception {
Cache cache = Cache.getCache(getName(), CacheType.Monthly); Cache cache = Cache.getCache(getName(), CacheType.Monthly);
String key = '?' + encodeParameters(parameters, true);
return cache.json(key, s -> getResource(s)).fetch(withPermit(fetchIfModified(), r -> REQUEST_LIMIT.acquirePermit())).expire(Cache.ONE_WEEK).get(); return cache.json(encodeParameters(parameters, true), s -> {
return getResource('?' + s + "&apikey=" + apikey);
}).fetch(withPermit(fetchIfModified(), r -> REQUEST_LIMIT.acquirePermit())).expire(Cache.ONE_WEEK).get();
} }
public URL getResource(String file) throws Exception { public URL getResource(String file) throws Exception {

View File

@ -8,7 +8,7 @@ import org.junit.Test;
public class OMDbClientTest { public class OMDbClientTest {
private final OMDbClient client = new OMDbClient(); private final OMDbClient client = new OMDbClient("49d311ec");
@Test @Test
public void searchMovie1() throws Exception { public void searchMovie1() throws Exception {