Auto-select direct APK source for URLs ending in '.apk' (#1820)

This commit is contained in:
Imran Remtulla
2024-09-08 02:51:11 -04:00
parent e019c8027b
commit 0e46a83843
24 changed files with 39 additions and 25 deletions

View File

@ -10,7 +10,7 @@ class APKCombo extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegEx = RegExp(
'^https?://(www\\.)?${getSourceRegex(hosts)}/+[^/]+/+[^/]+',
caseSensitive: false);

View File

@ -32,7 +32,7 @@ class APKMirror extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegEx = RegExp(
'^https?://(www\\.)?${getSourceRegex(hosts)}/apk/[^/]+/[^/]+',
caseSensitive: false);

View File

@ -29,7 +29,7 @@ class APKPure extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegExB = RegExp(
'^https?://m.${getSourceRegex(hosts)}(/+[^/]{2})?/+[^/]+/+[^/]+',
caseSensitive: false);

View File

@ -14,7 +14,7 @@ class Aptoide extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegEx = RegExp(
'^https?://([^\\.]+\\.){2,}${getSourceRegex(hosts)}',
caseSensitive: false);

View File

@ -16,7 +16,7 @@ class Codeberg extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegEx = RegExp(
'^https?://(www\\.)?${getSourceRegex(hosts)}/[^/]+/[^/]+',
caseSensitive: false);

View File

@ -1,12 +1,12 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:obtainium/app_sources/html.dart';
import 'package:obtainium/custom_errors.dart';
import 'package:obtainium/providers/source_provider.dart';
class DirectAPKLink extends AppSource {
HTML html = HTML();
DirectAPKLink() {
neverAutoSelect = true;
name = tr('directAPKLink');
additionalSourceAppSpecificSettingFormItems = html
.additionalSourceAppSpecificSettingFormItems
@ -24,6 +24,20 @@ class DirectAPKLink extends AppSource {
];
}
@override
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
print('AAA');
if (!forSelection) {
return url;
}
RegExp standardUrlRegExA = RegExp('.+\\.apk\$', caseSensitive: false);
var match = standardUrlRegExA.firstMatch(url);
if (match == null) {
throw InvalidURLError(name);
}
return match.group(0)!;
}
@override
Future<Map<String, String>?> getRequestHeaders(
Map<String, dynamic> additionalSettings,

View File

@ -38,7 +38,7 @@ class FDroid extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegExB = RegExp(
'^https?://(www\\.)?${getSourceRegex(hosts)}/+[^/]+/+packages/+[^/]+',
caseSensitive: false);

View File

@ -43,7 +43,7 @@ class FDroidRepo extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
var standardUri = Uri.parse(url);
var pathSegments = standardUri.pathSegments;
if (pathSegments.isNotEmpty && pathSegments.last == 'index.xml') {

View File

@ -154,7 +154,7 @@ class GitHub extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegEx = RegExp(
'^https?://(www\\.)?${getSourceRegex(hosts)}/[^/]+/[^/]+',
caseSensitive: false);

View File

@ -52,7 +52,7 @@ class GitLab extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegEx = RegExp(
'^https?://(www\\.)?${getSourceRegex(hosts)}/[^/]+/[^/]+',
caseSensitive: false);

View File

@ -288,7 +288,7 @@ class HTML extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
return url;
}

View File

@ -12,7 +12,7 @@ class HuaweiAppGallery extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegEx = RegExp(
'^https?://(www\\.)?${getSourceRegex(hosts)}(/#)?/(app|appdl)/[^/]+',
caseSensitive: false);

View File

@ -14,7 +14,7 @@ class IzzyOnDroid extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegExA = RegExp(
'^https?://android.${getSourceRegex(hosts)}/repo/apk/[^/]+',
caseSensitive: false);

View File

@ -10,7 +10,7 @@ class Mullvad extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegEx = RegExp(
'^https?://(www\\.)?${getSourceRegex(hosts)}',
caseSensitive: false);

View File

@ -10,7 +10,7 @@ class NeutronCode extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegEx = RegExp(
'^https?://(www\\.)?${getSourceRegex(hosts)}/downloads/file/[^/]+',
caseSensitive: false);

View File

@ -9,7 +9,7 @@ class Signal extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
return 'https://${hosts[0]}';
}

View File

@ -9,7 +9,7 @@ class SourceForge extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
var sourceRegex = getSourceRegex(hosts);
RegExp standardUrlRegExC =
RegExp('^https?://(www\\.)?$sourceRegex/p/.+', caseSensitive: false);

View File

@ -20,7 +20,7 @@ class SourceHut extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegEx = RegExp(
'^https?://(www\\.)?${getSourceRegex(hosts)}/[^/]+/[^/]+',
caseSensitive: false);

View File

@ -20,7 +20,7 @@ class SteamMobile extends AppSource {
final apks = {'steam': tr('steamMobile'), 'steam-chat-app': tr('steamChat')};
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
return 'https://${hosts[0]}';
}

View File

@ -11,7 +11,7 @@ class TelegramApp extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
return 'https://${hosts[0]}';
}

View File

@ -14,7 +14,7 @@ class Uptodown extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegEx = RegExp(
'^https?://([^\\.]+\\.){2,}${getSourceRegex(hosts)}',
caseSensitive: false);

View File

@ -21,7 +21,7 @@ class VLC extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
return 'https://${hosts[0]}';
}

View File

@ -10,7 +10,7 @@ class WhatsApp extends AppSource {
}
@override
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
return 'https://${hosts[0]}';
}

View File

@ -472,7 +472,7 @@ abstract class AppSource {
//
}
String sourceSpecificStandardizeURL(String url) {
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
throw NotImplementedError();
}
@ -809,7 +809,7 @@ class SourceProvider {
for (var s in sources.where(
(element) => element.hosts.isEmpty && !element.neverAutoSelect)) {
try {
s.sourceSpecificStandardizeURL(url);
s.sourceSpecificStandardizeURL(url, forSelection: true);
source = s;
break;
} catch (e) {