mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-11 01:20:16 +02:00
Enabled WhatsApp Source (#357)
This commit is contained in:
@@ -16,14 +16,13 @@ class WhatsApp extends AppSource {
|
|||||||
@override
|
@override
|
||||||
Future<String> apkUrlPrefetchModifier(
|
Future<String> apkUrlPrefetchModifier(
|
||||||
String apkUrl, String standardUrl) async {
|
String apkUrl, String standardUrl) async {
|
||||||
Response res = await sourceRequest('https://www.whatsapp.com/android');
|
Response res = await sourceRequest('$standardUrl/android');
|
||||||
if (res.statusCode == 200) {
|
if (res.statusCode == 200) {
|
||||||
var targetLinks = parse(res.body)
|
var targetLinks = parse(res.body)
|
||||||
.querySelectorAll('a')
|
.querySelectorAll('a')
|
||||||
.map((e) => e.attributes['href'] ?? '')
|
.map((e) => e.attributes['href'] ?? '')
|
||||||
.where((e) => e.isNotEmpty)
|
.where((e) => e.isNotEmpty)
|
||||||
.where((e) =>
|
.where((e) => e.contains('WhatsApp.apk'))
|
||||||
e.contains('content.whatsapp.net') && e.contains('WhatsApp.apk'))
|
|
||||||
.toList();
|
.toList();
|
||||||
if (targetLinks.isEmpty) {
|
if (targetLinks.isEmpty) {
|
||||||
throw NoAPKError();
|
throw NoAPKError();
|
||||||
@@ -39,37 +38,16 @@ class WhatsApp extends AppSource {
|
|||||||
String standardUrl,
|
String standardUrl,
|
||||||
Map<String, dynamic> additionalSettings,
|
Map<String, dynamic> additionalSettings,
|
||||||
) async {
|
) async {
|
||||||
Response res = await sourceRequest('https://www.whatsapp.com/android');
|
// This is a CDN link that is consistent per version
|
||||||
if (res.statusCode == 200) {
|
// But it has query params that change constantly
|
||||||
var targetElements = parse(res.body)
|
Uri apkUri =
|
||||||
.querySelectorAll('p')
|
Uri.parse(await apkUrlPrefetchModifier(standardUrl, standardUrl));
|
||||||
.where((element) => element.innerHtml.contains('Version '))
|
var unusableApkUrl = '${apkUri.origin}/${apkUri.path}';
|
||||||
.toList();
|
// So we use the param-less URL is a pseudo-version to add the app and check for updates
|
||||||
if (targetElements.isEmpty) {
|
// See #357 for why we can't scrape the version number directly
|
||||||
throw NoVersionError();
|
// But we re-fetch the URL again with its latest query params at the actual download time
|
||||||
}
|
String version = unusableApkUrl.hashCode.toString();
|
||||||
var vLines = targetElements[0]
|
return APKDetails(version, getApkUrlsFromUrls([unusableApkUrl]),
|
||||||
.innerHtml
|
AppNames('Meta', 'WhatsApp'));
|
||||||
.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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,7 @@ import 'package:obtainium/app_sources/steammobile.dart';
|
|||||||
import 'package:obtainium/app_sources/telegramapp.dart';
|
import 'package:obtainium/app_sources/telegramapp.dart';
|
||||||
import 'package:obtainium/app_sources/uptodown.dart';
|
import 'package:obtainium/app_sources/uptodown.dart';
|
||||||
import 'package:obtainium/app_sources/vlc.dart';
|
import 'package:obtainium/app_sources/vlc.dart';
|
||||||
|
import 'package:obtainium/app_sources/whatsapp.dart';
|
||||||
import 'package:obtainium/components/generated_form.dart';
|
import 'package:obtainium/components/generated_form.dart';
|
||||||
import 'package:obtainium/custom_errors.dart';
|
import 'package:obtainium/custom_errors.dart';
|
||||||
import 'package:obtainium/mass_app_sources/githubstars.dart';
|
import 'package:obtainium/mass_app_sources/githubstars.dart';
|
||||||
@@ -557,7 +558,7 @@ class SourceProvider {
|
|||||||
Mullvad(),
|
Mullvad(),
|
||||||
Signal(),
|
Signal(),
|
||||||
VLC(),
|
VLC(),
|
||||||
// WhatsApp(), // As of 2023-03-20 this is unusable as the version on the webpage is months out of date
|
WhatsApp(), // As of 2023-03-20 this is unusable as the version on the webpage is months out of date
|
||||||
TelegramApp(),
|
TelegramApp(),
|
||||||
SteamMobile(),
|
SteamMobile(),
|
||||||
NeutronCode(),
|
NeutronCode(),
|
||||||
|
Reference in New Issue
Block a user