gphotos-scraper
Version:
A tool to extract public url and metadata from shared album
48 lines • 2.2 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.getPhotos = void 0;
const axios_1 = __importDefault(require("axios"));
const mime_types_1 = require("mime-types");
const RPCID = 'fDcn4b';
const getPhotos = (key, photoIds) => __awaiter(void 0, void 0, void 0, function* () {
const queryData = photoIds.map((photoId) => [RPCID, JSON.stringify([photoId, null, key])]);
const bodyData = `f.req=${JSON.stringify([queryData])}`;
const res = yield axios_1.default.post('https://photos.google.com/_/PhotosUi/data/batchexecute', bodyData, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
},
});
const data = res.data.replace(')]}\'', '');
const list = JSON.parse(data);
return list.filter((item) => item[1] === RPCID)
.map((item) => {
const [, , responseText] = item;
const jsonObj = JSON.parse(responseText);
const [id, description, filename, createdAt, , size, width, height] = jsonObj[0];
const mimeType = `${(0, mime_types_1.lookup)(filename)}`;
return {
id,
description,
filename,
createdAt,
size,
width,
height,
mimeType,
};
});
});
exports.getPhotos = getPhotos;
//# sourceMappingURL=getPhotos.js.map