Take latest apk if not version specified

If no *versionCode* parameter is specified to *download* or *delivery*
methods, fetch the latest one with a simple `self.details(pkgName)`
This commit is contained in:
Domenico Iezzi 2017-11-09 12:25:39 +01:00
parent 639c7f9e98
commit 693ae8348f
No known key found for this signature in database
GPG Key ID: 7AC94D5DDA2FB7EE
2 changed files with 12 additions and 4 deletions

View File

@ -491,7 +491,7 @@ class GooglePlayAPI(object):
bar.done() bar.done()
return response_content return response_content
def delivery(self, packageName, versionCode, offerType=1, def delivery(self, packageName, versionCode=None, offerType=1,
downloadToken=None, progress_bar=False, expansion_files=False): downloadToken=None, progress_bar=False, expansion_files=False):
"""Download an already purchased app. """Download an already purchased app.
@ -513,6 +513,11 @@ class GooglePlayAPI(object):
Data to build this name string is provided in the dict object. For more Data to build this name string is provided in the dict object. For more
info check https://developer.android.com/google/play/expansion-files.html info check https://developer.android.com/google/play/expansion-files.html
""" """
if versionCode is None:
# pick up latest version
versionCode = self.details(packageName)['versionCode']
path = "delivery" path = "delivery"
params = {'ot': str(offerType), params = {'ot': str(offerType),
'doc': packageName, 'doc': packageName,
@ -557,7 +562,7 @@ class GooglePlayAPI(object):
result['additionalData'].append(a) result['additionalData'].append(a)
return result return result
def download(self, packageName, versionCode, offerType=1, def download(self, packageName, versionCode=None, offerType=1,
progress_bar=False, expansion_files=False): progress_bar=False, expansion_files=False):
"""Download an app and return its raw data (APK file). Free apps need """Download an app and return its raw data (APK file). Free apps need
to be "purchased" first, in order to retrieve the download cookie. to be "purchased" first, in order to retrieve the download cookie.
@ -578,6 +583,10 @@ class GooglePlayAPI(object):
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")
if versionCode is None:
# pick up latest version
versionCode = self.details(packageName)['versionCode']
path = "purchase" path = "purchase"
headers = self.getDefaultHeaders() headers = self.getDefaultHeaders()
params = { params = {

View File

@ -35,10 +35,9 @@ for a in apps:
# DOWNLOAD # DOWNLOAD
docid = apps[0]['docId'] docid = apps[0]['docId']
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, progress_bar=True) fl = server.download(docid, None, progress_bar=True)
with open(docid + '.apk', 'wb') as f: with open(docid + '.apk', 'wb') as f:
f.write(fl['data']) f.write(fl['data'])
print('\nDownload successful\n') print('\nDownload successful\n')