lib/search.js
/*
 * If already have requested results or there are no more pages, return current
 * app list, otherwise request the ajax endpoint of the next page and process
 * the results.
 */
If already have requested results or there are no more pages, return current
app list, otherwise request the ajax endpoint of the next page and process
the results.
If already have requested results or there are no more pages return current app list otherwise request the ajax endpoint of the next page and process the results .
function checkFinished (opts, savedApps, nextToken, fSid) {
  if (savedApps.length >= opts.num || !nextToken) {
    return savedApps.slice(0, opts.num);
  }
  const formattedDate = '20190805.05';
  const queryString = {
    rpcids: 'qnKhOb',
    'f.sid': fSid,
    bl: `boq_playuiserver_${formattedDate}_p0`,
    hl: opts.lang,
    gl: opts.country,
    'soc-app': '121',
    'soc-platform': '1',
    'soc-device': '1',
  };
  const requestOptions = Object.assign({
    url: `https://play.google.com/_/PlayStoreUi/data/batchexecute`,
    qs: queryString,
    method: 'POST',
    body: body.replace('%token%', nextToken),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    }
  }, opts.requestOptions);
  const URL = `https://play.google.com/_/PlayStoreUi/data/batchexecute?${qs.stringify(queryString)}`;
  console.log('Parsed url', URL);
  return request(requestOptions, opts.throttle)
    .then((html) => {
      const input = JSON.parse(html.substring(5));
      const data = JSON.parse(input[0][2]);
      return processAndRecur(data, opts, savedApps, REQUEST_MAPPINGS, fSid);
    });
}
function checkFinished ( opts , savedApps , nextToken , fSid ) { if ( savedApps . length >= opts . num || ! nextToken ) { return savedApps . slice ( 0 , opts . num ) ; } const formattedDate = '20190805.05' ; const queryString = { rpcids : 'qnKhOb' , 'f.sid' : fSid , bl : ` ${ formattedDate } ` , hl : opts . lang , gl : opts . country , 'soc-app' : '121' , 'soc-platform' : '1' , 'soc-device' : '1' , } ; const requestOptions = Object . assign ( { url : ` ` , qs : queryString , method : 'POST' , body : body . replace ( '%token%' , nextToken ) , headers : { 'Content-Type' : 'application/x-www-form-urlencoded;charset=UTF-8' } } , opts . requestOptions ) ; const URL = ` ${ qs . stringify ( queryString ) } ` ; console . log ( 'Parsed url' , URL ) ; return request ( requestOptions , opts . throttle ) . then ( ( html ) => { const input = JSON . parse ( html . substring ( 5 ) ) ; const data = JSON . parse ( input [ 0 ] [ 2 ] ) ; return processAndRecur ( data , opts , savedApps , REQUEST_MAPPINGS , fSid ) ; } ) ; }
If already have requested results or there are no more pages, return current
 app list, otherwise request the ajax endpoint of the next page and process
 the results.
If already have requested results or there are no more pages return current app list otherwise request the ajax endpoint of the next page and process the results .
//authuser: 0, //rt: 'c', //DESCOMENTAR AQUI PARA FICAR IGUAL A PLAYSTORE. //comentar essa linha caso o rt=c e descomentar as debaixo; /*
      const initialIndex = html.indexOf('[[') - 1;
      const finalIndex = html.indexOf('["di"') - 4;
      const input = html.substring(initialIndex, finalIndex);
      */