mirror of
https://github.com/FliegendeWurst/googleplay-api.git
synced 2024-11-22 12:54:58 +00:00
parent
3529c3c736
commit
ed0c926dc5
@ -405,9 +405,43 @@ class GooglePlayAPI(object):
|
|||||||
message = self.executeRequestApi2(path)
|
message = self.executeRequestApi2(path)
|
||||||
return message.payload.reviewResponse
|
return message.payload.reviewResponse
|
||||||
|
|
||||||
|
def delivery(self, packageName, versionCode,
|
||||||
|
offerType=1, downloadToken=None):
|
||||||
|
"""Download an already purchased app.
|
||||||
|
|
||||||
|
packageName is the app unique ID (usually starting with 'com.').
|
||||||
|
|
||||||
|
versionCode can be grabbed by using the details() method on the given
|
||||||
|
app."""
|
||||||
|
path = "delivery"
|
||||||
|
params = { 'ot': str(offerType),
|
||||||
|
'doc': packageName,
|
||||||
|
'vc': str(versionCode) }
|
||||||
|
headers = self.getDefaultHeaders()
|
||||||
|
if downloadToken is not None:
|
||||||
|
params['dtok'] = downloadToken
|
||||||
|
url = "https://android.clients.google.com/fdfe/%s" % path
|
||||||
|
response = requests.get(url, headers=headers,
|
||||||
|
params=params, verify=ssl_verify)
|
||||||
|
resObj = googleplay_pb2.ResponseWrapper.FromString(response.content)
|
||||||
|
if resObj.commands.displayErrorMessage != "":
|
||||||
|
raise RequestError(resObj.commands.displayErrorMessage)
|
||||||
|
elif resObj.payload.deliveryResponse.appDeliveryData.downloadUrl == "":
|
||||||
|
raise RequestError('App not purchased')
|
||||||
|
else:
|
||||||
|
downloadUrl = resObj.payload.deliveryResponse.appDeliveryData.downloadUrl
|
||||||
|
cookie = resObj.payload.deliveryResponse.appDeliveryData.downloadAuthCookie[0]
|
||||||
|
cookies = {
|
||||||
|
str(cookie.name): str(cookie.value)
|
||||||
|
}
|
||||||
|
return requests.get(downloadUrl, headers=headers,
|
||||||
|
cookies=cookies, verify=ssl_verify).content
|
||||||
|
|
||||||
def download(self, packageName, versionCode,
|
def download(self, packageName, versionCode,
|
||||||
offerType=1, progress_bar=False):
|
offerType=1):
|
||||||
"""Download an app and return its raw data (APK file).
|
"""Download an app and return its raw data (APK file). Free apps need
|
||||||
|
to be "purchased" first, in order to retrieve the download cookie.
|
||||||
|
If you want to download an already purchased app, use *delivery* method.
|
||||||
|
|
||||||
packageName is the app unique ID (usually starting with 'com.').
|
packageName is the app unique ID (usually starting with 'com.').
|
||||||
|
|
||||||
@ -433,17 +467,6 @@ class GooglePlayAPI(object):
|
|||||||
raise RequestError(resObj.commands.displayErrorMessage)
|
raise RequestError(resObj.commands.displayErrorMessage)
|
||||||
else:
|
else:
|
||||||
dlToken = resObj.payload.buyResponse.downloadToken
|
dlToken = resObj.payload.buyResponse.downloadToken
|
||||||
path = "delivery"
|
return self.delivery(packageName, versionCode,
|
||||||
params['dtok'] = dlToken
|
offerType, dlToken)
|
||||||
url = "https://android.clients.google.com/fdfe/%s" % path
|
|
||||||
response = requests.get(url, headers=headers,
|
|
||||||
params=params, verify=ssl_verify)
|
|
||||||
resObj = googleplay_pb2.ResponseWrapper.FromString(response.content)
|
|
||||||
downloadUrl = resObj.payload.deliveryResponse.appDeliveryData.downloadUrl
|
|
||||||
cookie = resObj.payload.deliveryResponse.appDeliveryData.downloadAuthCookie[0]
|
|
||||||
cookies = {
|
|
||||||
str(cookie.name): str(cookie.value)
|
|
||||||
}
|
|
||||||
return requests.get(downloadUrl, headers=headers,
|
|
||||||
cookies=cookies, verify=ssl_verify).content
|
|
||||||
|
|
||||||
|
25
test.py
25
test.py
@ -1,4 +1,4 @@
|
|||||||
from gpapi.googleplay import GooglePlayAPI
|
from gpapi.googleplay import GooglePlayAPI, RequestError
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -32,7 +32,6 @@ for a in apps:
|
|||||||
print(a['docId'])
|
print(a['docId'])
|
||||||
|
|
||||||
# DOWNLOAD
|
# DOWNLOAD
|
||||||
|
|
||||||
docid = apps[0]['docId']
|
docid = apps[0]['docId']
|
||||||
version = apps[0]['versionCode']
|
version = apps[0]['versionCode']
|
||||||
print('\nTermux docid is: %s\n' % docid)
|
print('\nTermux docid is: %s\n' % docid)
|
||||||
@ -43,6 +42,28 @@ with open(docid + '.apk', 'wb') as f:
|
|||||||
print('\nDownload successful\n')
|
print('\nDownload successful\n')
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
# DOWNLOAD APP NOT PURCHASED
|
||||||
|
# Attempting to download Nova Launcher Prime
|
||||||
|
# it should throw an error 'App Not Purchased'
|
||||||
|
|
||||||
|
errorThrown = False
|
||||||
|
try:
|
||||||
|
app = server.search('nova launcher prime', 3, None)
|
||||||
|
app = filter(lambda x: x['docId'] == 'com.teslacoilsw.launcher.prime', app)
|
||||||
|
app = list(app)[0]
|
||||||
|
fl = server.download(app['docId'], app['versionCode'])
|
||||||
|
with open(docid + '.apk', 'wb') as f:
|
||||||
|
f.write(fl)
|
||||||
|
print('\nDownload successful\n')
|
||||||
|
f.close()
|
||||||
|
except RequestError as e:
|
||||||
|
errorThrown = True
|
||||||
|
|
||||||
|
if not errorThrown:
|
||||||
|
print('Download of previous app should have failed')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
# BULK DETAILS
|
# BULK DETAILS
|
||||||
|
|
||||||
print('\nGetting details for %s\n' % testApps[0])
|
print('\nGetting details for %s\n' % testApps[0])
|
||||||
|
Loading…
Reference in New Issue
Block a user