Moved header string preparation to config.py

Signed-off-by: Domenico Iezzi <domenico.iezzi.201@gmail.com>
This commit is contained in:
Domenico Iezzi 2017-10-12 19:46:20 +02:00
parent e1cc147db4
commit 5bbdd195a1
2 changed files with 32 additions and 16 deletions

View File

@ -9,10 +9,10 @@ if VERSION == 2:
else: else:
import configparser import configparser
# separator used by search.py, categories.py, ...
SEPARATOR = ";"
DFE_TARGETS = "CAEScFfqlIEG6gUYogFWrAISK1WDAg+hAZoCDgIU1gYEOIACFkLMAeQBnASLATlASUuyAyqCAjY5igOMBQzfA/IClwFbApUC4ANbtgKVAS7OAX8YswHFBhgDwAOPAmGEBt4OfKkB5weSB5AFASkiN68akgMaxAMSAQEBA9kBO7UBFE1KVwIDBGs3go6BBgEBAgMECQgJAQIEAQMEAQMBBQEBBAUEFQYCBgUEAwMBDwIBAgOrARwBEwMEAg0mrwESfTEcAQEKG4EBMxghChMBDwYGASI3hAEODEwXCVh/EREZA4sBYwEdFAgIIwkQcGQRDzQ2fTC2AjfVAQIBAYoBGRg2FhYFBwEqNzACJShzFFblAo0CFxpFNBzaAd0DHjIRI4sBJZcBPdwBCQGhAUd2A7kBLBVPngEECHl0UEUMtQETigHMAgUFCc0BBUUlTywdHDgBiAJ+vgKhAU0uAcYCAWQ/5ALUAw1UwQHUBpIBCdQDhgL4AY4CBQICjARbGFBGWzA1CAEMOQH+BRAOCAZywAIDyQZ2MgM3BxsoAgUEBwcHFia3AgcGTBwHBYwBAlcBggFxSGgIrAEEBw4QEqUCASsWadsHCgUCBQMD7QICA3tXCUw7ugJZAwGyAUwpIwM5AwkDBQMJA5sBCw8BNxBVVBwVKhebARkBAwsQEAgEAhESAgQJEBCZATMdzgEBBwG8AQQYKSMUkAEDAwY/CTs4/wEaAUt1AwEDAQUBAgIEAwYEDx1dB2wGeBFgTQ"
LANG = "en_US" LANG = "en_US"
TIMEZONE = 'America/New_York'
GOOGLE_PUBKEY = "AAAAgMom/1a/v0lblO2Ubrt60J2gcuXSljGFQXgcyZWveWLEwo6prwgi3iJIZdodyhKZQrNWp5nKJ3srRXcUW+F1BD3baEVGcmEgqaLZUNBjm057pKRI16kB0YppeGx5qIQ5QjKzsR8ETQbKLNWgRY0QRNVz34kMJR3P/LgHax/6rmf5AAAAAwEAAQ==" GOOGLE_PUBKEY = "AAAAgMom/1a/v0lblO2Ubrt60J2gcuXSljGFQXgcyZWveWLEwo6prwgi3iJIZdodyhKZQrNWp5nKJ3srRXcUW+F1BD3baEVGcmEgqaLZUNBjm057pKRI16kB0YppeGx5qIQ5QjKzsR8ETQbKLNWgRY0QRNVz34kMJR3P/LgHax/6rmf5AAAAAwEAAQ=="
# parse phone config from the file 'device.properties'. # parse phone config from the file 'device.properties'.
@ -28,6 +28,11 @@ filepath = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'device.properties') 'device.properties')
config.read(filepath) config.read(filepath)
device = {} device = {}
# initialize device, because we need to setup UserAgent
# before the end of login method. If the login defines a different
# device, it won't cause conflicts
for (key, value) in config.items('angler'):
device[key] = value
def getDevicesCodenames(): def getDevicesCodenames():
@ -40,12 +45,25 @@ def getDevicesReadableNames():
sections = getDevicesCodenames() sections = getDevicesCodenames()
output = [] output = []
for s in sections: for s in sections:
device = config[s]['userreadablename']
output.append({'codename': s, output.append({'codename': s,
'readableName': config[s]['userreadablename']}) 'readableName': config[s]['userreadablename']})
return output return output
def getUserAgent():
return "Android-Finsky/7.1.15 (" \
"api=3" \
",versionCode={versionCode}" \
",sdk={sdk}" \
",device={device}" \
",hardware={hardware}" \
",product={product}".format(versionCode=device['vending.version'],
sdk=device['build.version.sdk_int'],
device=device['build.device'],
hardware=device['build.hardware'],
product=device['build.product'])
def getDeviceConfig(): def getDeviceConfig():
libList = device['sharedlibraries'].split(",") libList = device['sharedlibraries'].split(",")
featureList = device['features'].split(",") featureList = device['features'].split(",")
@ -53,13 +71,15 @@ def getDeviceConfig():
glList = device['gl.extensions'].split(",") glList = device['gl.extensions'].split(",")
platforms = device['platforms'].split(",") platforms = device['platforms'].split(",")
hasFiveWayNavigation = (device['hasfivewaynavigation'] == 'true')
hasHardKeyboard = (device['hashardkeyboard'] == 'true')
deviceConfig = googleplay_pb2.DeviceConfigurationProto() deviceConfig = googleplay_pb2.DeviceConfigurationProto()
deviceConfig.touchScreen = int(device['touchscreen']) deviceConfig.touchScreen = int(device['touchscreen'])
deviceConfig.keyboard = int(device['keyboard']) deviceConfig.keyboard = int(device['keyboard'])
deviceConfig.navigation = int(device['navigation']) deviceConfig.navigation = int(device['navigation'])
deviceConfig.screenLayout = int(device['screenlayout']) deviceConfig.screenLayout = int(device['screenlayout'])
deviceConfig.hasHardKeyboard = False if device['hashardkeyboard'] == 'false' else True deviceConfig.hasHardKeyboard = hasHardKeyboard
deviceConfig.hasFiveWayNavigation = False if device['hasfivewaynavigation'] == 'false' else True deviceConfig.hasFiveWayNavigation = hasFiveWayNavigation
deviceConfig.screenDensity = int(device['screen.density']) deviceConfig.screenDensity = int(device['screen.density'])
deviceConfig.screenWidth = int(device['screen.width']) deviceConfig.screenWidth = int(device['screen.width'])
deviceConfig.screenHeight = int(device['screen.height']) deviceConfig.screenHeight = int(device['screen.height'])
@ -113,8 +133,8 @@ def getAndroidCheckinRequest(device_codename):
request = googleplay_pb2.AndroidCheckinRequest() request = googleplay_pb2.AndroidCheckinRequest()
request.id = 0 request.id = 0
request.checkin.CopyFrom(getAndroidCheckin()) request.checkin.CopyFrom(getAndroidCheckin())
request.locale = 'en_US' request.locale = LANG
request.timeZone = 'America/New_York' request.timeZone = TIMEZONE
request.version = 3 request.version = 3
request.deviceConfiguration.CopyFrom(getDeviceConfig()) request.deviceConfiguration.CopyFrom(getDeviceConfig())
request.fragment = 0 request.fragment = 0

View File

@ -44,13 +44,11 @@ class GooglePlayAPI(object):
SEARCHURL = FDFE + "search" SEARCHURL = FDFE + "search"
CHECKINURL = BASE + "checkin" CHECKINURL = BASE + "checkin"
AUTHURL = BASE + "auth" AUTHURL = BASE + "auth"
ACCOUNT = "HOSTED_OR_GOOGLE" ACCOUNT = "HOSTED_OR_GOOGLE"
authSubToken = None
gsfId = None
def __init__(self, debug=False): def __init__(self, debug=False):
# you must use a device-associated androidId value self.authSubToken = None
self.gsfId = None
self.lang = config.LANG self.lang = config.LANG
self.debug = debug self.debug = debug
@ -87,11 +85,9 @@ class GooglePlayAPI(object):
can later be updated, based on the request type""" can later be updated, based on the request type"""
headers = { headers = {
"Accept-Language": "en-US", "Accept-Language": config.LANG.replace('_', '-'),
"X-DFE-Encoded-Targets": "X-DFE-Encoded-Targets": config.DFE_TARGETS,
"CAEScFfqlIEG6gUYogFWrAISK1WDAg+hAZoCDgIU1gYEOIACFkLMAeQBnASLATlASUuyAyqCAjY5igOMBQzfA/IClwFbApUC4ANbtgKVAS7OAX8YswHFBhgDwAOPAmGEBt4OfKkB5weSB5AFASkiN68akgMaxAMSAQEBA9kBO7UBFE1KVwIDBGs3go6BBgEBAgMECQgJAQIEAQMEAQMBBQEBBAUEFQYCBgUEAwMBDwIBAgOrARwBEwMEAg0mrwESfTEcAQEKG4EBMxghChMBDwYGASI3hAEODEwXCVh/EREZA4sBYwEdFAgIIwkQcGQRDzQ2fTC2AjfVAQIBAYoBGRg2FhYFBwEqNzACJShzFFblAo0CFxpFNBzaAd0DHjIRI4sBJZcBPdwBCQGhAUd2A7kBLBVPngEECHl0UEUMtQETigHMAgUFCc0BBUUlTywdHDgBiAJ+vgKhAU0uAcYCAWQ/" "User-Agent": config.getUserAgent()
"5ALUAw1UwQHUBpIBCdQDhgL4AY4CBQICjARbGFBGWzA1CAEMOQH+BRAOCAZywAIDyQZ2MgM3BxsoAgUEBwcHFia3AgcGTBwHBYwBAlcBggFxSGgIrAEEBw4QEqUCASsWadsHCgUCBQMD7QICA3tXCUw7ugJZAwGyAUwpIwM5AwkDBQMJA5sBCw8BNxBVVBwVKhebARkBAwsQEAgEAhESAgQJEBCZATMdzgEBBwG8AQQYKSMUkAEDAwY/CTs4/wEaAUt1AwEDAQUBAgIEAwYEDx1dB2wGeBFgTQ",
"User-Agent": "Android-Finsky/7.1.15 (api=3,versionCode=80798000,sdk=23,device=angler,hardware=angler,product=angler)",
} }
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)