mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-23 14:39:30 +02:00
Re-add VLC with better error messaging when no mirror available (#821)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:html/parser.dart';
|
import 'package:html/parser.dart';
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
import 'package:obtainium/app_sources/html.dart';
|
import 'package:obtainium/app_sources/html.dart';
|
||||||
@@ -41,27 +42,59 @@ class VLC extends AppSource {
|
|||||||
String standardUrl,
|
String standardUrl,
|
||||||
Map<String, dynamic> additionalSettings,
|
Map<String, dynamic> additionalSettings,
|
||||||
) async {
|
) async {
|
||||||
String? version = await getLatestVersion(standardUrl);
|
Response res = await get(
|
||||||
if (version == null) {
|
Uri.parse('https://www.videolan.org/vlc/download-android.html'));
|
||||||
throw NoVersionError();
|
|
||||||
}
|
|
||||||
String? targetUrl = '$dwUrlBase$version/';
|
|
||||||
Response res = await sourceRequest(targetUrl);
|
|
||||||
List<String> apkUrls = [];
|
|
||||||
if (res.statusCode == 200) {
|
if (res.statusCode == 200) {
|
||||||
apkUrls = parse(res.body)
|
var dwUrlBase = 'get.videolan.org/vlc-android';
|
||||||
|
var dwLinks = parse(res.body)
|
||||||
.querySelectorAll('a')
|
.querySelectorAll('a')
|
||||||
.map((e) => e.attributes['href']?.split('/').last)
|
.where((element) =>
|
||||||
.where((h) =>
|
element.attributes['href']?.contains(dwUrlBase) ?? false)
|
||||||
h != null && h.isNotEmpty && h.toLowerCase().endsWith('.apk'))
|
|
||||||
.map((e) => targetUrl + e!)
|
|
||||||
.toList();
|
.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<String> 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 {
|
} else {
|
||||||
throw getObtainiumHttpError(res);
|
throw getObtainiumHttpError(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return APKDetails(
|
|
||||||
version, getApkUrlsFromUrls(apkUrls), AppNames('VideoLAN', 'VLC'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@@ -25,6 +25,7 @@ import 'package:obtainium/app_sources/sourceforge.dart';
|
|||||||
import 'package:obtainium/app_sources/sourcehut.dart';
|
import 'package:obtainium/app_sources/sourcehut.dart';
|
||||||
import 'package:obtainium/app_sources/steammobile.dart';
|
import 'package:obtainium/app_sources/steammobile.dart';
|
||||||
import 'package:obtainium/app_sources/telegramapp.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/components/generated_form.dart';
|
||||||
import 'package:obtainium/custom_errors.dart';
|
import 'package:obtainium/custom_errors.dart';
|
||||||
import 'package:obtainium/mass_app_sources/githubstars.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)
|
// APKCombo(), // Can't get past their scraping blocking yet (get 403 Forbidden)
|
||||||
Mullvad(),
|
Mullvad(),
|
||||||
Signal(),
|
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
|
// WhatsApp(), // As of 2023-03-20 this is unusable as the version on the webpage is months out of date
|
||||||
TelegramApp(),
|
TelegramApp(),
|
||||||
SteamMobile(),
|
SteamMobile(),
|
||||||
|
Reference in New Issue
Block a user