google-photos-migrate
Version:
A tool to fix EXIF data and recover filenames from a Google Photos takeout.
35 lines (34 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.migrateDirFull = void 0;
exports.migrateDirFullGen = migrateDirFullGen;
const fs_extra_1 = require("fs-extra");
const path_1 = require("path");
const langs_1 = require("../config/langs");
const ts_1 = require("../ts");
const NoPhotosDirError_1 = require("./NoPhotosDirError");
const migration_args_1 = require("./migration-args");
const restructure_and_process_1 = require("./restructure-and-process");
exports.migrateDirFull = (0, ts_1.asyncGenToAsync)(migrateDirFullGen);
async function* migrateDirFullGen(args) {
const migCtx = await (0, migration_args_1.migrationArgsDefaults)(args);
// Either /Google Photos or Takeout/Google Photos
let googlePhotosDir = undefined;
for (const photosDir of langs_1.photosDirs) {
const subdir = (0, path_1.join)(migCtx.inputDir, photosDir);
if (await (0, fs_extra_1.pathExists)(subdir)) {
googlePhotosDir = subdir;
break;
}
if ((0, path_1.basename)(migCtx.inputDir) === photosDir) {
googlePhotosDir = migCtx.inputDir;
break;
}
}
if (!googlePhotosDir) {
yield new NoPhotosDirError_1.NoPhotosDirError(migCtx.inputDir);
return;
}
yield* (0, restructure_and_process_1.restructureAndProcess)(googlePhotosDir, migCtx);
migCtx.endExifTool && migCtx.exiftool.end();
}