UNPKG

google-photos-migrate

Version:

A tool to fix EXIF data and recover filenames from a Google Photos takeout.

31 lines (30 loc) 1.18 kB
import { pathExists } from 'fs-extra'; import { basename, join } from 'path'; import { photosDirs } from '../config/langs.js'; import { asyncGenToAsync } from '../ts.js'; import { NoPhotosDirError } from './NoPhotosDirError.js'; import { migrationArgsDefaults } from './migration-args.js'; import { restructureAndProcess } from './restructure-and-process.js'; export const migrateDirFull = asyncGenToAsync(migrateDirFullGen); export async function* migrateDirFullGen(args) { const migCtx = await migrationArgsDefaults(args); // Either /Google Photos or Takeout/Google Photos let googlePhotosDir = undefined; for (const photosDir of photosDirs) { const subdir = join(migCtx.inputDir, photosDir); if (await pathExists(subdir)) { googlePhotosDir = subdir; break; } if (basename(migCtx.inputDir) === photosDir) { googlePhotosDir = migCtx.inputDir; break; } } if (!googlePhotosDir) { yield new NoPhotosDirError(migCtx.inputDir); return; } yield* restructureAndProcess(googlePhotosDir, migCtx); migCtx.endExifTool && migCtx.exiftool.end(); }