From a79c1556abb24b20e898186b99a9413ae4e10d15 Mon Sep 17 00:00:00 2001 From: Domenico Iezzi Date: Thu, 5 Oct 2017 21:51:43 +0200 Subject: [PATCH] Fixed and improved browse() function Signed-off-by: Domenico Iezzi --- gpapi/googleplay.py | 23 ++++++++++++++++++----- test.py | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/gpapi/googleplay.py b/gpapi/googleplay.py index 1fce18f..705e0b4 100644 --- a/gpapi/googleplay.py +++ b/gpapi/googleplay.py @@ -328,16 +328,29 @@ class GooglePlayAPI(object): result = list(map(utils.fromDocToDictionary, detailsList)) return result - def browse(self, cat=None, ctr=None): + def browse(self, cat=None, subCat=None): """Browse categories. cat (category ID) and ctr (subcategory ID) are used as filters.""" path = "browse?c=3" if cat is not None: path += "&cat=%s" % requests.utils.quote(cat) - if ctr is not None: - path += "&ctr=%s" % requests.utils.quote(ctr) - message = self.executeRequestApi2(path) - return message.payload.browseResponse + if subCat is not None: + path += "&ctr=%s" % requests.utils.quote(subCat) + data = self.executeRequestApi2(path) + output = {} + + if len(data.preFetch) > 0: + # get Play Store showcase categories + # (like Top Trending, Recently Updated ...) + for preFetch in data.preFetch: + doc = preFetch.response.payload.listResponse.cluster[0].doc + if len(doc) == 0: + continue + categoryTitle = doc[0].title + output[categoryTitle] = list(map(utils.fromDocToDictionary, + [apps for apps in doc[0].child])) + + return output def list(self, cat, ctr=None, nb_results=None, offset=None): """List apps. diff --git a/test.py b/test.py index 6854eab..da1656b 100644 --- a/test.py +++ b/test.py @@ -8,6 +8,8 @@ PASSWD = "fjgozwjmkwyvvutt" testApps = ['com.cpuid.cpu_z'] server = GooglePlayAPI(debug=True) +# LOGIN + print('\nLogging in with email and password\n') server.login(EMAIL, PASSWD, None, None) gsfId = server.gsfId @@ -17,14 +19,20 @@ print('\nNow trying secondary login with ac2dm token and gsfId saved\n') server = GooglePlayAPI(debug=True) server.login(None, None, gsfId, authSubToken) +# SEARCH + apps = server.search('telegram', 34, None) print('nb_result: 34') print('number of results: %d' % len(apps)) + print('\nFound those apps:\n') for a in apps: print(a['docId']) + +# DOWNLOAD + docid = apps[0]['docId'] version = apps[0]['versionCode'] print('\nTelegram docid is: %s\n' % docid) @@ -34,6 +42,15 @@ with open(docid + '.apk', 'wb') as f: f.write(fl) print('\nDownload successful\n') f.close() + +# BULK DETAILS + print('\nGetting details for %s\n' % testApps[0]) bulk = server.bulkDetails(testApps) print(bulk) + +# BROWSE +browse = server.browse(cat='MUSIC_AND_AUDIO') +for key in list(browse.keys()): + print('First app for category %s is %s' % + (key, browse[key][0]['docId']))