Signed-off-by: Domenico Iezzi <domenico.iezzi.201@gmail.com>
This commit is contained in:
Domenico Iezzi 2017-10-05 20:39:24 +02:00
parent 0a5e270049
commit 73081ee57a
2 changed files with 49 additions and 37 deletions

View File

@ -274,19 +274,31 @@ class GooglePlayAPI(object):
def search(self, query, nb_result, offset=None): def search(self, query, nb_result, offset=None):
if self.authSubToken == None: if self.authSubToken == None:
raise Exception("You need to login before executing any request") raise Exception("You need to login before executing any request")
path = "search?c=3&q=%s" % requests.utils.quote(query)
remaining = nb_result
output = []
nextPath = "search?c=3&q=%s" % requests.utils.quote(query)
if (offset is not None): if (offset is not None):
path += "&o=%d" % int(offset) nextPath += "&o=%d" % int(offset)
while remaining > 0 and nextPath != None:
data = self.executeRequestApi2(path) currentPath = nextPath
# TODO: can response contain more than 1 cluster? data = self.executeRequestApi2(currentPath)
if len(data.preFetch) == 0:
cluster = data.payload.listResponse.cluster[0]
else:
cluster = data.preFetch[0].response.payload.listResponse.cluster[0] cluster = data.preFetch[0].response.payload.listResponse.cluster[0]
# cluster has more than 1 doc usually, and each doc has some if cluster.doc[0].containerMetadata.nextPageUrl != "":
# childs representing the applications. So we chain together every child nextPath = cluster.doc[0].containerMetadata.nextPageUrl
# of every doc else:
apps = itertools.chain.from_iterable([doc.child for doc in cluster.doc]) nextPath = None
output = list(map(utils.fromDocToDictionary, apps)) apps = list(itertools.chain.from_iterable([doc.child for doc in cluster.doc]))
output += list(map(utils.fromDocToDictionary, apps))
remaining -= len(apps)
if len(output) > nb_result:
output = output[:nb_result]
return output return output
def details(self, packageName): def details(self, packageName):

46
test.py
View File

@ -8,32 +8,32 @@ PASSWD = "fjgozwjmkwyvvutt"
testApps = ['com.cpuid.cpu_z'] testApps = ['com.cpuid.cpu_z']
server = GooglePlayAPI(debug=True) server = GooglePlayAPI(debug=True)
try: print('\nLogging in with email and password\n')
print('\nLogging in with email and password\n') server.login(EMAIL, PASSWD, None, None)
server.login(EMAIL, PASSWD, None, None) gsfId = server.gsfId
gsfId = server.gsfId authSubToken = server.authSubToken
authSubToken = server.authSubToken
print('\nNow trying secondary login with ac2dm token and gsfId saved\n') print('\nNow trying secondary login with ac2dm token and gsfId saved\n')
server = GooglePlayAPI(debug=True) server = GooglePlayAPI(debug=True)
server.login(None, None, gsfId, authSubToken) server.login(None, None, gsfId, authSubToken)
apps = server.search('telegram', 1, None) apps = server.search('telegram', 34, None)
print('\nFound those apps:\n')
for a in apps: print('nb_result: 34')
print('number of results: %d' % len(apps))
print('\nFound those apps:\n')
for a in apps:
print(a['docId']) print(a['docId'])
docid = apps[0]['docId'] docid = apps[0]['docId']
version = apps[0]['versionCode'] version = apps[0]['versionCode']
print('\nTelegram docid is: %s\n' % docid) print('\nTelegram docid is: %s\n' % docid)
print('\nAttempting to download %s\n' % docid) print('\nAttempting to download %s\n' % docid)
fl = server.download(docid, version) fl = server.download(docid, version)
with open(docid + '.apk', 'wb') as f: with open(docid + '.apk', 'wb') as f:
f.write(fl) f.write(fl)
print('\nDownload successful\n') print('\nDownload successful\n')
f.close() f.close()
print('\nGetting details for %s\n' % testApps[0]) print('\nGetting details for %s\n' % testApps[0])
bulk = server.bulkDetails(testApps) bulk = server.bulkDetails(testApps)
print(bulk) print(bulk)
except Exception as e:
print(str(e))
sys.exit(1)