/** * Google Play Store - Full App Metadata, Reviews, Rating & Screenshots Scraper * * Download & Run CLI: * curl -sL "https://code.vamxapi.my.id/snippet/raw/playstore-scraper" -o playstore-scraper.js * node playstore-scraper.js "com.flow.mobile" * node playstore-scraper.js "https://play.google.com/store/apps/details?id=com.flow.mobile" * * Author: Vamz Spectre / VamxAPI */ function decodeHtmlEntities(str) { if (!str) return ""; return str .replace(/&/g, "&") .replace(/</g, "<") .replace(/>/g, ">") .replace(/"/g, "\"") .replace(/'/g, "'") .replace(/ /g, " "); } function cleanHtml(html) { if (!html) return ""; return decodeHtmlEntities( html.replace(//gi, "\n").replace(/<[^>]+>/g, "").trim() ); } function formatNumber(num) { if (!num) return "0"; if (num >= 1000000) return (num / 1000000).toFixed(1).replace(/\.0$/, "") + "M"; if (num >= 1000) return (num / 1000).toFixed(1).replace(/\.0$/, "") + "K"; return num.toString(); } /** * Scrape detail aplikasi Google Play Store secara lengkap & real-time * @param {string} input - URL Play Store atau Package ID (contoh: com.flow.mobile) * @param {Object} [options] - Opsi konfigurasi (hl: bahasa, gl: negara) * @returns {Promise} Metadata aplikasi Google Play Store */ async function scrapePlayStore(input, options = {}) { if (!input || typeof input !== "string" || !input.trim()) { throw new Error("Parameter URL Google Play Store atau Package ID wajib disertakan."); } const raw = input.trim(); const pkgMatch = raw.match(/[?&]id=([a-zA-Z0-9._]+)/) || raw.match(/details\/([a-zA-Z0-9._]+)/) || raw.match(/^([a-zA-Z0-9._]+)$/); if (!pkgMatch) { throw new Error("Format Package ID atau URL Google Play Store tidak valid. Contoh: com.flow.mobile"); } const packageId = pkgMatch[1]; const hl = options.hl || "id"; const gl = options.gl || "ID"; const targetUrl = `https://play.google.com/store/apps/details?id=${encodeURIComponent(packageId)}&hl=${hl}&gl=${gl}`; const res = await fetch(targetUrl, { headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", "Accept-Language": `${hl}-${gl},${hl};q=0.9,en-US;q=0.8,en;q=0.7`, "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" } }); if (!res.ok) { if (res.status === 404) { throw new Error(`Aplikasi dengan package ID "${packageId}" tidak ditemukan di Google Play Store.`); } throw new Error(`Google Play Store merespons status HTTP ${res.status}.`); } const html = await res.text(); // 1. Ekstrak Structured Data Schema (ld+json) let ld = {}; const ldMatch = html.match(/