-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy path_downloader.py
415 lines (348 loc) · 14.3 KB
/
_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# -*- coding:utf-8 -*-
from urllib import request
from selenium import webdriver
from _googleplayapi import GooglePlayAPI
import urllib, time, requests, re, os, json
def get_apk_download_link(market, data, url):
if market == 'yingyongbao':
matcher = re.findall('data-apkurl=".*?"', data)
if len(matcher): return matcher[0].replace('data-apkurl="', "").replace('"', "")
elif market == 'baidu':
matcher = re.findall('<span class="one-setup-btn".*?data_url=".*?"', data, re.S)
if len(matcher): return re.subn('<span class="one-setup-btn".*?data_url="', "", matcher[0].replace("\r", "").replace("\n", ""))[0].replace('"', "")
elif market == '360':
matcher = re.findall('url=.*?.apk" data-sid=', data)
if len(matcher): return matcher[0].replace('url=', "").replace('" data-sid=', "")
elif market == 'googleplay':
return url
elif market == 'huawei':
matcher = re.findall('dlurl=".*?"', data)
if len(matcher): return matcher[0].replace('dlurl="', "").replace('"', "")
elif market == 'xiaomi':
matcher = re.findall('<div class="app-info-down"><a href=".*?"', data)
if len(matcher): return 'http://app.mi.com'+matcher[0].replace('<div class="app-info-down"><a href="', "").replace('"', "")
elif market == 'wandoujia':
return url+"/download"
elif market == 'hiapk':
matcher = re.findall('<a href="/appdown/.*?" class="link_btn"', data)
if len(matcher): return 'http://apk.hiapk.com'+matcher[0].replace('<a href="', "").replace('" class="link_btn"', "")
elif market == 'anzhi':
matcher = re.findall('<a href="#" onclick="opendown\([0-9]+\);"', data)
if len(matcher): return 'http://www.anzhi.com/dl_app.php?s='+matcher[0].replace('<a href="#" onclick="opendown(', "").replace(');"', "")+'&n=5'
elif market == '91':
matcher = re.findall(' href=".*?">下载到电脑', data)
if len(matcher): return 'http://apk.91.com'+matcher[0].replace(' href="', "").replace('">下载到电脑', "")
elif market == 'oppo':
matcher = re.findall('<a class="detail_down" onclick="detailInfoDownload\([0-9]+\)">下载到电脑</a>', data)
if len(matcher): return 'http://store.oppomobile.com/product/download.html?id='+matcher[0].replace('<a class="detail_down" onclick="detailInfoDownload(', "").replace(')">下载到电脑</a>', "")+'&from=0_0'
elif market == 'pp':
matcher = re.findall('appdownurl=".*?".*?data.*?">立即下载</a>', data)
if len(matcher): return matcher[0].split('"')[1]
elif market == 'sogou':
return "http://zhushou.sogou.com/apps/download.html?appid="+url.split('/')[-1].replace(".html", "")
elif market == 'gfan':
matcher = re.findall('<a href=".*?".*?title="下载到电脑"><i class="bt-ico3"></i>下载到电脑</a>', data)
if len(matcher): return matcher[0].split('"')[1]
elif market == 'meizu':
matcher = re.findall('data-appid="[0-9]+', data)
if '?' in url and len(matcher): return url.split('?')[0].replace('detail', 'download.json?app_id=')+matcher[0].replace('data-appid="', "")
elif market == 'sina':
matcher = re.findall('<a href=".*?" class="avBtn avBtn-down">立即下载</a>', data)
if len(matcher): return 'http://app.sina.com.cn'+matcher[0].split('"')[1]
elif market == 'dcn':
matcher = re.findall('onclick="Adapt.downPush\(\'.*?\'.*?立即下载</a></li>', data)
if len(matcher): return matcher[0].split("'")[1]
elif market == 'liqucn':
matcher = re.findall('<a href=".*?" target=".*?">下载到电脑</a>', data)
if len(matcher): return matcher[0].split('"')[1]
elif market == 'appchina':
matcher = re.findall('onclick="freeDownload\(this,'.*?;\)">免费下载</a>', data)
if len(matcher): return matcher[0].split(';')[1]
elif market == '10086':
matcher = re.findall('<span></span></div><a href=".*?" class="mj_xzdbd"', data)
if len(matcher): return matcher[0].split('"')[1]
elif market == 'lenovo':
matcher = re.findall('<a href=".*?" data-pkgname=".*?".*?<span>下载APK文件', data)
if len(matcher): return matcher[0].split('"')[1]
elif market == 'zol':
matcher = re.findall('<a id="down_main_android".*?corpsoft\(\'.*?\'', data)
if len(matcher): return matcher[0].split("'")[-2]
elif market == 'nduo':
matcher = re.findall('<a href=".*?".*?><span></span>立即下载</a>', data)
if len(matcher): return matcher[0].split('"')[1]
elif market == 'cnmo':
matcher = re.findall('appLocalDownloadUrl=".*?"', data)
if len(matcher): return matcher[0].split('"')[1]
elif market == 'pconline':
matcher = re.findall('<a href=".*?\.apk" rel="nofollow" class="btn dl-btn"', data)
if len(matcher): return matcher[0].split('"')[1]
elif market == 'appcool':
matcher = re.findall('<a href=".*?" class="det-butn-1"></a>', data)
if len(matcher): return matcher[0].split('"')[1]
return ""
def get_icon_download_link(market, data):
if market == 'yingyongbao':
matcher = re.findall('<div class="det-icon">.*?src=".*?"', data, re.S)
if len(matcher): return matcher[0].split('"')[-2]
elif market == 'baidu':
matcher = re.findall('<div class="app-pic">.*?=".*?"', data, re.S)
if len(matcher): return matcher[0].split('"')[-2]
elif market == '360':
matcher = re.findall('<dt>.*?<img src=".*?"', data, re.S)
if len(matcher): return matcher[0].split('"')[-2]
elif market == 'googleplay':
matcher = re.findall('<img class="cover-image" src=".*?"', data)
if len(matcher): return 'https:'+matcher[0].split('"')[-2]
elif market == 'huawei':
matcher = re.findall('img class="app-ico" lazyload=".*?"', data)
if len(matcher): return matcher[0].split('"')[-2]
elif market == 'xiaomi':
matcher = re.findall('<img class="yellow-flower" src=".*?"', data)
if len(matcher): return matcher[0].split('"')[-2]
elif market == 'wandoujia':
matcher = re.findall('<img src=".*?" itemprop="image" width="110" height="110"', data)
if len(matcher): return matcher[0].split('"')[-8]
elif market == 'hiapk':
matcher = re.findall('<img.*?src=".*?".*?ICON"', data)
if len(matcher):
matcher = re.findall('src=".*?"', matcher[0])
if len(matcher): return matcher[0].split('"')[-2]
elif market == 'anzhi':
matcher = re.findall('var ICON="http://.*?";', data)
if len(matcher): return matcher[0].split('"')[-2]
elif market == '91':
matcher = re.findall('<img src=".*?" alt=".*?"', data)
if len(matcher): return matcher[0].split('"')[-4]
elif market == 'oppo':
matcher = re.findall('<img class=".*?" dataimg="http://.*?" />', data)
if len(matcher): return matcher[0].split('"')[-2]
elif market == 'pp':
matcher = re.findall('<div class="detail-header clearfix"><div class="app-icon"><img src=".*?".*?</div>', data)
if len(matcher): return matcher[0].split('"')[5]
elif market == 'sogou':
matcher = re.findall('<img class="icon" width="[0-9]+" height="[0-9]+" src=".*?"', data)
if len(matcher): return matcher[0].split('"')[-2]
elif market == 'gfan':
matcher = re.findall('<img class="app-view png" src=".*?" alt=".*?"/>', data)
if len(matcher): return matcher[0].split('"')[-4]
elif market == 'meizu':
matcher = re.findall('<img class="app_img" src=".*?">\n', data)
if len(matcher): return matcher[0].split('"')[-2]
elif market == 'sina':
matcher = re.findall('<div class="avIcon"><img src=".*?".*?</div>', data)
if len(matcher): return matcher[0].split('"')[3]
elif market == 'dcn':
matcher = re.findall('<img src=".*?".*?class="de-app-icon">', data)
if len(matcher): return matcher[0].split('"')[1]
elif market == 'liqucn':
matcher = re.findall('<img src=".*?" />\n.*?<h1>', data)
if len(matcher): return matcher[0].split('"')[1]
elif market == 'appchina':
matcher = re.findall('<img class="Content_Icon".*?title=".*?" src=".*?"', data)
if len(matcher): return matcher[0].split('"')[-2]
elif market == '10086':
matcher = re.findall('<img id="appicon" src=".*?"', data)
if len(matcher): return matcher[0].split('"')[-2]
elif market == 'lenovo':
matcher = re.findall('<img src=".*?" alt=".*?"><i', data)
if len(matcher): return matcher[0].split('"')[1]
elif market == 'zol':
matcher = re.findall('<img src=".*?".*?><i class="marsk"></i>', data)
if len(matcher): return matcher[0].split('"')[1]
elif market == 'nduo':
matcher = re.findall('<img src=".*?" width="120" height="120"', data)
if len(matcher): return matcher[0].split('"')[1]
elif market == 'cnmo':
matcher = re.findall('<img width="80" height="80" src=".*?">', data)
if len(matcher): return matcher[0].split('"')[-2]
elif market == 'pconline':
matcher = re.findall('<img width="80" height="80" alt=".*?" src=".*?">\r?\n', data)
if len(matcher): return matcher[0].split('"')[-2]
elif market == 'appcool':
matcher = re.findall('<img src=".*?" original=".*?" width="72" height="72" />', data)
if len(matcher): return matcher[0].split('"')[3]
return ""
def download_apk(market, url, apkfile, config):
#Windows
#phantomjs_execute_path = 'phantomjs\\bin\\phantomjs.exe'
#Linux
phantomjs_execute_path = '/usr/lib/phantomjs/phantomjs'
if market == 'googleplay':
if not len(url): return False
packagename = url.split("=")[1]
for i in range(10):
try:
api = GooglePlayAPI(config['ANDROID_ID'])
api.login(config['GOOGLE_LOGIN'], config['GOOGLE_PASSWORD'], packagename)
m = api.details(packagename)
doc = m.docV2
vc = doc.details.appDetails.versionCode
ot = doc.offer[0].offerType
if api.download(packagename, vc, ot, apkfile): return True
except:
continue
elif market == 'sogou':
if not len(url): return False
for i in range(10):
try:
web = requests.get(url, stream=True, timeout=30)
content = ""
for chunk in web.iter_content(chunk_size=204800):
if chunk:
content += chunk.decode()
matcher = re.findall('"file_url":".*?"', content)
if len(matcher):
file_url = matcher[0].replace('"file_url":"', "").replace('"', "").replace('\\', "")
web = requests.get(file_url, stream=True, timeout=30)
with open(apkfile, 'wb') as fout:
for chunk in web.iter_content(chunk_size=204800):
if chunk:
fout.write(chunk)
fout.flush()
fout.close()
return True
else:
continue
except:
continue
elif market == 'gfan':
if not len(url): return False
if not 'apk=' in url: return False
referer = 'http://apk.gfan.com/Product/App'+url.split('=')[-1]+'.html'
headers = {'Referer': referer}
for i in range(10):
try:
urlnew = url
web = requests.get(urlnew, stream=True, timeout=30, headers=headers)
j = 0
while web.status_code == 302 and j <= 4:
j += 1
if 'Location' in web.headers:
urlnew = web.headers['Location']
web = requests.get(urlnew, stream=True, timeout=30, headers=headers)
else:
break
if web.status_code == 200:
with open(apkfile, 'wb') as fout:
for chunk in web.iter_content(chunk_size=204800):
if chunk:
fout.write(chunk)
fout.flush()
fout.close()
return True
except:
continue
elif market == 'meizu':
if not len(url): return False
for i in range(10):
try:
if i % 2 == 0: urlnew = url.replace('/games/', '/apps/')
else: urlnew = url.replace('/apps/', '/games/')
web = requests.get(urlnew, stream=True, timeout=30)
content = ""
for chunk in web.iter_content(chunk_size=204800):
if chunk:
content += chunk.decode()
matcher = re.findall('"downloadUrl":".*?"', content)
if len(matcher):
file_url = matcher[0].replace('"downloadUrl":', "").replace('"', "").replace('\\', "")
web = requests.get(file_url, stream=True, timeout=30)
with open(apkfile, 'wb') as fout:
for chunk in web.iter_content(chunk_size=204800):
if chunk:
fout.write(chunk)
fout.flush()
fout.close()
return True
else:
continue
except:
continue
elif market == 'cnmo':
if not len(url): return False
for i in range(10):
try:
urlnew = os.popen(phantomjs_execute_path+" _location.js "+url).read().split('\n')[-2].replace('\r', "")
web = requests.get(urlnew, stream=True, timeout=30)
with open(apkfile, 'wb') as fout:
for chunk in web.iter_content(chunk_size=204800):
if chunk:
fout.write(chunk)
fout.flush()
fout.close()
return True
except:
continue
else:
if not len(url): return False
for i in range(10):
try:
web = requests.get(url, stream=True, timeout=30)
with open(apkfile, 'wb') as fout:
for chunk in web.iter_content(chunk_size=204800):
if chunk:
fout.write(chunk)
fout.flush()
fout.close()
return True
except:
continue
return False
def download_icon(market, url, pngfile):
if not len(url):
return False
else:
for i in range(10):
try:
web = requests.get(url, stream=True, timeout=30)
with open(pngfile, 'wb') as fout:
for chunk in web.iter_content(chunk_size=204800):
if chunk:
fout.write(chunk)
fout.flush()
fout.close()
return True
except:
continue
return False
if __name__ == '__main__':
config = {
'ANDROID_ID': "",
'GOOGLE_LOGIN': "",
'GOOGLE_PASSWORD': ""
}
try:
if os.path.isfile("config.json"):
with open("config.json") as jsonfile:
config_dict = json.load(jsonfile)
for key in config.keys():
if key in config_dict:
config[key] = config_dict[key]
print("读取Config成功")
else:
print("Config不存在")
exit()
except:
print("读取Config失败")
exit()
if os.path.isfile("Google_Play_Download_List.txt"):
apk_list = open('Google_Play_Download_List.txt', 'r').read().replace('\r', "").split("\n")
print("读取下载列表成功")
fout = open('Google_Play_Download.log', 'w')
for apk in apk_list:
if len(apk):
url = 'https://play.google.com/store/apps/details?id='+apk
if not os.path.exists('Google_Play_Download'):
os.makedirs('Google_Play_Download')
success = download_apk('googleplay', url, 'Google_Play_Download/'+apk+'.apk', config)
if success:
print('下载成功 '+apk)
fout.write('Success '+apk+'\n')
else:
print('下载失败 '+apk)
fout.write('Failed '+apk+'\n')
fout.flush()
fout.close()
else:
print("下载列表不存在")
exit()