Skip to content

Commit

Permalink
_delivery_data returns more information
Browse files Browse the repository at this point in the history
  • Loading branch information
Domenico Iezzi committed Jan 27, 2018
1 parent e05d126 commit 0a13755
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
10 changes: 7 additions & 3 deletions gpapi/googleplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,11 @@ def _deliver_data(self, url, cookies):
cookies=cookies, verify=ssl_verify,
stream=True, timeout=60,
proxies=self.proxies_config)
return response.iter_content(chunk_size=(32 * 1 << 10))
total_size = response.headers.get('content-length')
chunk_size = 32 * (1 << 10)
return {'data': response.iter_content(chunk_size=chunk_size),
'total_size': total_size,
'chunk_size': chunk_size}

def delivery(self, packageName, versionCode=None, offerType=1,
downloadToken=None, expansion_files=False):
Expand Down Expand Up @@ -557,7 +561,7 @@ def delivery(self, packageName, versionCode=None, offerType=1,
cookies = {
str(cookie.name): str(cookie.value)
}
result['data'] = self._deliver_data(downloadUrl, cookies)
result['file'] = self._deliver_data(downloadUrl, cookies)
if not expansion_files:
return result
for obb in resObj.payload.deliveryResponse.appDeliveryData.additionalFile:
Expand All @@ -570,7 +574,7 @@ def delivery(self, packageName, versionCode=None, offerType=1,
obbType = 'patch'
a['type'] = obbType
a['versionCode'] = obb.versionCode
a['data'] = self._deliver_data(obb.downloadUrl, None)
a['file'] = self._deliver_data(obb.downloadUrl, None)
result['additionalData'].append(a)
return result

Expand Down
13 changes: 9 additions & 4 deletions obb_download_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@

args = ap.parse_args()

server = GooglePlayAPI(debug=True)
server = GooglePlayAPI(debug=True, locale='it_IT', timezone='Europe/Rome')

# LOGIN

print('\nLogging in with email and password\n')
server.login(args.email, args.password, None, None)
docid = 'com.pixel.gun3d'

download = server.download('com.mapswithme.maps.pro', 1754, progress_bar=True, expansion_files=True)
print('\nDownloading apk\n')
download = server.delivery(docid, versionCode=None, expansion_files=True)
with open(download['docId'] + '.apk', 'wb') as first:
first.write(download['data'])
for chunk in download.get('file').get('data'):
first.write(chunk)

print('\nDownloading additional files\n')
for obb in download['additionalData']:
name = obb['type'] + '.' + str(obb['versionCode']) + '.' + download['docId'] + '.obb'
with open(name, 'wb') as second:
second.write(obb['data'])
for chunk in obb.get('file').get('data'):
second.write(chunk)

print('\nDownload successful\n')
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
print('\nAttempting to download %s\n' % docid)
fl = server.delivery(docid, versionCode=None)
with open(docid + '.apk', 'wb') as apk_file:
for chunk in fl.get('data'):
for chunk in fl.get('file').get('data'):
apk_file.write(chunk)
print('\nDownload successful\n')

Expand Down

0 comments on commit 0a13755

Please sign in to comment.