Skip to content

Commit

Permalink
Improved support for --def artwork=y seriesDB=TheMovieDB::TV
Browse files Browse the repository at this point in the history
  • Loading branch information
rednoah committed Oct 10, 2021
1 parent 1d2b171 commit b95609b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 45 deletions.
8 changes: 3 additions & 5 deletions amc.groovy
Expand Up @@ -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)
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions 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"
}
Expand Down Expand Up @@ -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)
}
86 changes: 50 additions & 36 deletions lib/htpc.groovy
Expand Up @@ -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)
Expand All @@ -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'))
}
}
Expand Down

0 comments on commit b95609b

Please sign in to comment.