From ef9d24914a688e48ae1dcd8668fb2108abe68790 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 17 Apr 2016 22:44:25 +0000 Subject: [PATCH] Fix IMDB ID lookup --- source/net/filebot/web/TheTVDBClient2.java | 13 ++++++------- test/net/filebot/web/TheTVDBClient2Test.java | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/source/net/filebot/web/TheTVDBClient2.java b/source/net/filebot/web/TheTVDBClient2.java index 8202569d..2b24ed32 100644 --- a/source/net/filebot/web/TheTVDBClient2.java +++ b/source/net/filebot/web/TheTVDBClient2.java @@ -54,9 +54,9 @@ public class TheTVDBClient2 extends AbstractEpisodeListProvider implements Artwo return true; } - protected Object requestJson(String path, Object post) throws Exception { + protected Object postJson(String path, Object json) throws Exception { // curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' 'https://api.thetvdb.com/login' --data '{"apikey":"XXXXX"}' - ByteBuffer response = post(getEndpoint(path), asJsonString(post).getBytes(UTF_8), "application/json", null); + ByteBuffer response = post(getEndpoint(path), asJsonString(json).getBytes(UTF_8), "application/json", null); return readJson(UTF_8.decode(response)); } @@ -71,7 +71,7 @@ public class TheTVDBClient2 extends AbstractEpisodeListProvider implements Artwo private Map getRequestHeader(Locale locale) { Map header = new LinkedHashMap(3); - if (locale != null) { + if (locale != null && locale != Locale.ROOT) { header.put("Accept-Language", locale.getLanguage()); } header.put("Accept", "application/json"); @@ -85,10 +85,9 @@ public class TheTVDBClient2 extends AbstractEpisodeListProvider implements Artwo private String getAuthorizationToken() { synchronized (tokenExpireDuration) { - System.out.println("EXPIRE: " + tokenExpireInstant); if (token == null || (tokenExpireInstant != null && Instant.now().isAfter(tokenExpireInstant))) { try { - Object json = requestJson("login", singletonMap("apikey", apikey)); + Object json = postJson("login", singletonMap("apikey", apikey)); token = getString(json, "token"); tokenExpireInstant = Instant.now().plus(tokenExpireDuration); } catch (Exception e) { @@ -100,7 +99,7 @@ public class TheTVDBClient2 extends AbstractEpisodeListProvider implements Artwo } protected String[] languages() throws Exception { - Object response = requestJson("languages", Cache.ONE_MONTH); + Object response = requestJson("languages", Locale.ROOT, Cache.ONE_MONTH); return streamJsonObjects(response, "data").map(it -> getString(it, "abbreviation")).toArray(String[]::new); } @@ -221,7 +220,7 @@ public class TheTVDBClient2 extends AbstractEpisodeListProvider implements Artwo throw new IllegalArgumentException("Illegal IMDbID ID: " + imdbid); } - List result = search("search/series", singletonMap("imdbId", imdbid), locale, Cache.ONE_MONTH); + List result = search("search/series", singletonMap("imdbId", String.format("tt%07d", imdbid)), locale, Cache.ONE_MONTH); return result.size() > 0 ? result.get(0) : null; } diff --git a/test/net/filebot/web/TheTVDBClient2Test.java b/test/net/filebot/web/TheTVDBClient2Test.java index 17167c06..f99c84f9 100644 --- a/test/net/filebot/web/TheTVDBClient2Test.java +++ b/test/net/filebot/web/TheTVDBClient2Test.java @@ -136,7 +136,7 @@ public class TheTVDBClient2Test { public void getImages() throws Exception { Artwork i = thetvdb.getArtwork(buffy.getId(), "fanart", Locale.ENGLISH).get(0); - assertEquals("[fanart, null, 1280x720]", i.getCategory().toString()); + assertEquals("[fanart, 1280x720]", i.getCategory().toString()); assertEquals("http://thetvdb.com/banners/fanart/original/70327-1.jpg", i.getUrl().toString()); }