diff options
Diffstat (limited to 'app/relay')
| -rw-r--r-- | app/relay/modules/pix2pixhd.js | 27 | ||||
| -rw-r--r-- | app/relay/remote.js | 10 | ||||
| -rw-r--r-- | app/relay/runner.js | 104 |
3 files changed, 114 insertions, 27 deletions
diff --git a/app/relay/modules/pix2pixhd.js b/app/relay/modules/pix2pixhd.js index 4c169e8..02431e5 100644 --- a/app/relay/modules/pix2pixhd.js +++ b/app/relay/modules/pix2pixhd.js @@ -122,6 +122,32 @@ const live = { '--norm', 'batch', ] }, + listen: (task, res, i) => { + // relay the new dataset name from youtube-dl or w/e + const lines = res.split('\n') + for (let line of lines) { + console.log(line) + if ( line.match(/^final result: /) ) { + let tag = line.split(': ')[1].trim() + task.dataset = tag + console.log(">>>>>> recording live to", tag) + return { type: 'progress', action: 'resolve_dataset', task } + } + } + return null + }, + after: 'render', +} +const render = { + type: 'perl', + script: 'dir-to-movie.pl', + params: (task) => { + return [ + '--tag', task.dataset, + '--module', task.module, + '--endpoint', process.env.API_REMOTE + '/api/folder/' + task.opt.folder_id + '/upload/', + ] + } } export default { @@ -132,5 +158,6 @@ export default { train, generate, live, + render, } } diff --git a/app/relay/remote.js b/app/relay/remote.js index 79fdcfc..cf941b1 100644 --- a/app/relay/remote.js +++ b/app/relay/remote.js @@ -115,6 +115,16 @@ remote.on('system', (data) => { }) }) break + case 'list_sequences': + runner.list_sequences(data.payload, sequences => { + remote.emit('system_res', { + type: 'list_sequences', + dir: data.payload, + uuid: data.uuid, + sequences, + }) + }) + break case 'upload_file': runner.upload_file(data.payload, (error, stdout, stderr) => { remote.emit('system_res', { diff --git a/app/relay/runner.js b/app/relay/runner.js index 54f5a94..431ed75 100644 --- a/app/relay/runner.js +++ b/app/relay/runner.js @@ -7,6 +7,7 @@ import { set_connected } from './rpc' import uuidv1 from 'uuid/v1' import * as fs from 'fs' import * as path from 'path' +import readdir from 'fs-readdir-promise' import * as q from './queue' @@ -120,31 +121,31 @@ export function build_params(module, activity, task) { } } -export function run_system_command(cmd, cb) { - console.log('running system command:', cmd.cmd) - switch(cmd.cmd) { +export function run_system_command(opt, cb) { + console.log('running system command:', opt.cmd) + switch(opt.cmd) { case 'nvidia-smi': case 'uptime': case 'w': - execFile(cmd.cmd, [], cb) + execFile(opt.cmd, [], cb) break case 'ps': - execFile(cmd.cmd, ['au'], cb) + execFile('ps', ['au'], cb) break case 'df': execFile('df', ['-h'], cb) break case 'ls': - list_directory(cmd, cb) + list_directory(opt, cb) break case 'du': - disk_usage(cmd, cb) + disk_usage(opt, cb) break - case 'list_results': - list_results(cmd, cb) + case 'list_sequences': + list_sequences(opt, cb) break case 'dir_to_video': - dir_to_video(cmd, cb) + dir_to_video(opt, cb) break default: cb({ error: 'no such command' }) @@ -152,15 +153,20 @@ export function run_system_command(cmd, cb) { } } -export function list_directory(opt, cb) { +export function module_dir(opt, dir){ if (!opt.module || ! modules[opt.module]) { - cb([]) + return null } const module = modules[opt.module] if (!module) { - return cb([]) + return null } - const dir = path.join(module.cwd, opt.dir.replace(/\.\.?\//g, '')) + return path.join(module.cwd, dir.replace(/\.\.?\//g, '')) +} + +export function list_directory(opt, cb) { + const dir = module_dir(opt, opt.dir) + if (!dir) return cb([]) fs.readdir(dir, (err, files) => { const statPromises = (files || []).filter(f => f[0] !== '.').map(f => { return new Promise((resolve, reject) => { @@ -177,35 +183,79 @@ export function list_directory(opt, cb) { }) }) Promise.all(statPromises).then(stats => { - cb(stats) + cb(stats, dir) }).catch(error => { cb(error) }) }) } -export function list_results(opt, cb) { - // list the contents of the results directory for the module - // filter out non-directories - // for each directory - // list it and count the files and sum their sizes and print the first filename and `identify` it... - cb([]) +// list the contents of a directory of sequences +export function list_sequences(opt, cb) { + list_directory(opt, (files, root_dir) => { + // console.log(files, root_dir) + const sequencePromises = files.filter(d => !!d.dir).map(f => { + return list_sequence(opt, f, root_dir) + }) + Promise.all(sequencePromises).then(cb).catch(error => { + console.error(error) + cb([]) + }) + }) +} +export function list_sequence(opt, f, root_dir) { + return new Promise( (resolve, reject) => { + let sequence = { + name: f.name, + date: f.date, + size: f.size, + frame: null, + count: 0, + } + readdir(path.join(root_dir, f.name)).then(files => { + if (! files.length) { + return resolve(sequence) + } + const middle_file = files[Math.floor(files.length/2)] + if (! middle_file) return resolve(sequence) + sequence.frame = { + prefix: middle_file.split('_')[0], + } + sequence.count = files.length + // console.log(sequence.count) + return stat_promise(path.join(root_dir, f.name, middle_file)) + }).then(stat => { + sequence.frame.date = stat.date + sequence.frame.size = stat.size + resolve(sequence) + }).catch(err => reject(err)) + }) +} + +export function stat_promise(fn) { + return new Promise((resolve, reject) => { + fs.stat(fn, (err, stat={}) => { + if (err) reject(err) + resolve(stat) + }) + }) } export function dir_to_video(opt, db) { + const dir = module_dir(opt, opt.dir) + if (!dir) return cb([]) // input: the path (in results/) you want as a video // output: the path (in renders/) that contains the video // run the dir to video script with CWD as the directory and first input as ../renders plus the directory name // list the file in renders... - cb([]) + execFile('./bin/dir_to_video.pl', params, { + cwd: module.cwd, + }, cb) } export function disk_usage(opt, cb) { - if (!opt.module || ! modules[opt.module]) { - cb([]) - } - const module = modules[opt.module] - const dir = path.join(module.cwd, opt.dir.replace(/\.\.?\//g, '')) + const dir = module_dir(opt, opt.dir) + if (!dir) return cb([]) execFile('du', ['-d', 1, dir], cb) } |
