UNPKG

gplayapi-ts

Version:
144 lines 4.92 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var apps_exports = {}; __export(apps_exports, { AppsEndpoint: () => AppsEndpoint }); module.exports = __toCommonJS(apps_exports); var import_errors = require("../../errors"); var import_common = require("../../models/common"); var import_constants = require("../constants"); class AppsEndpoint { constructor(doAuthedReq) { this.doAuthedReq = doAuthedReq; } async getAppDetails(packageName) { const payload = await this.doAuthedReq(`${import_constants.URL_DETAILS}?doc=${packageName}`, { method: "GET" }); if (!payload || !payload.detailsResponse) { throw new import_errors.GPNilPayloadError(); } return this.buildAppFromItem(payload.detailsResponse.item); } async bulkDetails(packageNames) { const apps = []; for (const packageName of packageNames) { try { const app = await this.getAppDetails(packageName); apps.push(app); } catch (error) { console.warn(`Failed to fetch details for ${packageName}:`, error); } } return apps; } buildAppFromItem(item) { const details = item.details?.appDetails; const app = { packageName: item.id, categoryId: item.categoryId || 0, displayName: item.title || "", description: item.descriptionHtml || "", shortDescription: item.promotionalDescription || "", shareUrl: item.shareUrl || "", versionName: details?.versionString || "", versionCode: details?.versionCode || 0, categoryName: details?.categoryName || "", size: details?.infoDownloadSize || 0, downloadString: details?.downloadLabelAbbreviated || "", changes: details?.recentChangesHtml || "", containsAds: !!details?.installNotes, earlyAccess: !!details?.earlyAccessInfo, developerName: details?.developerName || item.creator || "", targetSdk: details?.targetSdkVersion || 0, updatedOn: details?.infoUpdatedOn || "", offerDetails: {}, offerType: 0, price: "", screenshots: [], isFree: true, isSystem: false }; if (item.offer && item.offer.length > 0) { const offer = item.offer[0]; if (offer) { app.offerType = offer.offerType || 0; app.isFree = (offer.micros || 0) === 0; app.price = offer.formattedAmount || ""; } } if (details?.instantLink) { app.instantAppLink = details.instantLink; } this.parseAppInfo(app, item); this.parseStreamUrls(app, item); this.parseImages(app, item); return app; } parseAppInfo(app, item) { if (item.appInfo) { app.appInfo = { appInfoMap: {} }; for (const section of item.appInfo.section || []) { if (section.label && section.container?.description) { app.appInfo.appInfoMap[section.label] = section.container.description; } } } } parseStreamUrls(app, item) { if (item.annotations) { app.liveStreamUrl = item.annotations.liveStreamUrl; app.promotionStreamUrl = item.annotations.promotionStreamUrl; } } parseImages(app, item) { for (const image of item.image || []) { switch (image.imageType) { case import_common.ImageType.CATEGORY_ICON: app.categoryImage = image; break; case import_common.ImageType.APP_ICON: app.iconImage = image; break; case import_common.ImageType.YOUTUBE_VIDEO_THUMBNAIL: app.video = image; break; case import_common.ImageType.PLAY_STORE_PAGE_BACKGROUND: app.coverImage = image; break; case import_common.ImageType.APP_SCREENSHOT: app.screenshots.push(image); break; } } if (app.screenshots.length === 0 && item.annotations?.sectionImage) { for (const imageContainer of item.annotations.sectionImage.imageContainer || []) { if (imageContainer.image) { app.screenshots.push(imageContainer.image); } } } } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { AppsEndpoint }); //# sourceMappingURL=apps.js.map