Use new “downsize” package that was split out (to make testing edge cases easier)

pull/67/merge
Romain 7 years ago
parent afd3915778
commit ac67a08da9

@ -31,7 +31,6 @@
"exiftool-json-db": "~1.0.0",
"fs-extra": "^2.0.0",
"fs-readdir-recursive": "^1.0.0",
"gm": "^1.23.0",
"handlebars": "~4.0.5",
"less": "^2.7.1",
"lightgallery": "1.2.14",
@ -39,6 +38,7 @@
"moment": "^2.16.0",
"pad": "^1.0.2",
"progress": "~1.1.8",
"thumbsup-downsize": "^1.0.0",
"url-join": "^2.0.2",
"video.js": "^5.17.0",
"yargs": "^6.3.0"

@ -9,14 +9,10 @@ const File = require('./input/file')
const hierarchy = require('./model/hierarchy.js')
const mapper = require('./model/mapper')
const Media = require('./model/media')
const resize = require('./output-media/resize')
const tasks = require('./output-media/tasks')
const website = require('./output-website/website')
exports.build = function (opts) {
resize.sizes.thumb = opts.thumbSize
resize.sizes.large = opts.largeSize
fs.mkdirpSync(opts.output)
const databaseFile = path.join(opts.output, 'metadata.json')

@ -1,88 +0,0 @@
const async = require('async')
const childProcess = require('child_process')
const gm = require('gm')
const path = require('path')
exports.sizes = {
thumb: 120,
large: 1000
}
// Small square photo thumbnail
exports.photoSquare = function (task, callback) {
gm(task.src)
.autoOrient()
.coalesce()
.resize(exports.sizes.thumb, exports.sizes.thumb, '^')
.gravity('Center')
.crop(exports.sizes.thumb, exports.sizes.thumb)
.quality(90)
.write(task.dest, callback)
}
// Large photo
exports.photoLarge = function (task, callback) {
gm(task.src)
.autoOrient()
.resize(null, exports.sizes.large, '>')
.quality(90)
.write(task.dest, callback)
}
// Web-streaming friendly video
exports.videoWeb = function (task, callback) {
const args = ['-i', task.src, '-y', task.dest, '-f', 'mp4', '-vcodec', 'libx264', '-ab', '96k']
// AVCHD/MTS videos need a full-frame export to avoid interlacing artefacts
if (path.extname(task.src).toLowerCase() === '.mts') {
args.push('-vf', 'yadif=1', '-qscale:v', '4')
} else {
args.push('-vb', '1200k')
}
exec('ffmpeg', args, callback)
}
// Large video preview (before you click play)
exports.videoLarge = function (task, callback) {
async.series([
function (next) {
extractFrame(task, next)
},
function (next) {
exports.photoLarge({
src: task.dest,
dest: task.dest
}, next)
}
], callback)
}
// Small square video preview
exports.videoSquare = function (task, callback) {
async.series([
function (next) {
extractFrame(task, next)
},
function (next) {
exports.photoSquare({
src: task.dest,
dest: task.dest
}, next)
}
], callback)
}
function extractFrame (task, callback) {
const args = ['-itsoffset', '-1', '-i', task.src, '-ss', '0.1', '-vframes', 1, '-y', task.dest]
exec('ffmpeg', args, callback)
}
function exec (command, args, callback) {
const child = childProcess.spawn(command, args, {
stdio: 'ignore'
})
child.on('error', err => callback(err))
child.on('exit', (code, signal) => {
if (code > 0) callback(new Error(`${command} exited with code ${code}`))
else callback(null)
})
}

@ -1,25 +1,7 @@
const debug = require('debug')('thumbsup')
const fs = require('fs-extra')
const path = require('path')
const resize = require('./resize')
function copy (task, callback) {
fs.copy(task.src, task.dest, callback)
}
function symlink (task, callback) {
fs.symlink(task.src, task.dest, callback)
}
const ACTION_MAP = {
'fs:copy': copy,
'fs:symlink': symlink,
'photo:thumbnail': resize.photoSquare,
'photo:large': resize.photoLarge,
'video:thumbnail': resize.videoSquare,
'video:poster': resize.videoLarge,
'video:resized': resize.videoWeb
}
const debug = require('debug')('thumbsup')
const downsize = require('thumbsup-downsize')
/*
Return a list of task to build all required outputs (new or updated)
@ -27,6 +9,7 @@ const ACTION_MAP = {
*/
exports.create = function (opts, files, filterType) {
var tasks = {}
const actionMap = getActionMap(opts)
// accumulate all tasks into an object
// to remove duplicate destinations
files.filter(f => f.type === filterType).forEach(f => {
@ -35,7 +18,7 @@ exports.create = function (opts, files, filterType) {
var src = path.join(opts.input, f.path)
var dest = path.join(opts.output, f.output[out].path)
var destDate = modifiedDate(dest)
var action = ACTION_MAP[f.output[out].rel]
var action = actionMap[f.output[out].rel]
// ignore output files that don't have an action (e.g. existing links)
if (action && f.date > destDate) {
tasks[dest] = (done) => {
@ -59,3 +42,19 @@ function modifiedDate (filepath) {
return 0
}
}
function getActionMap (opts) {
const thumbSize = opts.thumbSize || 120
const largeSize = opts.largeSize || 1000
const thumbnail = { height: thumbSize, width: thumbSize }
const large = { width: largeSize }
return {
'fs:copy': (task, done) => fs.copy(task.src, task.dest, done),
'fs:symlink': (task, done) => fs.symlink(task.src, task.dest, done),
'photo:thumbnail': (task, done) => downsize.image(task.src, task.dest, thumbnail, done),
'photo:large': (task, done) => downsize.image(task.src, task.dest, large, done),
'video:thumbnail': (task, done) => downsize.still(task.src, task.dest, thumbnail, done),
'video:poster': (task, done) => downsize.still(task.src, task.dest, large, done),
'video:resized': (task, done) => downsize.video(task.src, task.dest, {}, done)
}
}

Loading…
Cancel
Save