Compare commits

...

2 Commits

Author SHA1 Message Date
187efa8fc5 Merge pull request #406 from ImranR98/dev
Fixed Mullvad web scraping (again)
2023-03-31 09:25:50 -04:00
cd27ff7f2d Fixed Mullvad web scraping (again) 2023-03-31 09:24:15 -04:00
3 changed files with 37 additions and 21 deletions

View File

@ -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;
}
}

View File

@ -21,7 +21,7 @@ import 'package:easy_localization/src/easy_localization_controller.dart';
// ignore: implementation_imports
import 'package:easy_localization/src/localization.dart';
const String currentVersion = '0.11.17';
const String currentVersion = '0.11.18';
const String currentReleaseTag =
'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES

View File

@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.11.17+139 # When changing this, update the tag in main() accordingly
version: 0.11.18+140 # When changing this, update the tag in main() accordingly
environment:
sdk: '>=2.18.2 <3.0.0'