mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-16 11:48:09 +02:00
Add custom link filter for HTML
This commit is contained in:
@@ -246,6 +246,7 @@
|
|||||||
"gitlabSourceNote": "GitLab APK extraction may not work without an API key.",
|
"gitlabSourceNote": "GitLab APK extraction may not work without an API key.",
|
||||||
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
||||||
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
||||||
|
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "Želite li ukloniti aplikaciju?",
|
"one": "Želite li ukloniti aplikaciju?",
|
||||||
"other": "Želite li ukloniti aplikacije?"
|
"other": "Želite li ukloniti aplikacije?"
|
||||||
|
@@ -246,6 +246,7 @@
|
|||||||
"gitlabSourceNote": "GitLab APK-Extraktion funktioniert möglicherweise nicht ohne API-Schlüssel",
|
"gitlabSourceNote": "GitLab APK-Extraktion funktioniert möglicherweise nicht ohne API-Schlüssel",
|
||||||
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
||||||
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
||||||
|
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "App entfernen?",
|
"one": "App entfernen?",
|
||||||
"other": "Apps entfernen?"
|
"other": "Apps entfernen?"
|
||||||
|
@@ -246,6 +246,7 @@
|
|||||||
"gitlabSourceNote": "GitLab APK extraction may not work without an API key.",
|
"gitlabSourceNote": "GitLab APK extraction may not work without an API key.",
|
||||||
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
||||||
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
||||||
|
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "Remove App?",
|
"one": "Remove App?",
|
||||||
"other": "Remove Apps?"
|
"other": "Remove Apps?"
|
||||||
|
@@ -246,6 +246,7 @@
|
|||||||
"gitlabSourceNote": "GitLab APK extraction may not work without an API key.",
|
"gitlabSourceNote": "GitLab APK extraction may not work without an API key.",
|
||||||
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
||||||
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
||||||
|
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "¿Eliminar Aplicación?",
|
"one": "¿Eliminar Aplicación?",
|
||||||
"other": "¿Eliminar Aplicaciones?"
|
"other": "¿Eliminar Aplicaciones?"
|
||||||
|
@@ -246,6 +246,7 @@
|
|||||||
"gitlabSourceNote": "GitLab APK extraction may not work without an API key.",
|
"gitlabSourceNote": "GitLab APK extraction may not work without an API key.",
|
||||||
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
||||||
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
||||||
|
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "برنامه حذف شود؟",
|
"one": "برنامه حذف شود؟",
|
||||||
"other": "برنامه ها حذف شوند؟"
|
"other": "برنامه ها حذف شوند؟"
|
||||||
|
@@ -246,6 +246,7 @@
|
|||||||
"gitlabSourceNote": "GitLab APK extraction may not work without an API key.",
|
"gitlabSourceNote": "GitLab APK extraction may not work without an API key.",
|
||||||
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
||||||
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
||||||
|
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "Supprimer l'application ?",
|
"one": "Supprimer l'application ?",
|
||||||
"other": "Supprimer les applications ?"
|
"other": "Supprimer les applications ?"
|
||||||
|
@@ -245,6 +245,7 @@
|
|||||||
"gitlabSourceNote": "Előfordulhat, hogy a GitLab APK kibontása nem működik API-kulcs nélkül.",
|
"gitlabSourceNote": "Előfordulhat, hogy a GitLab APK kibontása nem működik API-kulcs nélkül.",
|
||||||
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
||||||
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
||||||
|
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "Eltávolítja az alkalmazást?",
|
"one": "Eltávolítja az alkalmazást?",
|
||||||
"other": "Eltávolítja az alkalmazást?"
|
"other": "Eltávolítja az alkalmazást?"
|
||||||
|
@@ -246,6 +246,7 @@
|
|||||||
"gitlabSourceNote": "GitLab APK extraction may not work without an API key.",
|
"gitlabSourceNote": "GitLab APK extraction may not work without an API key.",
|
||||||
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
||||||
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
||||||
|
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "Rimuovere l'app?",
|
"one": "Rimuovere l'app?",
|
||||||
"other": "Rimuovere le app?"
|
"other": "Rimuovere le app?"
|
||||||
|
@@ -246,6 +246,7 @@
|
|||||||
"gitlabSourceNote": "GitLabのAPK抽出はAPIキーがないと動作しない場合があります。",
|
"gitlabSourceNote": "GitLabのAPK抽出はAPIキーがないと動作しない場合があります。",
|
||||||
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
||||||
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
||||||
|
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "アプリを削除しますか?",
|
"one": "アプリを削除しますか?",
|
||||||
"other": "アプリを削除しますか?"
|
"other": "アプリを削除しますか?"
|
||||||
|
@@ -250,6 +250,7 @@
|
|||||||
"gitlabSourceNote": "Pozyskiwanie pliku APK z GitLab może nie działać bez klucza API.",
|
"gitlabSourceNote": "Pozyskiwanie pliku APK z GitLab może nie działać bez klucza API.",
|
||||||
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
||||||
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
||||||
|
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "Usunąć aplikację?",
|
"one": "Usunąć aplikację?",
|
||||||
"other": "Usunąć aplikacje?"
|
"other": "Usunąć aplikacje?"
|
||||||
|
@@ -246,6 +246,7 @@
|
|||||||
"gitlabSourceNote": "Извлечение APK из GitLab может не работать без ключа API.",
|
"gitlabSourceNote": "Извлечение APK из GitLab может не работать без ключа API.",
|
||||||
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
||||||
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
||||||
|
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "Удалить приложение?",
|
"one": "Удалить приложение?",
|
||||||
"other": "Удалить приложения?"
|
"other": "Удалить приложения?"
|
||||||
|
@@ -246,6 +246,7 @@
|
|||||||
"gitlabSourceNote": "未使用访问令牌时可能无法从 GitLab 获取 APK 文件。",
|
"gitlabSourceNote": "未使用访问令牌时可能无法从 GitLab 获取 APK 文件。",
|
||||||
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
"sortByFileNamesNotLinks": "Sort by file names instead of full links",
|
||||||
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
|
||||||
|
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "是否删除应用?",
|
"one": "是否删除应用?",
|
||||||
"other": "是否删除应用?"
|
"other": "是否删除应用?"
|
||||||
|
@@ -91,7 +91,18 @@ class HTML extends AppSource {
|
|||||||
[
|
[
|
||||||
GeneratedFormSwitch('sortByFileNamesNotLinks',
|
GeneratedFormSwitch('sortByFileNamesNotLinks',
|
||||||
label: tr('sortByFileNamesNotLinks'))
|
label: tr('sortByFileNamesNotLinks'))
|
||||||
]
|
],
|
||||||
|
[
|
||||||
|
GeneratedFormTextField('customLinkFilterRegex',
|
||||||
|
label: tr('customLinkFilterRegex'),
|
||||||
|
hint: 'download/(.*/)?(android|apk|mobile)',
|
||||||
|
required: false,
|
||||||
|
additionalValidators: [
|
||||||
|
(value) {
|
||||||
|
return regExValidator(value);
|
||||||
|
}
|
||||||
|
])
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,16 +126,29 @@ class HTML extends AppSource {
|
|||||||
var uri = Uri.parse(standardUrl);
|
var uri = Uri.parse(standardUrl);
|
||||||
Response res = await sourceRequest(standardUrl);
|
Response res = await sourceRequest(standardUrl);
|
||||||
if (res.statusCode == 200) {
|
if (res.statusCode == 200) {
|
||||||
List<String> links = parse(res.body)
|
var html = parse(res.body);
|
||||||
|
List<String> allLinks = html
|
||||||
.querySelectorAll('a')
|
.querySelectorAll('a')
|
||||||
.map((element) => element.attributes['href'] ?? '')
|
.map((element) => element.attributes['href'] ?? '')
|
||||||
|
.toList();
|
||||||
|
List<String> links = [];
|
||||||
|
if ((additionalSettings['customLinkFilterRegex'] as String?)
|
||||||
|
?.isNotEmpty ==
|
||||||
|
true) {
|
||||||
|
var reg = RegExp(additionalSettings['customLinkFilterRegex']);
|
||||||
|
links = allLinks.where((element) => reg.hasMatch(element)).toList();
|
||||||
|
} else {
|
||||||
|
links = allLinks
|
||||||
.where((element) =>
|
.where((element) =>
|
||||||
Uri.parse(element).path.toLowerCase().endsWith('.apk'))
|
Uri.parse(element).path.toLowerCase().endsWith('.apk'))
|
||||||
.toList();
|
.toList();
|
||||||
|
}
|
||||||
links.sort((a, b) => additionalSettings['sortByFileNamesNotLinks'] == true
|
links.sort((a, b) => additionalSettings['sortByFileNamesNotLinks'] == true
|
||||||
? compareAlphaNumeric(a.split('/').last, b.split('/').last)
|
? compareAlphaNumeric(a.split('/').where((e) => e.isNotEmpty).last,
|
||||||
|
b.split('/').where((e) => e.isNotEmpty).last)
|
||||||
: compareAlphaNumeric(a, b));
|
: compareAlphaNumeric(a, b));
|
||||||
if (additionalSettings['apkFilterRegEx'] != null) {
|
if ((additionalSettings['apkFilterRegEx'] as String?)?.isNotEmpty ==
|
||||||
|
true) {
|
||||||
var reg = RegExp(additionalSettings['apkFilterRegEx']);
|
var reg = RegExp(additionalSettings['apkFilterRegEx']);
|
||||||
links = links.where((element) => reg.hasMatch(element)).toList();
|
links = links.where((element) => reg.hasMatch(element)).toList();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user