From dcb8807fa741dc57488f8a53d7867ee469f018aa Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Mon, 28 Aug 2023 19:11:22 -0400 Subject: [PATCH] Add "Intermediate Link" option to HTML Source (#820) --- assets/translations/bs.json | 2 +- assets/translations/en.json | 4 +++- assets/translations/es.json | 2 +- assets/translations/fr.json | 2 +- assets/translations/hu.json | 2 +- assets/translations/it.json | 2 +- assets/translations/ru.json | 2 +- lib/app_sources/html.dart | 24 ++++++++++++++++++++++++ lib/app_sources/huaweiappgallery.dart | 3 ++- lib/app_sources/jenkins.dart | 3 ++- lib/providers/source_provider.dart | 11 +++++++++-- 11 files changed, 46 insertions(+), 11 deletions(-) diff --git a/assets/translations/bs.json b/assets/translations/bs.json index 830a3ac..9590708 100644 --- a/assets/translations/bs.json +++ b/assets/translations/bs.json @@ -240,7 +240,7 @@ "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", "sortByFileNamesNotLinks": "Sort by file names instead of full links", "filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression", - "customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')", + "customLinkFilterRegex": "Custom APK Link Filter by Regular Expression (Default '.apk$')", "appsPossiblyUpdated": "App Updates Attempted", "appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background", "xWasPossiblyUpdatedToY": "{} may have been updated to {}.", diff --git a/assets/translations/en.json b/assets/translations/en.json index e3a7684..d86d9a1 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -240,7 +240,7 @@ "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", "sortByFileNamesNotLinks": "Sort by file names instead of full links", "filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression", - "customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')", + "customLinkFilterRegex": "Custom APK Link Filter by Regular Expression (Default '.apk$')", "appsPossiblyUpdated": "App Updates Attempted", "appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background", "xWasPossiblyUpdatedToY": "{} may have been updated to {}.", @@ -248,6 +248,8 @@ "backgroundUpdateReqsExplanation": "Background updates may not be possible for all apps.", "backgroundUpdateLimitsExplanation": "The success of a background install can only be determined when Obtainium is opened.", "verifyLatestTag": "Verify the 'latest' tag", + "intermediateLinkRegex": "Filter for an 'Intermediate' Link to Visit First", + "intermediateLinkNotFound": "Intermediate link not found", "removeAppQuestion": { "one": "Remove App?", "other": "Remove Apps?" diff --git a/assets/translations/es.json b/assets/translations/es.json index afe6e5e..a7968a7 100644 --- a/assets/translations/es.json +++ b/assets/translations/es.json @@ -240,7 +240,7 @@ "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", "sortByFileNamesNotLinks": "Sort by file names instead of full links", "filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression", - "customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')", + "customLinkFilterRegex": "Custom APK Link Filter by Regular Expression (Default '.apk$')", "appsPossiblyUpdated": "App Updates Attempted", "appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background", "xWasPossiblyUpdatedToY": "{} may have been updated to {}.", diff --git a/assets/translations/fr.json b/assets/translations/fr.json index 2ab4bb8..4f7e585 100644 --- a/assets/translations/fr.json +++ b/assets/translations/fr.json @@ -240,7 +240,7 @@ "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", "sortByFileNamesNotLinks": "Sort by file names instead of full links", "filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression", - "customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')", + "customLinkFilterRegex": "Custom APK Link Filter by Regular Expression (Default '.apk$')", "appsPossiblyUpdated": "App Updates Attempted", "appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background", "xWasPossiblyUpdatedToY": "{} may have been updated to {}.", diff --git a/assets/translations/hu.json b/assets/translations/hu.json index d30c802..8c3a71e 100644 --- a/assets/translations/hu.json +++ b/assets/translations/hu.json @@ -239,7 +239,7 @@ "gitlabSourceNote": "Előfordulhat, hogy a GitLab APK kibontása nem működik API-kulcs nélkül.", "sortByFileNamesNotLinks": "Fájlnevek szerinti elrendezés teljes linkek helyett", "filterReleaseNotesByRegEx": "Kiadási megjegyzések szűrése reguláris kifejezéssel", - "customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')", + "customLinkFilterRegex": "Custom APK Link Filter by Regular Expression (Default '.apk$')", "appsPossiblyUpdated": "App Updates Attempted", "appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background", "xWasPossiblyUpdatedToY": "{} may have been updated to {}.", diff --git a/assets/translations/it.json b/assets/translations/it.json index b4d0359..75d5778 100644 --- a/assets/translations/it.json +++ b/assets/translations/it.json @@ -240,7 +240,7 @@ "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", "sortByFileNamesNotLinks": "Sort by file names instead of full links", "filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression", - "customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')", + "customLinkFilterRegex": "Custom APK Link Filter by Regular Expression (Default '.apk$')", "appsPossiblyUpdated": "App Updates Attempted", "appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background", "xWasPossiblyUpdatedToY": "{} may have been updated to {}.", diff --git a/assets/translations/ru.json b/assets/translations/ru.json index 703f057..6c91980 100644 --- a/assets/translations/ru.json +++ b/assets/translations/ru.json @@ -240,7 +240,7 @@ "gitlabSourceNote": "Извлечение APK из GitLab может не работать без ключа API.", "sortByFileNamesNotLinks": "Sort by file names instead of full links", "filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression", - "customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')", + "customLinkFilterRegex": "Custom APK Link Filter by Regular Expression (Default '.apk$')", "appsPossiblyUpdated": "App Updates Attempted", "appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background", "xWasPossiblyUpdatedToY": "{} may have been updated to {}.", diff --git a/lib/app_sources/html.dart b/lib/app_sources/html.dart index 8df2add..753e3f1 100644 --- a/lib/app_sources/html.dart +++ b/lib/app_sources/html.dart @@ -103,7 +103,16 @@ class HTML extends AppSource { } ]) ], + [ + GeneratedFormTextField('intermediateLinkRegex', + label: tr('intermediateLinkRegex'), + hint: '([0-9]+\.)*[0-9]+/\$', + required: false, + additionalValidators: [(value) => regExValidator(value)]) + ] ]; + overrideVersionDetectionFormDefault('noVersionDetection', + disableStandard: true, disableRelDate: true); } @override @@ -132,6 +141,21 @@ class HTML extends AppSource { .map((element) => element.attributes['href'] ?? '') .toList(); List links = []; + if ((additionalSettings['intermediateLinkRegex'] as String?) + ?.isNotEmpty == + true) { + var reg = RegExp(additionalSettings['intermediateLinkRegex']); + links = allLinks.where((element) => reg.hasMatch(element)).toList(); + links.sort((a, b) => compareAlphaNumeric(a, b)); + if (links.isEmpty) { + throw ObtainiumError(tr('intermediateLinkNotFound')); + } + Map additionalSettingsTemp = + Map.from(additionalSettings); + additionalSettingsTemp['intermediateLinkRegex'] = null; + return getLatestAPKDetails( + ensureAbsoluteUrl(links.last, uri), additionalSettingsTemp); + } if ((additionalSettings['customLinkFilterRegex'] as String?) ?.isNotEmpty == true) { diff --git a/lib/app_sources/huaweiappgallery.dart b/lib/app_sources/huaweiappgallery.dart index 1a97774..76388e9 100644 --- a/lib/app_sources/huaweiappgallery.dart +++ b/lib/app_sources/huaweiappgallery.dart @@ -7,7 +7,8 @@ class HuaweiAppGallery extends AppSource { HuaweiAppGallery() { name = 'Huawei AppGallery'; host = 'appgallery.huawei.com'; - overrideVersionDetectionFormDefault('releaseDateAsVersion', true); + overrideVersionDetectionFormDefault('releaseDateAsVersion', + disableStandard: true); } @override diff --git a/lib/app_sources/jenkins.dart b/lib/app_sources/jenkins.dart index 2aa8853..9e5af8d 100644 --- a/lib/app_sources/jenkins.dart +++ b/lib/app_sources/jenkins.dart @@ -6,7 +6,8 @@ import 'package:obtainium/providers/source_provider.dart'; class Jenkins extends AppSource { Jenkins() { - overrideVersionDetectionFormDefault('releaseDateAsVersion', true); + overrideVersionDetectionFormDefault('releaseDateAsVersion', + disableStandard: true); } String trimJobUrl(String url) { diff --git a/lib/providers/source_provider.dart b/lib/providers/source_provider.dart index 3371ee4..3611566 100644 --- a/lib/providers/source_provider.dart +++ b/lib/providers/source_provider.dart @@ -329,16 +329,23 @@ abstract class AppSource { name = runtimeType.toString(); } - overrideVersionDetectionFormDefault(String vd, bool disableStandard) { + overrideVersionDetectionFormDefault(String vd, + {bool disableStandard = false, bool disableRelDate = false}) { additionalAppSpecificSourceAgnosticSettingFormItems = additionalAppSpecificSourceAgnosticSettingFormItems.map((e) { return e.map((e2) { if (e2.key == 'versionDetection') { var item = e2 as GeneratedFormDropdown; item.defaultValue = vd; + item.disabledOptKeys = []; if (disableStandard) { - item.disabledOptKeys = ['standardVersionDetection']; + item.disabledOptKeys?.add('standardVersionDetection'); } + if (disableRelDate) { + item.disabledOptKeys?.add('releaseDateAsVersion'); + } + item.disabledOptKeys = + item.disabledOptKeys?.where((element) => element != vd).toList(); } return e2; }).toList();