gplayapi-ts
Version:
Google Play API wrapper in TypeScript
120 lines • 3.81 kB
JavaScript
import { GPNilPayloadError } from "../../errors";
import { ImageType } from "../../models/common";
import { URL_DETAILS } from "../constants";
class AppsEndpoint {
constructor(doAuthedReq) {
this.doAuthedReq = doAuthedReq;
}
async getAppDetails(packageName) {
const payload = await this.doAuthedReq(`${URL_DETAILS}?doc=${packageName}`, {
method: "GET"
});
if (!payload || !payload.detailsResponse) {
throw new 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 ImageType.CATEGORY_ICON:
app.categoryImage = image;
break;
case ImageType.APP_ICON:
app.iconImage = image;
break;
case ImageType.YOUTUBE_VIDEO_THUMBNAIL:
app.video = image;
break;
case ImageType.PLAY_STORE_PAGE_BACKGROUND:
app.coverImage = image;
break;
case 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);
}
}
}
}
}
export {
AppsEndpoint
};
//# sourceMappingURL=apps.mjs.map