gphotos-scraper
Version:
A tool to extract public url and metadata from shared album
40 lines • 2.08 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AlbumExtractor = void 0;
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const commander_1 = require("commander");
const exceptions_1 = require("../exceptions");
const services_1 = require("../services");
exports.AlbumExtractor = new commander_1.Command();
exports.AlbumExtractor.name("extract")
.description("Extract google photos data")
.argument("<url>", "album shared url")
.argument("<filename>", "output json filename")
.action((url, filename) => __awaiter(void 0, void 0, void 0, function* () {
const dir = node_path_1.default.dirname(filename);
const extname = node_path_1.default.extname(filename);
if (extname !== ".json") {
throw new exceptions_1.WrongFileExtException("file extension should be .json");
}
if (!node_fs_1.default.existsSync(dir)) {
node_fs_1.default.mkdirSync(dir);
}
const album = yield (0, services_1.extractAlbum)(url);
const jsonString = JSON.stringify(album);
node_fs_1.default.writeFileSync(filename, jsonString);
console.log(`album exported in ${filename}`);
}));
//# sourceMappingURL=album-extractor.js.map