UNPKG

google-photos-migrate

Version:

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

38 lines (37 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.indexJsonFiles = indexJsonFiles; const promises_1 = require("fs/promises"); const path_1 = require("path"); const langs_1 = require("../config/langs"); const walk_dir_1 = require("../fs/walk-dir"); const MAX_BASE_LENGTH = 51; async function indexJsonFiles(googleDir) { const titleJsonMap = new Map(); for await (const jsonPath of (0, walk_dir_1.walkDir)(googleDir)) { if (!jsonPath.endsWith('.json')) continue; let title; try { const data = JSON.parse((await (0, promises_1.readFile)(jsonPath)).toString()); title = data.title; } catch (e) { } if (typeof title !== 'string') continue; const potTitles = new Set(); const ext = (0, path_1.extname)(title); const woExt = title.slice(0, -ext.length); const maxWoExt = MAX_BASE_LENGTH - ext.length; potTitles.add(woExt.slice(0, maxWoExt) + ext); for (const suffix of langs_1.editedSuffices) { potTitles.add((woExt + `-${suffix}`).slice(0, maxWoExt) + ext); } for (const potTitle of potTitles) { const jsonPaths = titleJsonMap.get(potTitle) ?? []; jsonPaths.push(jsonPath); titleJsonMap.set(potTitle, jsonPaths); } } return titleJsonMap; }