2019-05-01 06:14:42 -04:00
|
|
|
#!/usr/bin/env filebot -script
|
|
|
|
|
|
|
|
import static org.apache.commons.io.FileUtils.*
|
|
|
|
|
|
|
|
|
|
|
|
void ls(f) {
|
2019-05-01 09:10:11 -04:00
|
|
|
if (f.exists()) {
|
|
|
|
log.info "$f (${byteCountToDisplaySize(f.length())})"
|
|
|
|
} else {
|
|
|
|
log.warning "[FILE NOT FOUND] $f"
|
|
|
|
}
|
2019-05-01 06:14:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-01 16:03:05 -04:00
|
|
|
File getOriginalPath(db, id) {
|
|
|
|
return _args.outputPath.resolve("images/${db}/original/poster/${id}.jpg")
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
File getThumbnailPath(db, id) {
|
|
|
|
return _args.outputPath.resolve("images/${db}/thumb/poster/${id}.png")
|
|
|
|
}
|
2019-05-01 06:14:42 -04:00
|
|
|
|
|
|
|
|
2019-05-01 16:03:05 -04:00
|
|
|
void createThumbnail(original, thumb) {
|
2019-05-03 08:02:18 -04:00
|
|
|
thumb.dir.mkdirs()
|
2019-05-04 08:16:31 -04:00
|
|
|
execute 'convert', original, '-strip', '-thumbnail', '48x48>', 'PNG8:' + thumb
|
2019-05-01 16:03:05 -04:00
|
|
|
}
|
2019-05-01 06:14:42 -04:00
|
|
|
|
|
|
|
|
2019-05-04 06:26:08 -04:00
|
|
|
void printIndex(db) {
|
|
|
|
def files = getThumbnailPath(db, 0).dir.listFiles()
|
|
|
|
log.info "[INDEX] $db ${files.size()} (${byteCountToDisplaySize(files*.length().sum())})"
|
2019-05-01 16:03:05 -04:00
|
|
|
}
|
2019-05-01 06:33:35 -04:00
|
|
|
|
2019-05-01 06:14:42 -04:00
|
|
|
|
2019-05-01 16:03:05 -04:00
|
|
|
|
2019-05-04 06:26:08 -04:00
|
|
|
|
2019-05-01 16:03:05 -04:00
|
|
|
void build(ids, section, db, query) {
|
|
|
|
ids.each{ id ->
|
|
|
|
def original = getOriginalPath(section, id)
|
|
|
|
def thumb = getThumbnailPath(section, id)
|
|
|
|
|
2019-05-04 06:46:49 -04:00
|
|
|
if (thumb.exists()) {
|
|
|
|
log.finest "[SKIP] $id"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-05-04 08:26:43 -04:00
|
|
|
if (original.length() == 0 && original.exists() && System.currentTimeMillis() - original.lastModified() > 90 * 24 * 60 * 60 * 1000) {
|
2019-05-02 15:59:49 -04:00
|
|
|
log.finest "[SKIP] $id"
|
2019-05-01 16:03:05 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-05-04 08:38:26 -04:00
|
|
|
if (original.length() == 0 || !original.exists()) {
|
|
|
|
def artwork = retry(2, 60000) {
|
|
|
|
try {
|
|
|
|
return db.getArtwork(id, query, Locale.ENGLISH)
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
log.warning "[ARTWORK NOT FOUND] $e"
|
|
|
|
return null
|
|
|
|
}
|
2019-05-03 08:02:18 -04:00
|
|
|
}
|
|
|
|
|
2019-05-04 08:38:26 -04:00
|
|
|
artwork?.findResult{ a ->
|
2019-05-01 16:03:05 -04:00
|
|
|
return retry(2, 60000) {
|
|
|
|
try {
|
|
|
|
log.fine "Fetch $a"
|
|
|
|
return a.url.saveAs(original)
|
|
|
|
} catch (FileNotFoundException e) {
|
2019-05-03 08:02:18 -04:00
|
|
|
log.warning "[IMAGE NOT FOUND] $e"
|
2019-05-01 16:03:05 -04:00
|
|
|
return null
|
|
|
|
}
|
2019-05-01 10:34:23 -04:00
|
|
|
}
|
2019-05-01 09:10:11 -04:00
|
|
|
}
|
2019-05-04 06:26:08 -04:00
|
|
|
|
|
|
|
// create empty placeholder if there is no artwork
|
2019-05-04 08:38:26 -04:00
|
|
|
if (original.length() == 0 || !original.exists()) {
|
2019-05-04 06:26:08 -04:00
|
|
|
original.createNewFile()
|
2019-05-04 08:38:26 -04:00
|
|
|
original.setLastModified(System.currentTimeMillis())
|
2019-05-04 06:26:08 -04:00
|
|
|
}
|
|
|
|
|
2019-05-01 16:03:05 -04:00
|
|
|
ls original
|
2019-05-01 09:10:11 -04:00
|
|
|
}
|
2019-05-01 06:14:42 -04:00
|
|
|
|
2019-05-01 16:29:23 -04:00
|
|
|
if (original.length() > 0 && !thumb.exists()) {
|
2019-05-01 16:03:05 -04:00
|
|
|
createThumbnail(original, thumb)
|
2019-05-01 16:29:23 -04:00
|
|
|
ls thumb
|
2019-05-01 16:03:05 -04:00
|
|
|
}
|
2019-05-01 06:14:42 -04:00
|
|
|
}
|
2019-05-01 06:33:35 -04:00
|
|
|
|
2019-05-04 06:26:08 -04:00
|
|
|
printIndex(section)
|
2019-05-01 06:14:42 -04:00
|
|
|
}
|
2019-05-01 06:33:35 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-05-01 16:03:05 -04:00
|
|
|
|
2019-05-02 11:10:38 -04:00
|
|
|
build(MediaDetection.seriesIndex.object.id as HashSet, 'thetvdb', TheTVDB, 'poster')
|
|
|
|
build(MediaDetection.movieIndex.object.tmdbId as HashSet, 'themoviedb', TheMovieDB, 'posters')
|