mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-16 06:36:44 +02:00
Fixed Mullvad web scraping (again)
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
import 'package:html/parser.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:obtainium/app_sources/github.dart';
|
||||
import 'package:obtainium/app_sources/html.dart';
|
||||
import 'package:obtainium/custom_errors.dart';
|
||||
import 'package:obtainium/providers/source_provider.dart';
|
||||
|
||||
@ -29,24 +28,41 @@ class Mullvad extends AppSource {
|
||||
String standardUrl,
|
||||
Map<String, dynamic> additionalSettings,
|
||||
) async {
|
||||
var details = await HTML().getLatestAPKDetails(
|
||||
'$standardUrl/en/download/android', additionalSettings);
|
||||
var fileName = details.apkUrls[0].split('/').last;
|
||||
var versionMatch = RegExp('[0-9]+(\\.[0-9]+)+').firstMatch(fileName);
|
||||
if (versionMatch == null) {
|
||||
throw NoVersionError();
|
||||
Response res = await get(Uri.parse('$standardUrl/en/download/android'));
|
||||
if (res.statusCode == 200) {
|
||||
var versions = parse(res.body)
|
||||
.querySelectorAll('p')
|
||||
.map((e) => e.innerHtml)
|
||||
.where((p) => p.contains('Latest version: '))
|
||||
.map((e) {
|
||||
var match = RegExp('[0-9]+(\\.[0-9]+)*').firstMatch(e);
|
||||
if (match == null) {
|
||||
return '';
|
||||
} else {
|
||||
return e.substring(match.start, match.end);
|
||||
}
|
||||
})
|
||||
.where((element) => element.isNotEmpty)
|
||||
.toList();
|
||||
if (versions.isEmpty) {
|
||||
throw NoVersionError();
|
||||
}
|
||||
String? changeLog;
|
||||
try {
|
||||
changeLog = (await GitHub().getLatestAPKDetails(
|
||||
'https://github.com/mullvad/mullvadvpn-app',
|
||||
{'fallbackToOlderReleases': true}))
|
||||
.changeLog;
|
||||
} catch (e) {
|
||||
// Ignore
|
||||
}
|
||||
return APKDetails(
|
||||
versions[0],
|
||||
['https://mullvad.net/download/app/apk/latest'],
|
||||
AppNames(name, 'Mullvad-VPN'),
|
||||
changeLog: changeLog);
|
||||
} else {
|
||||
throw getObtainiumHttpError(res);
|
||||
}
|
||||
details.version = fileName.substring(versionMatch.start, versionMatch.end);
|
||||
details.names = AppNames(name, 'Mullvad-VPN');
|
||||
try {
|
||||
details.changeLog = (await GitHub().getLatestAPKDetails(
|
||||
'https://github.com/mullvad/mullvadvpn-app',
|
||||
{'fallbackToOlderReleases': true}))
|
||||
.changeLog;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
// Ignore
|
||||
}
|
||||
return details;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user