This repository has been archived by the owner on Nov 29, 2022. It is now read-only.
forked from bluemutedwisdom/google-play-downloader
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMarket.py
59 lines (42 loc) · 1.47 KB
/
Market.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import re
import zlib
from http_request import http_request
class Market:
LOGIN_PAGE = "https://android.clients.google.com/auth"
LOGIN_SERVICE = "androidsecure"
LOGIN_TYPE = "HOSTED_OR_GOOGLE"
API_PAGE = "https://android.clients.google.com/market/api/ApiRequest"
def __init__(self, email, password):
self.email = email
self.password = password
self.token = None
def login(self):
params = {
"Email": self.email,
"Passwd": self.password,
"service": self.LOGIN_SERVICE,
"accountType": self.LOGIN_TYPE
}
data = http_request(self.LOGIN_PAGE, params)
response = str(data.decode('UTF-8'))
if "Error" in response:
raise Exception("Invalid login credentials.")
for line in response.split("\n"):
if "Auth=" in line:
self.token = line.split("=")[1]
if self.token is None:
raise Exception("Unexpected response.")
def get_asset(self, request):
params = {
"version": 2,
"request": request
}
data = http_request(self.API_PAGE, params)
decompressed = zlib.decompress(data, 16 + zlib.MAX_WBITS)
dl_url = ""
match = re.search(b"(https?:\/\/[^:]+)", decompressed)
if match is None:
raise Exception("Unexpected response.")
else:
dl_url = match.group(1).decode('utf-8')
return dl_url