1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-22 07:48:52 -05:00

Experiment with artwork thumbnail support

This commit is contained in:
Reinhard Pointner 2019-05-16 19:55:10 +07:00
parent a05ab703ff
commit 889d411c44

View File

@ -3,6 +3,10 @@
import static org.apache.commons.io.FileUtils.* import static org.apache.commons.io.FileUtils.*
scaleFactor = [1, 2]
thumbnailSize = [48, 48]
void ls(f) { void ls(f) {
if (f.exists()) { if (f.exists()) {
log.info "$f (${byteCountToDisplaySize(f.length())})" log.info "$f (${byteCountToDisplaySize(f.length())})"
@ -17,20 +21,26 @@ File getOriginalPath(db, id) {
} }
File getThumbnailPath(db, id) { File getThumbnailPath(db, id, scale) {
return _args.outputPath.resolve("images/${db}/thumb/poster/${id}.png") def n = id as String
if (scale != 1) {
n += '@' + scale + 'x'
}
return _args.outputPath.resolve("images/${db}/thumb/poster/${n}.png")
} }
void createThumbnail(original, thumb) { void createThumbnail(original, thumb, scale) {
thumb.dir.mkdirs() thumb.dir.mkdirs()
execute 'convert', '-strip', original, '-thumbnail', '48x48', '-gravity', 'center', '-background', 'transparent', '-extent', '48x48', 'PNG8:' + thumb
def size = thumbnailSize*.multiply(scale).join('x')
execute 'convert', '-strip', original, '-thumbnail', size, '-gravity', 'center', '-background', 'transparent', '-extent', size, 'PNG8:' + thumb
} }
void createIndexFile(db) { void createIndexFile(db) {
def indexFile = _args.outputPath.resolve("images/${db}/thumb/poster/index.txt") def indexFile = _args.outputPath.resolve("images/${db}/thumb/poster/index.txt")
def index = indexFile.dir.listFiles{ it.image }.collect{ it.nameWithoutExtension as int }.toSorted() def index = indexFile.dir.listFiles{ it.name =~ /\d+/ }.collect{ it.nameWithoutExtension as int }.toSorted()
index.join('\n').saveAs(indexFile) index.join('\n').saveAs(indexFile)
execute 'xz', indexFile, '--force', '--keep' execute 'xz', indexFile, '--force', '--keep'
@ -46,55 +56,57 @@ void build(ids, section, db, query) {
def files = [] def files = []
ids.each{ id -> ids.each{ id ->
def original = getOriginalPath(section, id) scaleFactor.each { scale ->
def thumb = getThumbnailPath(section, id) def original = getOriginalPath(section, id)
def thumb = getThumbnailPath(section, id, scale)
if (thumb.exists()) { if (thumb.exists()) {
log.finest "[SKIP] $id" log.finest "[SKIP] $id"
return return
}
if (original.length() == 0 && original.exists() && System.currentTimeMillis() - original.lastModified() > 90 * 24 * 60 * 60 * 1000) {
log.finest "[SKIP] $id"
return
}
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
}
} }
artwork?.findResult{ a -> if (original.length() == 0 && original.exists() && System.currentTimeMillis() - original.lastModified() > 90 * 24 * 60 * 60 * 1000) {
return retry(2, 60000) { log.finest "[SKIP] $id"
return
}
if (original.length() == 0 || !original.exists()) {
def artwork = retry(2, 60000) {
try { try {
log.fine "Fetch $a" return db.getArtwork(id, query, Locale.ENGLISH)
return a.url.saveAs(original)
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
log.warning "[IMAGE NOT FOUND] $e" log.warning "[ARTWORK NOT FOUND] $e"
return null return null
} }
} }
artwork?.findResult{ a ->
return retry(2, 60000) {
try {
log.fine "Fetch $a"
return a.url.saveAs(original)
} catch (FileNotFoundException e) {
log.warning "[IMAGE NOT FOUND] $e"
return null
}
}
}
// create empty placeholder if there is no artwork
if (original.length() == 0 || !original.exists()) {
original.createNewFile()
original.setLastModified(System.currentTimeMillis())
}
ls original
} }
// create empty placeholder if there is no artwork if (original.length() > 0 && !thumb.exists()) {
if (original.length() == 0 || !original.exists()) { createThumbnail(original, thumb, scale)
original.createNewFile() files << thumb
original.setLastModified(System.currentTimeMillis())
ls thumb
} }
ls original
}
if (original.length() > 0 && !thumb.exists()) {
createThumbnail(original, thumb)
files << thumb
ls thumb
} }
} }