From 075ecae540c1c78019dd7e2be00a75e46a9d6e07 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Mon, 28 Aug 2023 19:36:02 -0400 Subject: [PATCH] Re-add VLC with better error messaging when no mirror available (#821) --- lib/app_sources/vlc.dart | 63 +++++++++++++++++++++++------- lib/providers/source_provider.dart | 3 +- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/lib/app_sources/vlc.dart b/lib/app_sources/vlc.dart index 6787996..51adb7f 100644 --- a/lib/app_sources/vlc.dart +++ b/lib/app_sources/vlc.dart @@ -1,3 +1,4 @@ +import 'package:easy_localization/easy_localization.dart'; import 'package:html/parser.dart'; import 'package:http/http.dart'; import 'package:obtainium/app_sources/html.dart'; @@ -41,27 +42,59 @@ class VLC extends AppSource { String standardUrl, Map additionalSettings, ) async { - String? version = await getLatestVersion(standardUrl); - if (version == null) { - throw NoVersionError(); - } - String? targetUrl = '$dwUrlBase$version/'; - Response res = await sourceRequest(targetUrl); - List apkUrls = []; + Response res = await get( + Uri.parse('https://www.videolan.org/vlc/download-android.html')); if (res.statusCode == 200) { - apkUrls = parse(res.body) + var dwUrlBase = 'get.videolan.org/vlc-android'; + var dwLinks = parse(res.body) .querySelectorAll('a') - .map((e) => e.attributes['href']?.split('/').last) - .where((h) => - h != null && h.isNotEmpty && h.toLowerCase().endsWith('.apk')) - .map((e) => targetUrl + e!) + .where((element) => + element.attributes['href']?.contains(dwUrlBase) ?? false) .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 get(Uri.parse(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 if (res2.statusCode == 500 && + res2.body.toLowerCase().indexOf('mirror') > 0) { + var html = parse(res2.body); + var err = ''; + html.body?.nodes.forEach((element) { + if (element.text != null) { + err += '${element.text}\n'; + } + }); + err = err.trim(); + if (err.isEmpty) { + err = tr('err'); + } + throw ObtainiumError(err); + } 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 diff --git a/lib/providers/source_provider.dart b/lib/providers/source_provider.dart index 3611566..9eef449 100644 --- a/lib/providers/source_provider.dart +++ b/lib/providers/source_provider.dart @@ -25,6 +25,7 @@ import 'package:obtainium/app_sources/sourceforge.dart'; import 'package:obtainium/app_sources/sourcehut.dart'; import 'package:obtainium/app_sources/steammobile.dart'; import 'package:obtainium/app_sources/telegramapp.dart'; +import 'package:obtainium/app_sources/vlc.dart'; import 'package:obtainium/components/generated_form.dart'; import 'package:obtainium/custom_errors.dart'; import 'package:obtainium/mass_app_sources/githubstars.dart'; @@ -523,7 +524,7 @@ class SourceProvider { // APKCombo(), // Can't get past their scraping blocking yet (get 403 Forbidden) Mullvad(), Signal(), - // VLC(), // As of 2023-08-26 this site randomly messes up the 'latest' version (one minute it's 3.5.4, next minute back to 3.5.3) + VLC(), // As of 2023-08-26 this site randomly messes up the 'latest' version (one minute it's 3.5.4, next minute back to 3.5.3) // WhatsApp(), // As of 2023-03-20 this is unusable as the version on the webpage is months out of date TelegramApp(), SteamMobile(),