From 05170a1e0a7205585ae976909e3ec614f8df27fc Mon Sep 17 00:00:00 2001 From: Domenico Iezzi Date: Sun, 18 Mar 2018 21:26:03 +0100 Subject: [PATCH] Added API to fetch home apps --- gpapi/googleplay.py | 20 ++++++++++++++++++-- test.py | 9 +++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/gpapi/googleplay.py b/gpapi/googleplay.py index d4205fa..9d17182 100644 --- a/gpapi/googleplay.py +++ b/gpapi/googleplay.py @@ -95,6 +95,7 @@ class GooglePlayAPI(object): "X-DFE-Encoded-Targets": config.DFE_TARGETS, "User-Agent": self.deviceBuilder.getUserAgent(), "X-DFE-Client-Id": "am-android-google", + "X-DFE-MCCMNC": self.deviceBuilder.device.get('celloperator'), "X-DFE-Network-Type": "4", "X-DFE-Content-Filters": "", "X-DFE-Request-Params": "timeoutMs=4000"} @@ -268,7 +269,7 @@ class GooglePlayAPI(object): else: 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: raise Exception("You need to login before executing any request") headers = self.getDefaultHeaders() @@ -281,12 +282,14 @@ class GooglePlayAPI(object): response = requests.post(url, data=str(post_data), headers=headers, + params=params, verify=ssl_verify, timeout=60, proxies=self.proxies_config) else: response = requests.get(url, headers=headers, + params=params, verify=ssl_verify, timeout=60, proxies=self.proxies_config) @@ -370,17 +373,30 @@ class GooglePlayAPI(object): if the app doesn't exist""" path = "bulkDetails" + params = {'au': '1'} req = googleplay_pb2.BulkDetailsRequest() req.docid.extend(packageNames) data = req.SerializeToString() message = self.executeRequestApi2(path, post_data=data.decode("utf-8"), - content_type="application/x-protobuf") + content_type="application/x-protobuf", + params=params) response = message.payload.bulkDetailsResponse return [None if not utils.hasDoc(entry) else utils.fromDocToDictionary(entry.doc) 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): """Browse categories. If neither cat nor subcat are specified, return a list of categories, otherwise it return a list of apps diff --git a/test.py b/test.py index 22908f7..9d3a4ef 100644 --- a/test.py +++ b/test.py @@ -33,6 +33,15 @@ print('\nFound those apps:\n') for a in apps: 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 docid = apps[0]['docId'] print('\nTelegram docid is: %s\n' % docid)