diff --git a/amc.groovy b/amc.groovy index 038bb0d..560a8d2 100755 --- a/amc.groovy +++ b/amc.groovy @@ -385,11 +385,9 @@ groups.each{ group, files -> rfs.mapByFolder().each{ dir, fs -> def hasSeasonFolder = any{ dir =~ /Specials|Season.\d+/ || dir.parentFile.structurePathTail.listPath().size() > 0 }{ false } // MAY NOT WORK WELL FOR CERTAIN FORMATS - fs.findResults{ it.metadata }.findAll{ it.seriesInfo.database == 'TheTVDB' }.collect{ [name: it.seriesName, season: it.special ? 0 : it.season, id: it.seriesInfo.id] }.unique().each{ s -> - tryLogCatch { - log.fine "Fetching series artwork for [$s.name / Season $s.season] to [$dir]" - fetchSeriesArtworkAndNfo(hasSeasonFolder ? dir.parentFile : dir, dir, s.id, s.season, false, _args.language.locale) - } + fs.findResults{ it.metadata }.collect{ [series: it.seriesInfo, season: it.special ? 0 : it.season] }.unique().each{ s -> + log.fine "Fetching series artwork for [$s.series / Season $s.season] to [$dir]" + fetchSeriesArtworkAndNfo(hasSeasonFolder ? dir.parentFile : dir, dir, s.series, s.season, false, _args.language.locale) } } } diff --git a/artwork.tvdb.groovy b/artwork.tvdb.groovy index 64083b6..2858375 100644 --- a/artwork.tvdb.groovy +++ b/artwork.tvdb.groovy @@ -1,7 +1,7 @@ #!/usr/bin/env filebot -script -// sanity checks +// require at least 1 input folder if (args.size() == 0) { die "Illegal usage: no input" } @@ -53,7 +53,5 @@ args.eachMediaFolder{ dir -> def season = sxe && sxe.season > 0 ? sxe.season : 1 log.fine "$dir => $series" - tryLogCatch { - fetchSeriesArtworkAndNfo(seriesDir, dir, series.id, season, false, locale) - } + fetchSeriesArtworkAndNfo(seriesDir, dir, TheTVDB.getSeriesInfo(series, locale), season, false, locale) } diff --git a/lib/htpc.groovy b/lib/htpc.groovy index 63a00a2..c8db805 100644 --- a/lib/htpc.groovy +++ b/lib/htpc.groovy @@ -94,41 +94,43 @@ def rescanSickbeardSeries(server, port, apikey, seriesId) { /** * TheTVDB artwork/nfo helpers */ -def fetchSeriesBanner(outputFile, seriesId, bannerType, bannerType2, season, override, locale) { +def fetchSeriesBanner(outputFile, series, bannerType, bannerType2, season, override, locale) { if (outputFile.exists() && !override) { - log.finest "Banner already exists: $outputFile" return outputFile } - // select and fetch banner - def artwork = TheTVDB.getArtwork(seriesId, bannerType, locale) + def artwork = series.getArtwork(bannerType, locale) + if (artwork == null) { + return null + } + def banner = artwork.find{ it.matches(bannerType2, season) } if (banner == null) { - log.finest "Banner not found: $outputFile / $bannerType:$bannerType2" return null } + log.finest "Fetching $outputFile => $banner" return banner.url.saveAs(outputFile) } -def fetchSeriesFanart(outputFile, seriesId, type, season, override, locale) { +def fetchSeriesFanart(outputFile, series, type, season, override, locale) { if (outputFile.exists() && !override) { - log.finest "Fanart already exists: $outputFile" return outputFile } - def artwork = FanartTV.getArtwork(seriesId, "tv", locale) + def artwork = FanartTV.getArtwork(series.id, "tv", locale) def fanart = artwork.find{ it.matches(type, season) } if (fanart == null) { - log.finest "Fanart not found: $outputFile / $type" return null } + log.finest "Fetching $outputFile => $fanart" return fanart.url.saveAs(outputFile) } def fetchSeriesNfo(outputFile, i, locale) { - log.finest "Generate Series NFO: $i.name [$i.id]" + // generate nfo file + log.finest "Generate Series NFO: $i.name [$i]" def xml = XML { tvshow { title(i.name) @@ -146,49 +148,61 @@ def fetchSeriesNfo(outputFile, i, locale) { premiered(i.startDate) status(i.status) studio(i.network) - tvdb(id:i.id, 'http://www.thetvdb.com/?tab=series&id=' + i.id) - episodeguide { - url(post:'yes', cache:'auth.json', 'https://api.thetvdb.com/login?{"apikey":"439DFEBA9D3059C6","id":' + i.id + '}|Content-Type=application/json') - } + tvdb(id:i.id, 'https://thetvdb.com/series/' + i.slug) } } xml.saveAs(outputFile) } -def fetchSeriesArtworkAndNfo(seriesDir, seasonDir, seriesId, season, override = false, locale = Locale.ENGLISH) { +def getSeriesID(series, locale) { + if (series.database =~ /TheTVDB/) { + return TheTVDB.getSeriesInfo(series.id, locale) + } + if (series.database =~ /TheMovieDB/) { + def eid = TheMovieDB_TV.getExternalIds(series.id).'tvdb_id' + if (eid) { + return TheTVDB.getSeriesInfo(eid as int, locale) + } + } + return null +} + +def fetchSeriesArtworkAndNfo(seriesDir, seasonDir, series, season, override = false, locale = Locale.ENGLISH) { tryLogCatch { - // fetch nfo - def seriesInfo = TheTVDB.getSeriesInfo(seriesId, locale) - fetchSeriesNfo(seriesDir.resolve('tvshow.nfo'), seriesInfo, locale) + def sid = getSeriesID(series, locale) - // fetch series banner, fanart, posters, etc - ['680x1000', null].findResult{ fetchSeriesBanner(seriesDir.resolve('poster.jpg'), seriesId, 'poster', it, null, override, locale) } - ['graphical', null].findResult{ fetchSeriesBanner(seriesDir.resolve('banner.jpg'), seriesId, 'series', it, null, override, locale) } + if (sid == null) { + log.finest "Artwork not supported: $series" + return + } + + // fetch nfo + fetchSeriesNfo(seriesDir.resolve('tvshow.nfo'), sid, locale) - // fetch highest resolution fanart - ['1920x1080', '1280x720', null].findResult{ fetchSeriesBanner(seriesDir.resolve('fanart.jpg'), seriesId, 'fanart', it, null, override, locale) } + // series artwork + ['680x1000', null].findResult{ fetchSeriesBanner(seriesDir.resolve('poster.jpg'), sid, 'poster', it, null, override, locale) } + ['graphical', null].findResult{ fetchSeriesBanner(seriesDir.resolve('banner.jpg'), sid, 'series', it, null, override, locale) } + ['1920x1080', '1280x720', null].findResult{ fetchSeriesBanner(seriesDir.resolve('fanart.jpg'), sid, 'fanart', it, null, override, locale) } - // fetch season banners + // season artwork if (seasonDir != seriesDir) { - fetchSeriesBanner(seasonDir.resolve('poster.jpg'), seriesId, 'season', 'season', season, override, locale) - fetchSeriesBanner(seasonDir.resolve('banner.jpg'), seriesId, 'seasonwide', 'seasonwide', season, override, locale) - - // folder image (resuse series poster if possible) - copyIfPossible(seasonDir.resolve('poster.jpg'), seasonDir.resolve('folder.jpg')) + fetchSeriesBanner(seasonDir.resolve('poster.jpg'), sid, 'season', 'season', season, override, locale) + fetchSeriesBanner(seasonDir.resolve('banner.jpg'), sid, 'seasonwide', 'seasonwide', season, override, locale) } - // fetch fanart - ['hdclearart', 'clearart'].findResult{ type -> fetchSeriesFanart(seriesDir.resolve('clearart.png'), seriesId, type, null, override, locale) } - ['hdtvlogo', 'clearlogo'].findResult{ type -> fetchSeriesFanart(seriesDir.resolve('logo.png'), seriesId, type, null, override, locale) } - fetchSeriesFanart(seriesDir.resolve('landscape.jpg'), seriesId, 'tvthumb', null, override, locale) + // external series artwork + ['hdclearart', 'clearart'].findResult{ type -> fetchSeriesFanart(seriesDir.resolve('clearart.png'), sid, type, null, override, locale) } + ['hdtvlogo', 'clearlogo'].findResult{ type -> fetchSeriesFanart(seriesDir.resolve('logo.png'), sid, type, null, override, locale) } + fetchSeriesFanart(seriesDir.resolve('landscape.jpg'), sid, 'tvthumb', null, override, locale) - // fetch season fanart + // external season artwork if (seasonDir != seriesDir) { - fetchSeriesFanart(seasonDir.resolve('landscape.jpg'), seriesId, 'seasonthumb', season, override, locale) + fetchSeriesFanart(seasonDir.resolve('landscape.jpg'), sid, 'seasonthumb', season, override, locale) } - // folder image (resuse series poster if possible) + // folder image (resuse series / season poster if possible) + copyIfPossible(seasonDir.resolve('poster.jpg'), seasonDir.resolve('folder.jpg')) copyIfPossible(seriesDir.resolve('poster.jpg'), seriesDir.resolve('folder.jpg')) } }