mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-31 13:33:28 +01:00 
			
		
		
		
	Auto-select direct APK source for URLs ending in '.apk' (#1820)
This commit is contained in:
		| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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') { | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -288,7 +288,7 @@ class HTML extends AppSource { | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   String sourceSpecificStandardizeURL(String url) { | ||||
|   String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) { | ||||
|     return url; | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -9,7 +9,7 @@ class Signal extends AppSource { | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   String sourceSpecificStandardizeURL(String url) { | ||||
|   String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) { | ||||
|     return 'https://${hosts[0]}'; | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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]}'; | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -11,7 +11,7 @@ class TelegramApp extends AppSource { | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   String sourceSpecificStandardizeURL(String url) { | ||||
|   String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) { | ||||
|     return 'https://${hosts[0]}'; | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -21,7 +21,7 @@ class VLC extends AppSource { | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   String sourceSpecificStandardizeURL(String url) { | ||||
|   String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) { | ||||
|     return 'https://${hosts[0]}'; | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -10,7 +10,7 @@ class WhatsApp extends AppSource { | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   String sourceSpecificStandardizeURL(String url) { | ||||
|   String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) { | ||||
|     return 'https://${hosts[0]}'; | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -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) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user