From 9a275b8f996cf85efdddb622087a0ec9b7fd27cd Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 9 Dec 2014 09:58:33 +0000 Subject: [PATCH] * rewrite extended metadata lookup logic --- .../net/filebot/format/MediaBindingBean.java | 38 +++++++++++++------ source/net/filebot/web/TMDbClient.java | 8 +--- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/source/net/filebot/format/MediaBindingBean.java b/source/net/filebot/format/MediaBindingBean.java index 2fcad0ba..2f19fd36 100644 --- a/source/net/filebot/format/MediaBindingBean.java +++ b/source/net/filebot/format/MediaBindingBean.java @@ -557,34 +557,50 @@ public class MediaBindingBean { public synchronized AssociativeScriptObject getMetaInfo() { if (metaInfo == null) { try { - if (infoObject instanceof Episode) - metaInfo = WebServices.TheTVDB.getSeriesInfoByName(getEpisode().getSeriesName(), getEpisode().getLanguage() == null ? Locale.ENGLISH : getEpisode().getLanguage()); - if (infoObject instanceof Movie) - metaInfo = WebServices.TheMovieDB.getMovieInfo(getMovie(), getMovie().getLanguage() == null ? Locale.ENGLISH : getMovie().getLanguage(), true); + if (infoObject instanceof Episode) { + Episode episode = (Episode) infoObject; + if (episode.getSeries() instanceof TheTVDBSearchResult) { + metaInfo = WebServices.TheTVDB.getSeriesInfo((TheTVDBSearchResult) episode.getSeries(), episode.getLanguage() == null ? Locale.ENGLISH : episode.getLanguage()); + } + } else if (infoObject instanceof Movie) { + if (getMovie().getTmdbId() > 0) { + metaInfo = WebServices.TheMovieDB.getMovieInfo(getMovie(), getMovie().getLanguage() == null ? Locale.ENGLISH : getMovie().getLanguage(), true); + } else if (getMovie().getImdbId() > 0) { + metaInfo = WebServices.OMDb.getMovieInfo(getMovie()); + } + } } catch (Exception e) { - throw new RuntimeException("Failed to retrieve metadata: " + infoObject, e); + throw new RuntimeException("Failed to retrieve extended metadata: " + infoObject, e); } } + + if (mediaInfo == null) { + throw new UnsupportedOperationException("Extended metadata not available"); + } + return createMapBindings(new PropertyBindings(metaInfo, null)); } @Define("imdb") public synchronized AssociativeScriptObject getImdbApiInfo() { - Object data = null; + Object metaInfo = null; try { if (infoObject instanceof Episode) { - data = WebServices.OMDb.getMovieInfo(new Movie(getEpisode().getSeriesName(), getEpisode().getSeriesStartDate().getYear(), -1, -1)); + metaInfo = WebServices.OMDb.getMovieInfo(new Movie(getEpisode().getSeriesName(), getEpisode().getSeriesStartDate().getYear(), -1, -1)); } if (infoObject instanceof Movie) { - Movie m = getMovie(); - data = WebServices.OMDb.getMovieInfo(m.getImdbId() > 0 ? m : new Movie(null, -1, WebServices.TheMovieDB.getMovieInfo(getMovie(), Locale.ENGLISH, false).getImdbId(), -1)); + metaInfo = WebServices.OMDb.getMovieInfo(getMovie()); } } catch (Exception e) { - throw new RuntimeException("Failed to retrieve metadata: " + infoObject, e); + throw new RuntimeException("Failed to retrieve extended metadata: " + infoObject, e); } - return createMapBindings(new PropertyBindings(data, null)); + if (mediaInfo == null) { + throw new UnsupportedOperationException("Extended metadata not available"); + } + + return createMapBindings(new PropertyBindings(metaInfo, null)); } @Define("episodelist") diff --git a/source/net/filebot/web/TMDbClient.java b/source/net/filebot/web/TMDbClient.java index 96bd8d7a..89e22d67 100644 --- a/source/net/filebot/web/TMDbClient.java +++ b/source/net/filebot/web/TMDbClient.java @@ -177,15 +177,9 @@ public class TMDbClient implements MovieIdentificationService { return getMovieInfo(String.valueOf(movie.getTmdbId()), locale, extendedInfo); } else if (movie.getImdbId() > 0) { return getMovieInfo(String.format("tt%07d", movie.getImdbId()), locale, extendedInfo); - } else { - for (Movie result : searchMovie(movie.getName(), locale)) { - if (movie.getName().equalsIgnoreCase(result.getName()) && movie.getYear() == result.getYear()) { - return getMovieInfo(String.valueOf(result.getTmdbId()), locale, extendedInfo); - } - } } } catch (FileNotFoundException | NullPointerException e) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, String.format("Movie data missing: %s [%d / %d]", movie, movie.getTmdbId(), movie.getImdbId()), e); + Logger.getLogger(getClass().getName()).log(Level.WARNING, String.format("Movie data not found: %s [%d / %d]", movie, movie.getTmdbId(), movie.getImdbId()), e); } return null; }