diff --git a/lib/app_sources/vlc.dart b/lib/app_sources/vlc.dart index bbdec76..6787996 100644 --- a/lib/app_sources/vlc.dart +++ b/lib/app_sources/vlc.dart @@ -1,5 +1,6 @@ import 'package:html/parser.dart'; import 'package:http/http.dart'; +import 'package:obtainium/app_sources/html.dart'; import 'package:obtainium/custom_errors.dart'; import 'package:obtainium/providers/source_provider.dart'; @@ -7,55 +8,60 @@ class VLC extends AppSource { VLC() { host = 'videolan.org'; } + get dwUrlBase => 'https://get.$host/vlc-android/'; + + @override + Map? get requestHeaders => HTML().requestHeaders; @override String sourceSpecificStandardizeURL(String url) { return 'https://$host'; } + Future getLatestVersion(String standardUrl) async { + Response res = await sourceRequest(dwUrlBase); + if (res.statusCode == 200) { + var dwLinks = parse(res.body) + .querySelectorAll('a') + .where((element) => element.attributes['href'] != 'last/') + .map((e) => e.attributes['href']?.split('/')[0]) + .toList(); + String? version = dwLinks.isNotEmpty ? dwLinks.last : null; + if (version == null) { + throw NoVersionError(); + } + return version; + } else { + throw getObtainiumHttpError(res); + } + } + @override Future getLatestAPKDetails( String standardUrl, Map additionalSettings, ) async { - Response res = await sourceRequest( - 'https://www.videolan.org/vlc/download-android.html'); + String? version = await getLatestVersion(standardUrl); + if (version == null) { + throw NoVersionError(); + } + String? targetUrl = '$dwUrlBase$version/'; + Response res = await sourceRequest(targetUrl); + List apkUrls = []; if (res.statusCode == 200) { - var dwUrlBase = 'get.videolan.org/vlc-android'; - var dwLinks = parse(res.body) + apkUrls = parse(res.body) .querySelectorAll('a') - .where((element) => - element.attributes['href']?.contains(dwUrlBase) ?? false) + .map((e) => e.attributes['href']?.split('/').last) + .where((h) => + h != null && h.isNotEmpty && h.toLowerCase().endsWith('.apk')) + .map((e) => targetUrl + e!) .toList(); - String? version = dwLinks.isNotEmpty - ? dwLinks.first.attributes['href'] - ?.split('/') - .where((s) => s.isNotEmpty) - .last - : null; - if (version == null) { - throw NoVersionError(); - } - String? targetUrl = 'https://$dwUrlBase/$version/'; - Response res2 = await sourceRequest(targetUrl); - List apkUrls = []; - if (res2.statusCode == 200) { - apkUrls = parse(res2.body) - .querySelectorAll('a') - .map((e) => e.attributes['href']?.split('/').last) - .where((h) => - h != null && h.isNotEmpty && h.toLowerCase().endsWith('.apk')) - .map((e) => targetUrl + e!) - .toList(); - } else { - throw getObtainiumHttpError(res2); - } - - return APKDetails( - version, getApkUrlsFromUrls(apkUrls), AppNames('VideoLAN', 'VLC')); } else { throw getObtainiumHttpError(res); } + + return APKDetails( + version, getApkUrlsFromUrls(apkUrls), AppNames('VideoLAN', 'VLC')); } @override