Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Developer method, typo in extractDeveloperId #560

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/developer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const scriptData = require('./utils/scriptData');
const { BASE_URL } = require('./constants');
const request = require('./utils/request');
const R = require('ramda');
const processPages = require('./utils/processPages');
const { processPages } = require('./utils/processPages');

function buildUrl (opts) {
const { lang, devId, country } = opts;
Expand Down Expand Up @@ -56,8 +56,9 @@ function developer (opts) {

const INITIAL_MAPPINGS = {
cluster: ['ds:3', 0, 1, 0, 0, 3, 4, 2],
apps: ['ds:3', 0, 1, 0, 0, 0],
token: ['ds:3', 0, 1, 0, 0, 7, 1]
apps: ['ds:3', 0, 1, 0, 22, 0],
appsAlt: ['ds:3', 0, 1, 0, 21, 0],
token: ['ds:3', 0, 1, 0, 22, 1, 3, 1]
};

function parseDeveloperApps (developerObject, opts) {
Expand Down
98 changes: 94 additions & 4 deletions lib/search.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
'use strict';

const R = require('ramda');
const url = require('url');
const request = require('./utils/request');
const { BASE_URL } = require('./constants');
const processPages = require('./utils/processPages');
const { processFullDetailApps, checkFinished } = require('./utils/processPages');
const appList = require('./utils/appList');
const scriptData = require('./utils/scriptData');

/*
* Make the first search request as in the browser and call `checkfinished` to
Expand All @@ -25,14 +29,100 @@ function initialRequest (opts) {
const url = `${BASE_URL}/store/search?c=apps&q=${opts.term}&hl=${opts.lang}&gl=${opts.country}&price=${opts.price}`;
return request(Object.assign({ url }, opts.requestOptions), opts.throttle)
.then(skipClusterPage)
.then((html) => processPages(html, opts, [], INITIAL_MAPPINGS));
.then((html) => processFirstPage(html, opts, [], INITIAL_MAPPINGS));
}

async function processFirstPage (html, opts, savedApps, mappings) {
if (R.is(String, html)) {
html = scriptData.parse(html);
}

const mainAppMapping = {
title: [16, 2, 0, 0],
appId: [16, 11, 0, 0],
url: {
path: [17, 0, 0, 4, 2],
fun: (path) => new url.URL(path, BASE_URL).toString()
},
icon: [16, 2, 95, 0, 3, 2],
developer: [16, 2, 68, 0],
developerId: {
path: [16, 2, 68, 1, 4, 2],
fun: appList.extractDeveloperId
},
currency: [17, 0, 2, 0, 1, 0, 1],
price: [17, 0, 2, 0, 1, 0, 0],
free: {
path: [17, 0, 2, 0, 1, 0, 0],
fun: (price) => price === 0
},
summary: [16, 2, 73, 0, 1],
scoreText: [16, 2, 51, 0, 0],
score: [16, 2, 51, 0, 1]
};

const moreResultsMapping = {
title: [0, 3],
appId: [0, 0, 0],
url: {
path: [0, 10, 4, 2],
fun: (path) => new url.URL(path, BASE_URL).toString()
},
icon: [0, 1, 3, 2],
developer: [0, 14],
currency: [0, 8, 1, 0, 1],
price: [0, 8, 1, 0, 0],
free: {
path: [0, 8, 1, 0, 0],
fun: (price) => price === 0
},
summary: [0, 13, 1],
scoreText: [0, 4, 0],
score: [0, 4, 1]
};

const sections = R.path(mappings.sections, html);
let moreResultsSection;
let mainApp;
if (sections.length === 1) {
moreResultsSection = sections[0];
} else {
moreResultsSection = sections.filter(section => R.path(SECTIONS_MAPPING.title, section) === MORE_RESULTS)[0];
if (moreResultsSection) {
mainApp = scriptData.extractor(mainAppMapping)(R.path(mappings.app, html));
} else if (R.path(SECTIONS_MAPPING.noResults, sections[0])) {
throw Error(R.path(SECTIONS_MAPPING.noResults, sections[0]));
} else {
moreResultsSection = sections[0];
}
}
const processedApps = R.map(scriptData.extractor(moreResultsMapping), R.path(SECTIONS_MAPPING.apps, moreResultsSection));
if (mainApp) {
processedApps.unshift(mainApp);
}

const apps = opts.fullDetail
? await processFullDetailApps(processedApps, opts)
: processedApps;
const token = R.path(SECTIONS_MAPPING.token, moreResultsSection);

return checkFinished(opts, [...savedApps, ...apps], token);
}

const INITIAL_MAPPINGS = {
apps: ['ds:3', 0, 1, 0, 0, 0],
token: ['ds:3', 0, 1, 0, 0, 7, 1]
app: ['ds:4', 0, 1, 0, 23],
sections: ['ds:4', 0, 1]
};

const SECTIONS_MAPPING = {
title: [22, 1, 0],
token: [22, 1, 3, 1],
apps: [22, 0],
noResults: [25, 0, 0, 0, 1]
};

const MORE_RESULTS = 'More results';

function getPriceGoogleValue (value) {
switch (value.toLowerCase()) {
case 'free':
Expand Down
46 changes: 24 additions & 22 deletions lib/utils/appList.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,53 @@ const scriptData = require('./scriptData');
const { BASE_URL } = require('../constants');

const MAPPINGS = {
title: [2],
appId: [12, 0],
title: [0, 3],
appId: [0, 0, 0],
url: {
path: [9, 4, 2],
path: [0, 8, 6, 5, 2],
fun: (path) => new url.URL(path, BASE_URL).toString()
},
icon: [1, 1, 0, 3, 2],
developer: [4, 0, 0, 0],
developerId: {
path: [4, 0, 0, 1, 4, 2],
fun: extaractDeveloperId
},
icon: [0, 1, 3, 2],
developer: [0, 14],
priceText: {
path: [7, 0, 3, 2, 1, 0, 2],
path: [0, 8, 1, 0, 2],
fun: (price) => price === undefined ? 'FREE' : price
},
currency: {
path: [7, 0, 3, 2, 1, 0, 2],
path: [0, 8, 1, 0, 1],
fun: (price) => price === undefined ? undefined : price.match(/([^0-9.,\s]+)/)[0]
},
price: {
path: [7, 0, 3, 2, 1, 0, 2],
fun: (price) => price === undefined ? 0 : parseFloat(price.match(/([0-9.,]+)/)[0])
path: [0, 8, 1, 0, 2],
fun: (price) => price === undefined || price === 0 || price === '' ? 0 : parseFloat(price.match(/([0-9.,]+)/)[0])
},
free: {
path: [7, 0, 3, 2, 1, 0, 2],
fun: (price) => price === undefined
path: [0, 8, 1, 0, 2],
fun: (price) => price === undefined || price === ''
},
summary: [4, 1, 1, 1, 1],
scoreText: [6, 0, 2, 1, 0],
score: [6, 0, 2, 1, 1]
summary: [0, 13, 1],
scoreText: [0, 4, 0],
score: [0, 4, 1]
};

function extaractDeveloperId (link) {
function extractDeveloperId (link) {
return link;
return link.split('?id=')[1];
}

/*
* Apply MAPPINGS for each application in list from root path
*/

function extract (root, data) {
const input = R.path(root, data);
function extract (root, rootAlt, data) {
let input = R.path(root, data);

if (input === undefined)
input = R.path(rootAlt, data);

if (input === undefined) return [];

return R.map(scriptData.extractor(MAPPINGS), input);
}

module.exports = { MAPPINGS, extract };
module.exports = { MAPPINGS, extract, extractDeveloperId };
16 changes: 8 additions & 8 deletions lib/utils/processPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function processPages (html, opts, savedApps, mappings) {
html = scriptData.parse(html);
}

const processedApps = appList.extract(mappings.apps, html);
const processedApps = appList.extract(mappings.apps, mappings.appsAlt, html);
const apps = opts.fullDetail
? await processFullDetailApps(processedApps, opts)
: processedApps;
Expand All @@ -41,8 +41,8 @@ async function processFullDetailApps (apps, opts) {
}

const REQUEST_MAPPINGS = {
apps: [0, 0, 0],
token: [0, 0, 7, 1]
apps: [0, 22, 0],
token: [0, 22, 1, 3, 1]
};

function checkFinished (opts, savedApps, nextToken) {
Expand All @@ -54,8 +54,8 @@ function checkFinished (opts, savedApps, nextToken) {
numberOfApps: opts.numberOfApps,
withToken: nextToken
});
const url = `${BASE_URL}/_/PlayStoreUi/data/batchexecute?rpcids=qnKhOb&f.sid=-697906427155521722&bl=boq_playuiserver_20190903.08_p0&hl=${opts.lang}&gl=${opts.country}&authuser&soc-app=121&soc-platform=1&soc-device=1&_reqid=1065213`;

const url = `${BASE_URL}/_/PlayStoreUi/data/batchexecute?rpcids=qnKhOb&source-path=/store/apps/developer&f.sid=5540864258265546590&bl=boq_playuiserver_20220606.06_p1&hl=${opts.lang}&authuser=0&soc-app=121&soc-platform=1&soc-device=1&_reqid=773397&rt=c`;
debug('batchexecute URL: %s', url);
debug('with body: %s', body);

Expand All @@ -71,7 +71,7 @@ function checkFinished (opts, savedApps, nextToken) {

return request(requestOptions, opts.throttle)
.then((html) => {
const input = JSON.parse(html.substring(5));
const input = JSON.parse(html.split('\n')[3]);
const data = JSON.parse(input[0][2]);

return (data === null)
Expand All @@ -84,9 +84,9 @@ function getBodyForRequests ({
numberOfApps = 100,
withToken = '%token%'
}) {
const body = `f.req=%5B%5B%5B%22qnKhOb%22%2C%22%5B%5Bnull%2C%5B%5B10%2C%5B10%2C${numberOfApps}%5D%5D%2Ctrue%2Cnull%2C%5B96%2C27%2C4%2C8%2C57%2C30%2C110%2C79%2C11%2C16%2C49%2C1%2C3%2C9%2C12%2C104%2C55%2C56%2C51%2C10%2C34%2C77%5D%5D%2Cnull%2C%5C%22${withToken}%5C%22%5D%5D%22%2Cnull%2C%22generic%22%5D%5D%5D`;
const body = `f.req=%5B%5B%5B%22qnKhOb%22%2C%22%5B%5Bnull%2C%5B%5B10%2C%5B20%5D%5D%2Ctrue%2Cnull%2C%5B96%2C108%2C72%2C27%2C8%2C57%2C169%2C30%2C110%2C11%2C16%2C1%2C139%2C152%2C165%2C163%2C9%2C71%2C31%2C195%2C12%2C64%2C151%2C150%2C148%2C113%2C104%2C55%2C56%2C145%2C32%2C34%2C10%2C122%5D%5D%2Cnull%2C%5C%22${withToken}%5C%22%5D%2C%5Btrue%5D%5D%22%2Cnull%2C%22generic%22%5D%5D%5D&at=AFSRYlwKfU4N9lNFPhofJ03SZ3pE%3A1654903395365&`

return body;
}

module.exports = processPages;
module.exports = { processPages, processFullDetailApps, checkFinished };