UNPKG

gphotos-scraper

Version:

A tool to extract public url and metadata from shared album

74 lines 3.04 kB
"use strict"; 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPhotos = void 0; const mime_types_1 = require("mime-types"); const axiosClient_1 = require("./axiosClient"); const RPCID = "fDcn4b"; const BASE_URL = "https://photos.google.com/_/PhotosUi/data/batchexecute"; const getPhotos = (key, photoIds) => __awaiter(void 0, void 0, void 0, function* () { const queryData = photoIds.map((photoId) => [ RPCID, JSON.stringify([photoId, null, key]), ]); const params = new URLSearchParams(); params.append("f.req", JSON.stringify([queryData])); const { data } = yield axiosClient_1.apiClient.post(BASE_URL, params, { headers: { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", }, }); // Security: Anti-hijacking cleanup const cleanData = data.replace(/^\)\]\}'/, ""); // DEBUG: Log raw RPC response const fs = require('fs'); fs.writeFileSync('tmp/debug_rpc_photos.txt', cleanData); let list; try { list = JSON.parse(cleanData); } catch (_a) { return []; } // Optimized single-pass reduction return list.reduce((acc, item) => { if ((item === null || item === void 0 ? void 0 : item[1]) !== RPCID) return acc; try { const responseText = item === null || item === void 0 ? void 0 : item[2]; if (!responseText) return acc; const jsonObj = JSON.parse(responseText); const photoData = jsonObj === null || jsonObj === void 0 ? void 0 : jsonObj[0]; if (!photoData) return acc; const [id, description, filename, createdAt, , size, width, height] = photoData; const mimeType = (0, mime_types_1.lookup)(filename) || "application/octet-stream"; acc.push({ id, url: "", // Will be populated in extractAlbum description, filename, createdAt, size, width, height, mimeType, }); } catch (_a) { // Silently ignore parsing failures for individual items } return acc; }, []); }); exports.getPhotos = getPhotos; //# sourceMappingURL=getPhotos.js.map