Update TheTVDB API v2 to return extended TheTVDBSeriesInfo

This commit is contained in:
Reinhard Pointner 2016-05-07 02:41:29 +08:00
parent d5607e79a5
commit 68faa9b53d
5 changed files with 58 additions and 58 deletions

View File

@ -648,7 +648,7 @@ public class MediaBindingBean {
try {
if (infoObject instanceof Episode) {
if (WebServices.TheTVDB.getIdentifier().equals(getSeriesInfo().getDatabase())) {
TheTVDBSeriesInfo extendedSeriesInfo = (TheTVDBSeriesInfo) WebServices.TheTVDB.getSeriesInfo(getSeriesInfo().getId(), Locale.ENGLISH);
TheTVDBSeriesInfo extendedSeriesInfo = WebServices.TheTVDB.getSeriesInfo(getSeriesInfo().getId(), Locale.ENGLISH);
if (extendedSeriesInfo.getImdbId() != null) {
metaInfo = WebServices.OMDb.getMovieInfo(new Movie(grepImdbId(extendedSeriesInfo.getImdbId()).iterator().next()));
}

View File

@ -166,7 +166,7 @@ public class SubtitleUploadDialog extends JDialog {
NAMES: for (String name : seriesNames) {
List<SearchResult> options = WebServices.TheTVDB.search(name, Locale.ENGLISH);
for (SearchResult entry : options) {
TheTVDBSeriesInfo seriesInfo = (TheTVDBSeriesInfo) WebServices.TheTVDB.getSeriesInfo(entry, Locale.ENGLISH);
TheTVDBSeriesInfo seriesInfo = WebServices.TheTVDB.getSeriesInfo(entry, Locale.ENGLISH);
if (seriesInfo.getImdbId() != null) {
int imdbId = grepImdbId(seriesInfo.getImdbId()).iterator().next();
mapping.setIdentity(WebServices.OpenSubtitles.getMovieDescriptor(new Movie(imdbId), Locale.ENGLISH));

View File

@ -127,11 +127,16 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor
}
@Override
public SeriesInfo getSeriesInfo(SearchResult series, Locale locale) throws Exception {
public TheTVDBSeriesInfo getSeriesInfo(int id, Locale language) throws Exception {
return getSeriesInfo(new SearchResult(id, null), language);
}
@Override
public TheTVDBSeriesInfo getSeriesInfo(SearchResult series, Locale locale) throws Exception {
Object json = requestJson("series/" + series.getId(), locale, Cache.ONE_WEEK);
Object data = getMap(json, "data");
SeriesInfo info = new SeriesInfo(this, locale, series.getId());
TheTVDBSeriesInfo info = new TheTVDBSeriesInfo(this, locale, series.getId());
info.setAliasNames(Stream.of(series.getAliasNames(), getArray(data, "aliases")).flatMap(it -> stream(it)).map(Object::toString).distinct().toArray(String[]::new));
info.setName(getString(data, "seriesName"));
@ -140,12 +145,20 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor
info.setStatus(getString(data, "status"));
info.setRating(getDecimal(data, "siteRating"));
info.setRatingCount(getInteger(data, "siteRatingCount")); // TODO rating count not implemented in the new API yet
info.setRatingCount(getInteger(data, "siteRatingCount"));
info.setRuntime(matchInteger(getString(data, "runtime")));
info.setGenres(stream(getArray(data, "genre")).map(Object::toString).collect(toList()));
info.setStartDate(getStringValue(data, "firstAired", SimpleDate::parse));
// TheTVDB SeriesInfo extras
info.setImdbId(getString(data, "imdbId"));
info.setOverview(getString(data, "overview"));
info.setAirsDayOfWeek(getString(data, "airsDayOfWeek"));
info.setAirsTime(getString(data, "airsTime"));
info.setBannerUrl(getStringValue(data, "banner", this::resolveBanner));
info.setLastUpdated(getStringValue(data, "lastUpdated", Long::new));
return info;
}
@ -233,9 +246,6 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor
public List<Artwork> getArtwork(int id, String category, Locale locale) throws Exception {
Object json = requestJson("series/" + id + "/images/query?keyType=" + category, locale, Cache.ONE_WEEK);
// TheTVDB API v2 does not have a dedicated banner mirror
URL mirror = new URL("http://thetvdb.com/banners/");
return streamJsonObjects(json, "data").map(it -> {
try {
String subKey = getString(it, "subKey");
@ -243,7 +253,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor
String resolution = getString(it, "resolution");
Double rating = getDecimal(getString(it, "ratingsInfo"), "average");
return new Artwork(this, Stream.of(category, subKey, resolution), new URL(mirror, fileName), locale, rating);
return new Artwork(this, Stream.of(category, subKey, resolution), resolveBanner(fileName), locale, rating);
} catch (Exception e) {
debug.log(Level.WARNING, e, e::getMessage);
return null;
@ -251,4 +261,17 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor
}).filter(Objects::nonNull).collect(toList());
}
protected URL resolveBanner(String path) {
if (path == null || path.isEmpty()) {
return null;
}
// TheTVDB API v2 does not have a dedicated banner mirror
try {
return new URL("http://thetvdb.com/banners/" + path);
} catch (Exception e) {
throw new IllegalArgumentException(Objects.toString(path));
}
}
}

View File

@ -8,13 +8,10 @@ public class TheTVDBSeriesInfo extends SeriesInfo implements Serializable {
protected String imdbId;
protected String overview;
protected String airsDayOfWeek;
protected String airTime;
protected String bannerUrl;
protected String fanartUrl;
protected String posterUrl;
protected String airsTime;
protected URL banner;
protected long lastUpdated;
protected TheTVDBSeriesInfo() {
@ -25,22 +22,13 @@ public class TheTVDBSeriesInfo extends SeriesInfo implements Serializable {
this.imdbId = other.imdbId;
this.overview = other.overview;
this.airsDayOfWeek = other.airsDayOfWeek;
this.airTime = other.airTime;
this.bannerUrl = other.bannerUrl;
this.fanartUrl = other.fanartUrl;
this.posterUrl = other.posterUrl;
this.airsTime = other.airsTime;
this.banner = other.banner;
this.lastUpdated = other.lastUpdated;
}
public TheTVDBSeriesInfo(Datasource database, SortOrder order, Locale language, Integer id) {
super(database, order, language, id);
}
public SimpleDate getFirstAired() {
return getStartDate();
}
public String getContentRating() {
return getCertification();
public TheTVDBSeriesInfo(Datasource database, Locale language, Integer id) {
super(database, language, id);
}
public String getImdbId() {
@ -67,44 +55,28 @@ public class TheTVDBSeriesInfo extends SeriesInfo implements Serializable {
this.airsDayOfWeek = airsDayOfWeek;
}
public String getAirTime() {
return airTime;
public String getAirsTime() {
return airsTime;
}
public void setAirTime(String airTime) {
this.airTime = airTime;
public void setAirsTime(String airsTime) {
this.airsTime = airsTime;
}
public String getBannerUrl() {
return bannerUrl;
public URL getBannerUrl() {
return banner;
}
public void setBannerUrl(URL bannerUrl) {
this.bannerUrl = bannerUrl.toString();
public void setBannerUrl(URL banner) {
this.banner = banner;
}
public URL getFanartUrl() {
try {
return new URL(fanartUrl);
} catch (Exception e) {
return null;
}
public long getLastUpdated() {
return lastUpdated;
}
public void setFanartUrl(URL fanartUrl) {
this.fanartUrl = fanartUrl.toString();
}
public URL getPosterUrl() {
try {
return new URL(posterUrl);
} catch (Exception e) {
return null;
}
}
public void setPosterUrl(URL posterUrl) {
this.posterUrl = posterUrl.toString();
public void setLastUpdated(Long lastUpdated) {
this.lastUpdated = lastUpdated == null ? 0 : lastUpdated;
}
@Override

View File

@ -123,7 +123,7 @@ public class TheTVDBClientTest {
@Test
public void getSeriesInfo() throws Exception {
SeriesInfo it = thetvdb.getSeriesInfo(80348, Locale.ENGLISH);
TheTVDBSeriesInfo it = thetvdb.getSeriesInfo(80348, Locale.ENGLISH);
assertEquals(80348, it.getId(), 0);
assertEquals("Action", it.getGenres().get(0));
@ -132,6 +132,11 @@ public class TheTVDBClientTest {
assertEquals("Chuck", it.getName());
assertEquals(9.0, it.getRating(), 0.5);
assertEquals(1000, it.getRatingCount(), 100);
assertEquals("tt0934814", it.getImdbId());
assertEquals("Friday", it.getAirsDayOfWeek());
assertEquals("8:00 PM", it.getAirsTime());
assertEquals(1000, it.getOverview().length(), 100);
assertEquals("http://thetvdb.com/banners/graphical/80348-g26.jpg", it.getBannerUrl().toString());
}
@Test