Skip to content

Commit

Permalink
Take latest apk if not version specified
Browse files Browse the repository at this point in the history
If no *versionCode* parameter is specified to *download* or *delivery*
methods, fetch the latest one with a simple `self.details(pkgName)`
  • Loading branch information
Domenico Iezzi committed Nov 9, 2017
1 parent 639c7f9 commit 693ae83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 11 additions & 2 deletions gpapi/googleplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def _deliver_data(self, url, cookies, progress_bar):
bar.done()
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):
"""Download an already purchased app.
Expand All @@ -513,6 +513,11 @@ def delivery(self, packageName, versionCode, offerType=1,
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
"""

if versionCode is None:
# pick up latest version
versionCode = self.details(packageName)['versionCode']

path = "delivery"
params = {'ot': str(offerType),
'doc': packageName,
Expand Down Expand Up @@ -557,7 +562,7 @@ def delivery(self, packageName, versionCode, offerType=1,
result['additionalData'].append(a)
return result

def download(self, packageName, versionCode, offerType=1,
def download(self, packageName, versionCode=None, offerType=1,
progress_bar=False, expansion_files=False):
"""Download an app and return its raw data (APK file). Free apps need
to be "purchased" first, in order to retrieve the download cookie.
Expand All @@ -578,6 +583,10 @@ def download(self, packageName, versionCode, offerType=1,
if self.authSubToken is None:
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"
headers = self.getDefaultHeaders()
params = {
Expand Down
3 changes: 1 addition & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@

# DOWNLOAD
docid = apps[0]['docId']
version = apps[0]['versionCode']
print('\nTelegram docid is: %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:
f.write(fl['data'])
print('\nDownload successful\n')
Expand Down

0 comments on commit 693ae83

Please sign in to comment.