From a5494115891e0e99ee5086ed373377b80d5010c8 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Sat, 5 Aug 2023 13:55:25 -0400 Subject: [PATCH] Add dynamic mirror picking to VLC (#715) --- lib/app_sources/vlc.dart | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/app_sources/vlc.dart b/lib/app_sources/vlc.dart index c531f26..bbdec76 100644 --- a/lib/app_sources/vlc.dart +++ b/lib/app_sources/vlc.dart @@ -38,16 +38,14 @@ class VLC extends AppSource { } String? targetUrl = 'https://$dwUrlBase/$version/'; Response res2 = await sourceRequest(targetUrl); - String mirrorDwBase = - 'https://plug-mirror.rcac.purdue.edu/vlc/vlc-android/$version/'; List apkUrls = []; if (res2.statusCode == 200) { apkUrls = parse(res2.body) .querySelectorAll('a') - .map((e) => e.attributes['href']) + .map((e) => e.attributes['href']?.split('/').last) .where((h) => h != null && h.isNotEmpty && h.toLowerCase().endsWith('.apk')) - .map((e) => mirrorDwBase + e!) + .map((e) => targetUrl + e!) .toList(); } else { throw getObtainiumHttpError(res2); @@ -59,4 +57,20 @@ class VLC extends AppSource { throw getObtainiumHttpError(res); } } + + @override + Future apkUrlPrefetchModifier( + String apkUrl, String standardUrl) async { + Response res = await sourceRequest(apkUrl); + if (res.statusCode == 200) { + String? apkUrl = + parse(res.body).querySelector('#alt_link')?.attributes['href']; + if (apkUrl == null) { + throw NoAPKError(); + } + return apkUrl; + } else { + throw getObtainiumHttpError(res); + } + } }