Skip to content

Commit ab3d123

Browse files
authored
Improved LegacyWhatsApp APK download handler (#97). Thanks @elzdave
Because whatscrypt.com somewhat obsolete, and the archive.org sometimes returning Content-Length 0 on HEAD, I managed to update the whatscrypt CDN server to use another server from androidapksfree.com, and slightly improved the source code for better reading and debugging.
1 parent 5d87ac1 commit ab3d123

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

helpers/handler.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
from custom_ci import custom_input, custom_print
1717

1818
# Global variables
19-
app_url_whatsapp_cdn = 'https://web.archive.org/web/20141111030303if_/http://www.whatsapp.com/android/current/WhatsApp.apk'
20-
app_url_whatscrypt_cdn = 'https://whatcrypt.com/WhatsApp-2.11.431.apk'
21-
19+
app_url_primary_cdn = 'https://web.archive.org/web/20141111030303if_/http://www.whatsapp.com/android/current/WhatsApp.apk'
20+
app_url_alternate_cdn = 'https://legacy-static-assets.androidapksfree.com/earth/androidbucket/WhatsApp-v2.11.431-AndroidBucket.com.apk'
2221

2322
def after_connect(adb):
2423
custom_print(
@@ -39,8 +38,7 @@ def after_connect(adb):
3938
# To check if APK even exists at a given path to download!
4039
# Since that obviously is not available at whatsapp cdn defaulting that content_length to 0 for GH #46
4140
try:
42-
resp = requests.head(
43-
'https://web.archive.org/web/20141111030303if_/http://www.whatsapp.com/android/current/WhatsApp.apk', timeout=5)
41+
resp = requests.head(app_url_primary_cdn, timeout=5)
4442
try:
4543
content_length = resp.headers['content-length']
4644
except KeyError as e:
@@ -51,14 +49,14 @@ def after_connect(adb):
5149
except requests.exceptions.RequestException as e:
5250
custom_print(e, is_print=False)
5351
custom_print(
54-
'An exception has occured while checking for LegacyWhatsApp existence at web.archive.org, defaulting to whatscrypt.com, check log for futher details.', 'yellow')
52+
'An exception has occured while checking for LegacyWhatsApp existence at web.archive.org, defaulting to alternate CDN server, check log for futher details.', 'yellow')
5553
content_length = 0
5654
_version_name_text = f'{adb} shell dumpsys package com.whatsapp'
5755
version_name = re.findall(
5856
"(?<=versionName=)(.*?)(?=\n)", getoutput(_version_name_text))[0]
5957
custom_print(f'WhatsApp v{version_name} installed on device')
60-
download_app_from = app_url_whatsapp_cdn if(
61-
content_length == 18329558) else app_url_whatscrypt_cdn
58+
download_app_from = app_url_primary_cdn if(
59+
content_length == 18329558) else app_url_alternate_cdn
6260
if (version.parse(version_name) > version.parse('2.11.431')):
6361
if not (os.path.isfile('helpers/LegacyWhatsApp.apk')):
6462
custom_print(
@@ -93,9 +91,9 @@ def download_apk(url, file_name):
9391
'\aFor some reason I could not download Legacy WhatsApp, you need to download it on your own now from either of the links given below: ', 'red')
9492
custom_print('\n', is_get_time=False)
9593
custom_print(
96-
f'1. \"{app_url_whatsapp_cdn}\" (official\'s archive)', 'red')
94+
f'1. \"{app_url_primary_cdn}\" (official\'s archive)', 'red')
9795
custom_print(
98-
f'2. \"{app_url_whatscrypt_cdn}\" unofficial website.', 'red')
96+
f'2. \"{app_url_alternate_cdn}\" unofficial website.', 'red')
9997
custom_print('\n', is_get_time=False)
10098
custom_print(
10199
'Once downloaded rename it to \"LegacyWhatsApp.apk\" exactly and put in \"helpers\" folder.', 'red')

wa_kdbe.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939
if platform.system() == 'Linux':
4040
is_linux = True
4141

42-
# Global Variables
43-
app_url_whatsapp_cdn = 'https://www.cdn.whatsapp.net/android/2.11.431/WhatsApp.apk'
44-
app_url_whatscrypt_cdn = 'https://whatcrypt.com/WhatsApp-2.11.431.apk'
45-
46-
4742
def main():
4843
custom_print('>>> I am in wa_kdbe.main()', is_print=False)
4944
os.system('cls' if os.name == 'nt' else 'clear')

0 commit comments

Comments
 (0)