forked from m4ll0k/BBTz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dapk.py
112 lines (82 loc) · 2.94 KB
/
dapk.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
#!/usr/bin/env pytho
# by @m4ll0k
#
# dapk.py - download all apk versions of an org from apkmirror.com
# usage
'''
E.g: Downlad all paypal apk
$ python3 dapk.py "paypal" "paypal-apk"
Without threads so it will be slow, however this is just an example, you can improve this tool
'''
import requests
import os
import re
import sys
from lxml.html import fromstring as FS
HEADERS = {
'User-Agent':'Mozilla/5.0'
}
LIST_OF_PK = [
# (url,package_name)
]
APKM_URL = 'https://www.apkmirror.com'
if len(sys.argv) <= 2:
sys.exit(print(f'\npython3 {sys.argv[0]} <name-of-packages> <output-dir>\n'))
NAME_PK = sys.argv[1]
DIRECTORY = sys.argv[2]
if os.path.exists(DIRECTORY):
if os.path.isdir(DIRECTORY) is True:
pass
else:
sys.exit(print('[ ! ] Check your directory output!'))
else:
os.mkdir(DIRECTORY)
def download_apk(url,pkname):
print(f'[ + ] Download.. {pkname} -> {os.path.abspath(DIRECTORY+"/"+pkname)}')
r = requests.get(url,stream=True,headers=HEADERS)
open(f'{DIRECTORY}/{pkname}','wb').write(r.content)
def get_pages_len():
l = [f'https://www.apkmirror.com/uploads/?q={NAME_PK}']
r = requests.get(l[0],headers=HEADERS)
for href in FS(r.content or "").xpath('//a[@class="page larger"]/@href'):
href = APKM_URL + href
if href not in l:
l.append(href)
return [] if 'No uploads found' in (r.content.decode('utf-8') or ' ') else l
def get_all_info(url):
r = requests.get(url,headers=HEADERS)
for href in FS(r.content).xpath('//div[@class="iconsBox "]/div[@class="downloadIconPositioning"]/a/@href'):
href = APKM_URL + href
ADD = (href,href.split('/')[-2] + '.apk')
if ADD not in LIST_OF_PK:
LIST_OF_PK.append(
ADD
)
def getDowloadUrl(content):
for i in FS(content).xpath('//@href'):
if '/wp-content/themes/APKMirror/download.php' in i:
return APKM_URL + i
def get_apk_only(url,pkname):
r = requests.get(url,headers=HEADERS)
ally = FS(r.content).xpath('//div[@class="table topmargin variants-table"]/*')
if type(ally) is list and ally != []:
ally.pop(0)
for dom in ally:
if '\nBUNDLEAPK' in dom.text_content():
pass
elif '\nAPK' in dom.text_content():
for i in list(set(dom.xpath('div[@class="table-cell rowheight addseparator expand pad dowrap"]/a/@href'))):
href = APKM_URL + i +'download/?forcebaseapk'
r = requests.get(href,headers=HEADERS)
download_apk(getDowloadUrl(r.content),pkname)
def main():
lens = get_pages_len()
if lens == []:
sys.exit(print(f'[ ! ] {NAME_PK} not found! Check here https://www.apkmirror.com/uploads/?q={NAME_PK}'))
print(f'[ + ] Found {len(lens)} pages..')
for url in lens:
get_all_info(url)
print(f'[ + ] Found {len(LIST_OF_PK)} releases..')
for t in LIST_OF_PK:
get_apk_only(t[0],t[1])
main()