google-photos-migrate
Version:
A tool to fix EXIF data and recover filenames from a Google Photos takeout.
84 lines (83 loc) • 3.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.migrateFlat = void 0;
const cmd_ts_1 = require("cmd-ts");
const exiftool_vendored_1 = require("exiftool-vendored");
const fs_extra_1 = require("fs-extra");
const migrate_flat_1 = require("../dir/migrate-flat");
const is_empty_dir_1 = require("../fs/is-empty-dir");
const MediaMigrationError_1 = require("../media/MediaMigrationError");
const common_1 = require("./common");
exports.migrateFlat = (0, cmd_ts_1.command)({
name: 'google-photos-migrate-flat',
args: {
inputDir: (0, cmd_ts_1.positional)({
type: cmd_ts_1.string,
displayName: 'input_dir',
description: 'The path to your "Google Photos" directory.',
}),
outputDir: (0, cmd_ts_1.positional)({
type: cmd_ts_1.string,
displayName: 'output_dir',
description: 'The path to your flat output directory.',
}),
...common_1.commonArgs,
},
handler: async ({ inputDir, outputDir, errorDir, exiftoolArgs, force, timeout, skipCorrections, renameEmpty, verbose, }) => {
const errs = [];
const checkErrs = () => {
if (errs.length !== 0) {
errs.forEach((e) => console.error(e));
process.exit(1);
}
};
if (!(await (0, fs_extra_1.pathExists)(inputDir))) {
errs.push(`The specified google directory does not exist: ${inputDir}`);
}
if (!(await (0, fs_extra_1.pathExists)(outputDir))) {
errs.push(`The specified output directory does not exist: ${outputDir}`);
}
if (!(await (0, fs_extra_1.pathExists)(errorDir))) {
errs.push(`The specified error directory does not exist: ${errorDir}`);
}
checkErrs();
if (!force && !(await (0, is_empty_dir_1.isEmptyDir)(outputDir))) {
errs.push('The output directory is not empty. Pass "-f" to force the operation.');
}
if (!force && !(await (0, is_empty_dir_1.isEmptyDir)(errorDir))) {
errs.push('The error directory is not empty. Pass "-f" to force the operation.');
}
if (await (0, is_empty_dir_1.isEmptyDir)(inputDir)) {
errs.push(`Nothing to do, the source directory is empty: ${inputDir}`);
}
checkErrs();
console.log('Started migration.');
const migGen = (0, migrate_flat_1.migrateDirFlatGen)({
inputDir,
outputDir,
errorDir,
log: console.log,
warnLog: console.error,
verboseLog: verbose ? console.log : undefined,
exiftool: new exiftool_vendored_1.ExifTool({ taskTimeoutMillis: timeout }),
exiftoolArgs,
endExifTool: true,
skipCorrections,
renameEmpty,
});
const counts = { err: 0, suc: 0 };
for await (const result of migGen) {
if (result instanceof MediaMigrationError_1.MediaMigrationError) {
console.error(`Error: ${result}`);
counts.err++;
continue;
}
else {
counts.suc++;
}
}
console.log(`Done! Processed ${counts.suc + counts.err} files.`);
console.log(`Files migrated: ${counts.suc}`);
console.log(`Files failed: ${counts.err}`);
},
});