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
/
gplay-downloader.py
executable file
·117 lines (93 loc) · 5.57 KB
/
gplay-downloader.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/python
#
# This file is part of GooglePlay Downloader.
#
# Copyright(c) 2012-2013 Simone Margaritelli aka evilsocket
# http://www.evilsocket.net
#
# This file may be licensed under the terms of of the
# GNU General Public License Version 2 (the ``GPL'').
#
# Software distributed under the License is distributed
# on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
# express or implied. See the GPL for the specific language
# governing rights and limitations.
#
# You should have received a copy of the GPL along with this
# program. If not, go to http://www.gnu.org/licenses/gpl.html
# or write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import traceback
import json
from constants import defaults
from ExtendedOptionParser import ExtendedOptionParser
from Market import Market
from OperatorModel import Operator
from AssetRequest import AssetRequest
from Util import Util
from http_request import set_default_proxy
def main():
print("\n\tGooglePlay Downloader - Directly download apks from GooglePlay to your PC.\n" +
"\tCopyleft Simone Margaritelli <[email protected]>\n" +
"\thttp://www.evilsocket.net\n\n")
usage = """usage: %prog [options]
EXAMPLE:
%prog --email [email protected] --password your-password --name com.arttech.xbugsfree --country "Italy" --operator "3" --device your-device-id
"""
parser = ExtendedOptionParser(defaults=defaults, usage=usage)
parser.add_option_with_default("-e", "--email", action="store", dest="email", help="Your android account email.")
parser.add_option_with_default("-p", "--password", action="store", dest="password", help="Your android account password.")
parser.add_option_with_default("-n", "--name", action="store", dest="package", help="Package identifier (com.something.name).")
parser.add_option_with_default("-c", "--country", action="store", dest="country", help="Your country.")
parser.add_option_with_default("-o", "--operator", action="store", dest="operator", help="Your phone operator.")
parser.add_option_with_default("-d", "--device", action="store", dest="device", help="Your device ID (can be obtained with this app https://play.google.com/store/apps/details?id=com.redphx.deviceid) .")
parser.add_option_with_default("-s", "--sdklevel", action="store", dest="sdklevel", help="Android SDK API level (default is 19 like Android 4.4).")
parser.add_option_with_default("-m", "--devname", action="store", dest="devname", help="Device name (default 'passion' like HTC Passion aka Google Nexus One.")
parser.add_option_with_default("-t", "--dry-run", action="store_true", dest="dry_run", help="Test only, a.k.a. dry run")
parser.add_option_with_default("--proxy", action="store", dest="proxy", default=None, help="Proxy server to use. Use the form user:pass@host:port")
parser.add_option_with_default("--proxy-auth-digest", action="store_true", default=None, dest="proxy_auth_digest", help="Use digest authentication in proxies. Default is basic authentication")
parser.add_option("-f", "--config", action="store", dest="config", default=None, help="Load additional settings from the specified config file. Parameters in this file always overwrite command line settings.")
(o, args) = parser.parse_args()
option_pool = {}
for key in defaults:
option_pool[key] = getattr(o, key)
if o.config is not None:
config = json.loads(open(o.config, 'rb').read().decode('utf-8'))
for key in config:
# in Python 2.x, json results are unicode
option_pool[key] = str(config[key])
if option_pool['email'] is None:
print("No email specified.")
elif option_pool['password'] is None:
print("No password specified.")
elif option_pool['package'] is None:
print("No package specified.")
elif option_pool['country'] is None or option_pool['country'] not in Operator.OPERATORS:
print("Empty or invalid country specified, choose from: \n\n" + ", ".join(Operator.OPERATORS.keys()))
elif option_pool['operator'] is None or option_pool['operator'] not in Operator.OPERATORS[option_pool['country']]:
print("Empty or invalid operator specified, choose from: \n\n" + ", ".join(Operator.OPERATORS[option_pool['country']].keys()))
elif option_pool['device'] is None:
print("No device id specified.")
elif int(option_pool['sdklevel']) < 2:
print("The SDK API level cannot be less than 2.")
else:
if option_pool['proxy']:
set_default_proxy(
option_pool['proxy'],
'digest' if option_pool['proxy_auth_digest'] else 'basic')
print("@ Logging in ...")
market = Market(option_pool['email'], option_pool['password'])
market.login()
print("@ Requesting package ...")
operator = Operator(option_pool['country'], option_pool['operator'])
request = AssetRequest(option_pool['package'], market.token, option_pool['device'], operator, option_pool['devname'], int(option_pool['sdklevel']))
url = market.get_asset(request.encode())
if not option_pool['dry_run']:
print("@ Downloading...\n")
Util.download_apk(option_pool['package'], url)
if __name__ == '__main__':
try:
main()
except Exception as e:
print(traceback.format_exc())