mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-31 05:23:28 +01:00 
			
		
		
		
	Enabled WhatsApp Source (#357)
This commit is contained in:
		| @@ -16,14 +16,13 @@ class WhatsApp extends AppSource { | ||||
|   @override | ||||
|   Future<String> apkUrlPrefetchModifier( | ||||
|       String apkUrl, String standardUrl) async { | ||||
|     Response res = await sourceRequest('https://www.whatsapp.com/android'); | ||||
|     Response res = await sourceRequest('$standardUrl/android'); | ||||
|     if (res.statusCode == 200) { | ||||
|       var targetLinks = parse(res.body) | ||||
|           .querySelectorAll('a') | ||||
|           .map((e) => e.attributes['href'] ?? '') | ||||
|           .where((e) => e.isNotEmpty) | ||||
|           .where((e) => | ||||
|               e.contains('content.whatsapp.net') && e.contains('WhatsApp.apk')) | ||||
|           .where((e) => e.contains('WhatsApp.apk')) | ||||
|           .toList(); | ||||
|       if (targetLinks.isEmpty) { | ||||
|         throw NoAPKError(); | ||||
| @@ -39,37 +38,16 @@ class WhatsApp extends AppSource { | ||||
|     String standardUrl, | ||||
|     Map<String, dynamic> additionalSettings, | ||||
|   ) async { | ||||
|     Response res = await sourceRequest('https://www.whatsapp.com/android'); | ||||
|     if (res.statusCode == 200) { | ||||
|       var targetElements = parse(res.body) | ||||
|           .querySelectorAll('p') | ||||
|           .where((element) => element.innerHtml.contains('Version ')) | ||||
|           .toList(); | ||||
|       if (targetElements.isEmpty) { | ||||
|         throw NoVersionError(); | ||||
|       } | ||||
|       var vLines = targetElements[0] | ||||
|           .innerHtml | ||||
|           .split('\n') | ||||
|           .where((element) => element.contains('Version ')) | ||||
|           .toList(); | ||||
|       if (vLines.isEmpty) { | ||||
|         throw NoVersionError(); | ||||
|       } | ||||
|       var versionMatch = RegExp('[0-9]+(\\.[0-9]+)+').firstMatch(vLines[0]); | ||||
|       if (versionMatch == null) { | ||||
|         throw NoVersionError(); | ||||
|       } | ||||
|       String version = | ||||
|           vLines[0].substring(versionMatch.start, versionMatch.end); | ||||
|       return APKDetails( | ||||
|           version, | ||||
|           getApkUrlsFromUrls([ | ||||
|             'https://www.whatsapp.com/android?v=$version&=thisIsaPlaceholder&a=realURLPrefetchedAtDownloadTime' | ||||
|           ]), | ||||
|           AppNames('Meta', 'WhatsApp')); | ||||
|     } else { | ||||
|       throw getObtainiumHttpError(res); | ||||
|     } | ||||
|     // This is a CDN link that is consistent per version | ||||
|     // But it has query params that change constantly | ||||
|     Uri apkUri = | ||||
|         Uri.parse(await apkUrlPrefetchModifier(standardUrl, standardUrl)); | ||||
|     var unusableApkUrl = '${apkUri.origin}/${apkUri.path}'; | ||||
|     // So we use the param-less URL is a pseudo-version to add the app and check for updates | ||||
|     // See #357 for why we can't scrape the version number directly | ||||
|     // But we re-fetch the URL again with its latest query params at the actual download time | ||||
|     String version = unusableApkUrl.hashCode.toString(); | ||||
|     return APKDetails(version, getApkUrlsFromUrls([unusableApkUrl]), | ||||
|         AppNames('Meta', 'WhatsApp')); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user