Added API to fetch home apps

This commit is contained in:
Domenico Iezzi 2018-03-18 21:26:03 +01:00
parent 78113555b5
commit 05170a1e0a
2 changed files with 27 additions and 2 deletions

View File

@ -95,6 +95,7 @@ class GooglePlayAPI(object):
"X-DFE-Encoded-Targets": config.DFE_TARGETS, "X-DFE-Encoded-Targets": config.DFE_TARGETS,
"User-Agent": self.deviceBuilder.getUserAgent(), "User-Agent": self.deviceBuilder.getUserAgent(),
"X-DFE-Client-Id": "am-android-google", "X-DFE-Client-Id": "am-android-google",
"X-DFE-MCCMNC": self.deviceBuilder.device.get('celloperator'),
"X-DFE-Network-Type": "4", "X-DFE-Network-Type": "4",
"X-DFE-Content-Filters": "", "X-DFE-Content-Filters": "",
"X-DFE-Request-Params": "timeoutMs=4000"} "X-DFE-Request-Params": "timeoutMs=4000"}
@ -268,7 +269,7 @@ class GooglePlayAPI(object):
else: else:
raise LoginError("Auth token not found.") raise LoginError("Auth token not found.")
def executeRequestApi2(self, path, post_data=None, content_type=None): def executeRequestApi2(self, path, post_data=None, content_type=None, params=None):
if self.authSubToken is None: if self.authSubToken is None:
raise Exception("You need to login before executing any request") raise Exception("You need to login before executing any request")
headers = self.getDefaultHeaders() headers = self.getDefaultHeaders()
@ -281,12 +282,14 @@ class GooglePlayAPI(object):
response = requests.post(url, response = requests.post(url,
data=str(post_data), data=str(post_data),
headers=headers, headers=headers,
params=params,
verify=ssl_verify, verify=ssl_verify,
timeout=60, timeout=60,
proxies=self.proxies_config) proxies=self.proxies_config)
else: else:
response = requests.get(url, response = requests.get(url,
headers=headers, headers=headers,
params=params,
verify=ssl_verify, verify=ssl_verify,
timeout=60, timeout=60,
proxies=self.proxies_config) proxies=self.proxies_config)
@ -370,17 +373,30 @@ class GooglePlayAPI(object):
if the app doesn't exist""" if the app doesn't exist"""
path = "bulkDetails" path = "bulkDetails"
params = {'au': '1'}
req = googleplay_pb2.BulkDetailsRequest() req = googleplay_pb2.BulkDetailsRequest()
req.docid.extend(packageNames) req.docid.extend(packageNames)
data = req.SerializeToString() data = req.SerializeToString()
message = self.executeRequestApi2(path, message = self.executeRequestApi2(path,
post_data=data.decode("utf-8"), post_data=data.decode("utf-8"),
content_type="application/x-protobuf") content_type="application/x-protobuf",
params=params)
response = message.payload.bulkDetailsResponse response = message.payload.bulkDetailsResponse
return [None if not utils.hasDoc(entry) else return [None if not utils.hasDoc(entry) else
utils.fromDocToDictionary(entry.doc) utils.fromDocToDictionary(entry.doc)
for entry in response.entry] for entry in response.entry]
def getHomeApps(self):
path = "homeV2?c=3&nocache_isui=true"
data = self.executeRequestApi2(path)
output = []
cluster = data.preFetch[0].response.payload.listResponse.cluster[0]
for doc in cluster.doc:
output.append({"categoryId": doc.docid,
"categoryStr": doc.title,
"apps": [utils.fromDocToDictionary(c) for c in doc.child]})
return output
def browse(self, cat=None, subCat=None): def browse(self, cat=None, subCat=None):
"""Browse categories. If neither cat nor subcat are specified, """Browse categories. If neither cat nor subcat are specified,
return a list of categories, otherwise it return a list of apps return a list of categories, otherwise it return a list of apps

View File

@ -33,6 +33,15 @@ print('\nFound those apps:\n')
for a in apps: for a in apps:
print(a['docId']) print(a['docId'])
# HOME APPS
print('\nFetching apps from play store home\n')
home = server.getHomeApps()
for cat in home:
print("cat {0} with {1} apps".format(cat.get('categoryId'),
str(len(cat.get('apps')))))
# DOWNLOAD # DOWNLOAD
docid = apps[0]['docId'] docid = apps[0]['docId']
print('\nTelegram docid is: %s\n' % docid) print('\nTelegram docid is: %s\n' % docid)