From c3093eb8d1521ed24fbbb0714fd93ad9e71a2838 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 29 Dec 2011 00:51:00 +0000 Subject: [PATCH] * gracefully ignore missing data --- .../sourceforge/filebot/web/TMDbClient.java | 64 ++++++++++++++----- .../filebot/web/TheTVDBClient.java | 50 +++++++++++---- website/scripts/artwork.tmdb.groovy | 14 ++-- website/scripts/artwork.tvdb.groovy | 31 +++++---- 4 files changed, 111 insertions(+), 48 deletions(-) diff --git a/source/net/sourceforge/filebot/web/TMDbClient.java b/source/net/sourceforge/filebot/web/TMDbClient.java index 75514059..e65e1551 100644 --- a/source/net/sourceforge/filebot/web/TMDbClient.java +++ b/source/net/sourceforge/filebot/web/TMDbClient.java @@ -225,7 +225,11 @@ public class TMDbClient implements MovieIdentificationService { public Locale getLanguage() { - return new Locale(get(MovieProperty.language)); + try { + return new Locale(get(MovieProperty.language)); + } catch (Exception e) { + return null; + } } @@ -239,14 +243,22 @@ public class TMDbClient implements MovieIdentificationService { } - public int getId() { - return Integer.parseInt(get(MovieProperty.id)); + public Integer getId() { + try { + return new Integer(get(MovieProperty.id)); + } catch (Exception e) { + return null; + } } - public int getImdbId() { + public Integer getImdbId() { // e.g. tt0379786 - return Integer.parseInt(get(MovieProperty.imdb_id).substring(2)); + try { + return new Integer(get(MovieProperty.imdb_id).substring(2)); + } catch (Exception e) { + return null; + } } @@ -264,13 +276,21 @@ public class TMDbClient implements MovieIdentificationService { } - public int getVotes() { - return Integer.parseInt(get(MovieProperty.votes)); + public Integer getVotes() { + try { + return new Integer(get(MovieProperty.votes)); + } catch (Exception e) { + return null; + } } - public double getRating() { - return Double.parseDouble(get(MovieProperty.rating)); + public Double getRating() { + try { + return new Double(get(MovieProperty.rating)); + } catch (Exception e) { + return null; + } } @@ -286,8 +306,12 @@ public class TMDbClient implements MovieIdentificationService { } - public int getRuntime() { - return Integer.parseInt(get(MovieProperty.runtime)); + public Integer getRuntime() { + try { + return new Integer(get(MovieProperty.runtime)); + } catch (Exception e) { + return null; + } } @@ -350,7 +374,7 @@ public class TMDbClient implements MovieIdentificationService { public URL getUrl() { try { return new URL(get(ArtworkProperty.url)); - } catch (MalformedURLException e) { + } catch (Exception e) { return null; } } @@ -361,13 +385,21 @@ public class TMDbClient implements MovieIdentificationService { } - public int getWidth() { - return Integer.parseInt(get(ArtworkProperty.width)); + public Integer getWidth() { + try { + return new Integer(get(ArtworkProperty.width)); + } catch (Exception e) { + return null; + } } - public int getHeight() { - return Integer.parseInt(get(ArtworkProperty.height)); + public Integer getHeight() { + try { + return new Integer(get(ArtworkProperty.height)); + } catch (Exception e) { + return null; + } } diff --git a/source/net/sourceforge/filebot/web/TheTVDBClient.java b/source/net/sourceforge/filebot/web/TheTVDBClient.java index 6403c2a6..e15eed50 100644 --- a/source/net/sourceforge/filebot/web/TheTVDBClient.java +++ b/source/net/sourceforge/filebot/web/TheTVDBClient.java @@ -460,9 +460,13 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { } - public int getId() { + public Integer getId() { // e.g. 80348 - return Integer.parseInt(get(SeriesProperty.id)); + try { + return Integer.parseInt(get(SeriesProperty.id)); + } catch (Exception e) { + return null; + } } @@ -480,10 +484,12 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { protected List split(String values) { List items = new ArrayList(); - for (String it : values.split("[|]")) { - it = it.trim(); - if (it.length() > 0) { - items.add(it); + if (values != null && values.length() > 0) { + for (String it : values.split("[|]")) { + it = it.trim(); + if (it.length() > 0) { + items.add(it); + } } } return items; @@ -514,15 +520,23 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { } - public int getImdbId() { + public Integer getImdbId() { // e.g. tt0934814 - return Integer.parseInt(get(SeriesProperty.IMDB_ID).substring(2)); + try { + return Integer.parseInt(get(SeriesProperty.IMDB_ID).substring(2)); + } catch (Exception e) { + return null; + } } public Locale getLanguage() { // e.g. en - return new Locale(get(SeriesProperty.Language)); + try { + return new Locale(get(SeriesProperty.Language)); + } catch (Exception e) { + return null; + } } @@ -532,15 +546,23 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { } - public double getRating() { + public Double getRating() { // e.g. 9.0 - return Double.parseDouble(get(SeriesProperty.Rating)); + try { + return Double.parseDouble(get(SeriesProperty.Rating)); + } catch (Exception e) { + return null; + } } - public int getRatingCount() { + public Integer getRatingCount() { // e.g. 696 - return Integer.parseInt(get(SeriesProperty.RatingCount)); + try { + return Integer.parseInt(get(SeriesProperty.RatingCount)); + } catch (Exception e) { + return null; + } } @@ -595,7 +617,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { } - public URL getPosterUrl() throws MalformedURLException { + public URL getPosterUrl() { try { return new URL(getBannerMirrorUrl(), get(SeriesProperty.poster)); } catch (Exception e) { diff --git a/website/scripts/artwork.tmdb.groovy b/website/scripts/artwork.tmdb.groovy index 99f388e6..de7cd3e5 100644 --- a/website/scripts/artwork.tmdb.groovy +++ b/website/scripts/artwork.tmdb.groovy @@ -1,7 +1,7 @@ // filebot -script "http://filebot.sf.net/scripts/artwork.tmdb.groovy" -trust-script /path/to/media/ // EXPERIMENTAL // HERE THERE BE DRAGONS -if (net.sourceforge.filebot.Settings.applicationRevisionNumber < 802) throw new Exception("Application revision too old") +if (net.sourceforge.filebot.Settings.applicationRevisionNumber < 808) throw new Exception("Application revision too old") /* @@ -41,6 +41,11 @@ def fetchMovieArtworkAndNfo(movieDir, movie) { println "Fetch nfo and artwork for $movie" def movieInfo = TheMovieDB.getMovieInfo(movie, Locale.ENGLISH) + println movieInfo + movieInfo.images.each { + println "Available artwork: $it.url => $it" + } + // fetch nfo fetchNfo(movieDir['movie.nfo'], movieInfo) @@ -50,7 +55,7 @@ def fetchMovieArtworkAndNfo(movieDir, movie) { } -def jobs = args.getFolders().findResults { dir -> +args.getFolders().each { dir -> def videos = dir.listFiles{ it.isVideo() } if (videos.isEmpty()) { return null @@ -66,7 +71,6 @@ def jobs = args.getFolders().findResults { dir -> // auto-select series def movie = options.sortBySimilarity(query, { it.name })[0] - return { fetchMovieArtworkAndNfo(dir, movie) } + println "$dir => $movie" + fetchMovieArtworkAndNfo(dir, movie) } - -parallel(jobs, 10) diff --git a/website/scripts/artwork.tvdb.groovy b/website/scripts/artwork.tvdb.groovy index b9d167af..5b57769e 100644 --- a/website/scripts/artwork.tvdb.groovy +++ b/website/scripts/artwork.tvdb.groovy @@ -1,18 +1,18 @@ // filebot -script "http://filebot.sf.net/scripts/artwork.tvdb.groovy" -trust-script /path/to/media/ // EXPERIMENTAL // HERE THERE BE DRAGONS -if (net.sourceforge.filebot.Settings.applicationRevisionNumber < 802) throw new Exception("Application revision too old") +if (net.sourceforge.filebot.Settings.applicationRevisionNumber < 808) throw new Exception("Application revision too old") /* * Fetch series and season banners for all tv shows. Series name is auto-detected if possible or the folder name is used. */ -def fetchBanner(outputFile, series, bannerType, bannerType2, season = null) { +def fetchBanner(outputFile, series, bannerType, bannerType2 = null, season = null) { // select and fetch banner def banner = TheTVDB.getBanner(series, bannerType, bannerType2, season, Locale.ENGLISH, 0) if (banner == null) { - println "Banner not found: $outputFile" + println "Banner not found: $outputFile / $bannerType:$bannerType2" return null } @@ -22,7 +22,9 @@ def fetchBanner(outputFile, series, bannerType, bannerType2, season = null) { def fetchNfo(outputFile, series) { - TheTVDB.getSeriesInfo(series, Locale.ENGLISH).applyXmlTemplate(''' + def info = TheTVDB.getSeriesInfo(series, Locale.ENGLISH) + println info + info.applyXmlTemplate(''' $name ${firstAired?.year} $rating @@ -49,15 +51,19 @@ def fetchNfo(outputFile, series) { def fetchSeriesBannersAndNfo(seriesDir, seasonDir, series, season) { println "Fetch nfo and banners for $series / Season $season" + TheTVDB.getBannerList(series.seriesId).each { + println "Available banner: $it.url => $it" + } + // fetch nfo fetchNfo(seriesDir['tvshow.nfo'], series) - + // fetch series banner, fanart, posters, etc - fetchBanner(seriesDir['folder.jpg'], series, "poster", "680x1000") - fetchBanner(seriesDir['banner.jpg'], series, "series", "graphical") + ["680x1000", null].findResult{ fetchBanner(seriesDir['folder.jpg'], series, "poster", it) } + ["graphical", null].findResult{ fetchBanner(seriesDir['banner.jpg'], series, "series", it) } // fetch highest resolution fanart - ["1920x1080", "1280x720"].findResult{ fetchBanner(seriesDir["fanart.jpg"], series, "fanart", it) } + ["1920x1080", "1280x720", null].findResult{ fetchBanner(seriesDir["fanart.jpg"], series, "fanart", it) } // fetch season banners if (seasonDir != seriesDir) { @@ -67,7 +73,7 @@ def fetchSeriesBannersAndNfo(seriesDir, seasonDir, series, season) { } -def jobs = args.getFolders().findResults { dir -> +args.getFolders().each { dir -> def videos = dir.listFiles{ it.isVideo() } if (videos.isEmpty()) { return null @@ -78,9 +84,9 @@ def jobs = args.getFolders().findResults { dir -> if (query == null) { query = dir.dir.hasFile{ it.name =~ /Season/ && it.isDirectory() } ? dir.dir.name : dir.name - println "Failed to detect series name from video files -> Query by $query instead" } + println "$dir => Search by $query" def options = TheTVDB.search(query, Locale.ENGLISH) if (options.isEmpty()) { println "TV Series not found: $query" @@ -94,7 +100,6 @@ def jobs = args.getFolders().findResults { dir -> def seriesDir = [dir.dir, dir].sortBySimilarity(series.name, { it.name })[0] def season = sxe && sxe.season > 0 ? sxe.season : 1 - return { fetchSeriesBannersAndNfo(seriesDir, dir, series, season) } + println "$dir => $series" + fetchSeriesBannersAndNfo(seriesDir, dir, series, season) } - -parallel(jobs, 10)