mirror of
https://github.com/FliegendeWurst/googleplay-api.git
synced 2024-11-22 04:44:59 +00:00
Moved some code in config.py
This commit is contained in:
parent
525c24fae0
commit
5324eaa51b
@ -66,6 +66,27 @@ class DeviceBuilder(object):
|
|||||||
raise Exception('Wrong timezone supplied')
|
raise Exception('Wrong timezone supplied')
|
||||||
self.timezone = timezone
|
self.timezone = timezone
|
||||||
|
|
||||||
|
def getBaseHeaders(self):
|
||||||
|
return {"Accept-Language": self.locale.replace('_', '-'),
|
||||||
|
"X-DFE-Encoded-Targets": DFE_TARGETS,
|
||||||
|
"User-Agent": self.getUserAgent(),
|
||||||
|
"X-DFE-Client-Id": "am-android-google",
|
||||||
|
"X-DFE-MCCMNC": self.device.get('celloperator'),
|
||||||
|
"X-DFE-Network-Type": "4",
|
||||||
|
"X-DFE-Content-Filters": "",
|
||||||
|
"X-DFE-Request-Params": "timeoutMs=4000"}
|
||||||
|
|
||||||
|
def getDeviceUploadHeaders(self):
|
||||||
|
headers = self.getBaseHeaders()
|
||||||
|
headers["X-DFE-Enabled-Experiments"] = "cl:billing.select_add_instrument_by_default"
|
||||||
|
headers["X-DFE-Unsupported-Experiments"] = ("nocache:billing.use_charging_poller,"
|
||||||
|
"market_emails,buyer_currency,prod_baseline,checkin.set_asset_paid_app_field,"
|
||||||
|
"shekel_test,content_ratings,buyer_currency_in_app,nocache:encrypted_apk,recent_changes")
|
||||||
|
headers["X-DFE-SmallestScreenWidthDp"] = "320"
|
||||||
|
headers["X-DFE-Filter-Level"] = "3"
|
||||||
|
return headers
|
||||||
|
|
||||||
|
|
||||||
def getUserAgent(self):
|
def getUserAgent(self):
|
||||||
version_string = self.device.get('vending.versionstring')
|
version_string = self.device.get('vending.versionstring')
|
||||||
if version_string is None:
|
if version_string is None:
|
||||||
|
@ -34,6 +34,7 @@ LIST_URL = FDFE + "list"
|
|||||||
REVIEWS_URL = FDFE + "rev"
|
REVIEWS_URL = FDFE + "rev"
|
||||||
|
|
||||||
CONTENT_TYPE_URLENC = "application/x-www-form-urlencoded; charset=UTF-8"
|
CONTENT_TYPE_URLENC = "application/x-www-form-urlencoded; charset=UTF-8"
|
||||||
|
CONTENT_TYPE_PROTO = "application/x-protobuf"
|
||||||
|
|
||||||
|
|
||||||
class LoginError(Exception):
|
class LoginError(Exception):
|
||||||
@ -98,18 +99,14 @@ class GooglePlayAPI(object):
|
|||||||
def setAuthSubToken(self, authSubToken):
|
def setAuthSubToken(self, authSubToken):
|
||||||
self.authSubToken = authSubToken
|
self.authSubToken = authSubToken
|
||||||
|
|
||||||
def getDefaultHeaders(self):
|
def getHeaders(self, upload_fields=False):
|
||||||
"""Return the default set of request headers, which
|
"""Return the default set of request headers, which
|
||||||
can later be expanded, based on the request type"""
|
can later be expanded, based on the request type"""
|
||||||
|
|
||||||
headers = {"Accept-Language": self.deviceBuilder.locale.replace('_', '-'),
|
if upload_fields:
|
||||||
"X-DFE-Encoded-Targets": config.DFE_TARGETS,
|
headers = self.deviceBuilder.getDeviceUploadHeaders()
|
||||||
"User-Agent": self.deviceBuilder.getUserAgent(),
|
else:
|
||||||
"X-DFE-Client-Id": "am-android-google",
|
headers = self.deviceBuilder.getBaseHeaders()
|
||||||
"X-DFE-MCCMNC": self.deviceBuilder.device.get('celloperator'),
|
|
||||||
"X-DFE-Network-Type": "4",
|
|
||||||
"X-DFE-Content-Filters": "",
|
|
||||||
"X-DFE-Request-Params": "timeoutMs=4000"}
|
|
||||||
if self.gsfId is not None:
|
if self.gsfId is not None:
|
||||||
headers["X-DFE-Device-Id"] = "{0:x}".format(self.gsfId)
|
headers["X-DFE-Device-Id"] = "{0:x}".format(self.gsfId)
|
||||||
if self.authSubToken is not None:
|
if self.authSubToken is not None:
|
||||||
@ -119,8 +116,8 @@ class GooglePlayAPI(object):
|
|||||||
return headers
|
return headers
|
||||||
|
|
||||||
def checkin(self, email, ac2dmToken):
|
def checkin(self, email, ac2dmToken):
|
||||||
headers = self.getDefaultHeaders()
|
headers = self.getHeaders()
|
||||||
headers["Content-Type"] = "application/x-protobuffer"
|
headers["Content-Type"] = CONTENT_TYPE_PROTO
|
||||||
|
|
||||||
request = self.deviceBuilder.getAndroidCheckinRequest()
|
request = self.deviceBuilder.getAndroidCheckinRequest()
|
||||||
|
|
||||||
@ -132,15 +129,15 @@ class GooglePlayAPI(object):
|
|||||||
response.ParseFromString(res.content)
|
response.ParseFromString(res.content)
|
||||||
|
|
||||||
# checkin again to upload gfsid
|
# checkin again to upload gfsid
|
||||||
request2 = googleplay_pb2.AndroidCheckinRequest()
|
request.id = response.androidId
|
||||||
request2.CopyFrom(request)
|
request.securityToken = response.securityToken
|
||||||
request2.id = response.androidId
|
request.accountCookie.append("[" + email + "]")
|
||||||
request2.securityToken = response.securityToken
|
request.accountCookie.append(ac2dmToken)
|
||||||
request2.accountCookie.append("[" + email + "]")
|
stringRequest = request.SerializeToString()
|
||||||
request2.accountCookie.append(ac2dmToken)
|
requests.post(CHECKIN_URL,
|
||||||
stringRequest = request2.SerializeToString()
|
data=stringRequest,
|
||||||
requests.post(CHECKIN_URL, data=stringRequest,
|
headers=headers,
|
||||||
headers=headers, verify=ssl_verify,
|
verify=ssl_verify,
|
||||||
proxies=self.proxies_config)
|
proxies=self.proxies_config)
|
||||||
|
|
||||||
return response.androidId
|
return response.androidId
|
||||||
@ -151,11 +148,7 @@ class GooglePlayAPI(object):
|
|||||||
|
|
||||||
upload = googleplay_pb2.UploadDeviceConfigRequest()
|
upload = googleplay_pb2.UploadDeviceConfigRequest()
|
||||||
upload.deviceConfiguration.CopyFrom(self.deviceBuilder.getDeviceConfig())
|
upload.deviceConfiguration.CopyFrom(self.deviceBuilder.getDeviceConfig())
|
||||||
headers = self.getDefaultHeaders()
|
headers = self.getHeaders(upload_fields=True)
|
||||||
headers["X-DFE-Enabled-Experiments"] = "cl:billing.select_add_instrument_by_default"
|
|
||||||
headers["X-DFE-Unsupported-Experiments"] = "nocache:billing.use_charging_poller,market_emails,buyer_currency,prod_baseline,checkin.set_asset_paid_app_field,shekel_test,content_ratings,buyer_currency_in_app,nocache:encrypted_apk,recent_changes"
|
|
||||||
headers["X-DFE-SmallestScreenWidthDp"] = "320"
|
|
||||||
headers["X-DFE-Filter-Level"] = "3"
|
|
||||||
stringRequest = upload.SerializeToString()
|
stringRequest = upload.SerializeToString()
|
||||||
response = requests.post(UPLOAD_URL, data=stringRequest,
|
response = requests.post(UPLOAD_URL, data=stringRequest,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
@ -283,7 +276,7 @@ class GooglePlayAPI(object):
|
|||||||
def executeRequestApi2(self, path, post_data=None, content_type=CONTENT_TYPE_URLENC, params=None):
|
def executeRequestApi2(self, path, post_data=None, content_type=CONTENT_TYPE_URLENC, params=None):
|
||||||
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")
|
||||||
headers = self.getDefaultHeaders()
|
headers = self.getHeaders()
|
||||||
headers["Content-Type"] = content_type
|
headers["Content-Type"] = content_type
|
||||||
|
|
||||||
if post_data is not None:
|
if post_data is not None:
|
||||||
@ -399,7 +392,7 @@ class GooglePlayAPI(object):
|
|||||||
data = req.SerializeToString()
|
data = req.SerializeToString()
|
||||||
message = self.executeRequestApi2(BULK_URL,
|
message = self.executeRequestApi2(BULK_URL,
|
||||||
post_data=data.decode("utf-8"),
|
post_data=data.decode("utf-8"),
|
||||||
content_type="application/x-protobuf",
|
content_type=CONTENT_TYPE_PROTO,
|
||||||
params=params)
|
params=params)
|
||||||
response = message.payload.bulkDetailsResponse
|
response = message.payload.bulkDetailsResponse
|
||||||
return [None if not utils.hasDoc(entry) else
|
return [None if not utils.hasDoc(entry) else
|
||||||
@ -528,7 +521,7 @@ class GooglePlayAPI(object):
|
|||||||
return output
|
return output
|
||||||
|
|
||||||
def _deliver_data(self, url, cookies):
|
def _deliver_data(self, url, cookies):
|
||||||
headers = self.getDefaultHeaders()
|
headers = self.getHeaders()
|
||||||
response = requests.get(url, headers=headers,
|
response = requests.get(url, headers=headers,
|
||||||
cookies=cookies, verify=ssl_verify,
|
cookies=cookies, verify=ssl_verify,
|
||||||
stream=True, timeout=60,
|
stream=True, timeout=60,
|
||||||
@ -569,7 +562,7 @@ class GooglePlayAPI(object):
|
|||||||
params = {'ot': str(offerType),
|
params = {'ot': str(offerType),
|
||||||
'doc': packageName,
|
'doc': packageName,
|
||||||
'vc': str(versionCode)}
|
'vc': str(versionCode)}
|
||||||
headers = self.getDefaultHeaders()
|
headers = self.getHeaders()
|
||||||
if downloadToken is not None:
|
if downloadToken is not None:
|
||||||
params['dtok'] = downloadToken
|
params['dtok'] = downloadToken
|
||||||
response = requests.get(DELIVERY_URL, headers=headers,
|
response = requests.get(DELIVERY_URL, headers=headers,
|
||||||
@ -631,7 +624,7 @@ class GooglePlayAPI(object):
|
|||||||
# pick up latest version
|
# pick up latest version
|
||||||
versionCode = self.details(packageName).get('versionCode')
|
versionCode = self.details(packageName).get('versionCode')
|
||||||
|
|
||||||
headers = self.getDefaultHeaders()
|
headers = self.getHeaders()
|
||||||
params = {'ot': str(offerType),
|
params = {'ot': str(offerType),
|
||||||
'doc': packageName,
|
'doc': packageName,
|
||||||
'vc': str(versionCode)}
|
'vc': str(versionCode)}
|
||||||
@ -658,7 +651,7 @@ class GooglePlayAPI(object):
|
|||||||
string_request = log_request.SerializeToString()
|
string_request = log_request.SerializeToString()
|
||||||
response = requests.post(LOG_URL,
|
response = requests.post(LOG_URL,
|
||||||
data=string_request,
|
data=string_request,
|
||||||
headers=self.getDefaultHeaders(),
|
headers=self.getHeaders(),
|
||||||
verify=ssl_verify,
|
verify=ssl_verify,
|
||||||
timeout=60,
|
timeout=60,
|
||||||
proxies=self.proxies_config)
|
proxies=self.proxies_config)
|
||||||
|
Loading…
Reference in New Issue
Block a user