mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-01 21:30:16 +02:00
Merge duplicate version extraction code into one function
This commit is contained in:
@@ -252,26 +252,12 @@ class HTML extends AppSource {
|
|||||||
if (additionalSettings['supportFixedAPKURL'] != true) {
|
if (additionalSettings['supportFixedAPKURL'] != true) {
|
||||||
version = rel.hashCode.toString();
|
version = rel.hashCode.toString();
|
||||||
}
|
}
|
||||||
var versionExtractionRegEx =
|
version = extractVersion(
|
||||||
additionalSettings['versionExtractionRegEx'] as String?;
|
additionalSettings['versionExtractionRegEx'] as String?,
|
||||||
if (versionExtractionRegEx?.isNotEmpty == true) {
|
additionalSettings['matchGroupToUse'] as String?,
|
||||||
var match = RegExp(versionExtractionRegEx!).allMatches(
|
additionalSettings['versionExtractWholePage'] == true
|
||||||
additionalSettings['versionExtractWholePage'] == true
|
? res.body.split('\r\n').join('\n').split('\n').join('\\n')
|
||||||
? res.body.split('\r\n').join('\n').split('\n').join('\\n')
|
: rel);
|
||||||
: rel);
|
|
||||||
if (match.isEmpty) {
|
|
||||||
throw NoVersionError();
|
|
||||||
}
|
|
||||||
String matchGroupString =
|
|
||||||
(additionalSettings['matchGroupToUse'] as String).trim();
|
|
||||||
if (matchGroupString.isEmpty) {
|
|
||||||
matchGroupString = "0";
|
|
||||||
}
|
|
||||||
version = match.last.group(int.parse(matchGroupString));
|
|
||||||
if (version?.isNotEmpty != true) {
|
|
||||||
throw NoVersionError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rel = ensureAbsoluteUrl(rel, uri);
|
rel = ensureAbsoluteUrl(rel, uri);
|
||||||
version ??= (await checkDownloadHash(rel)).toString();
|
version ??= (await checkDownloadHash(rel)).toString();
|
||||||
return APKDetails(version, [rel].map((e) => MapEntry(e, e)).toList(),
|
return APKDetails(version, [rel].map((e) => MapEntry(e, e)).toList(),
|
||||||
|
@@ -603,6 +603,28 @@ bool isTempId(App app) {
|
|||||||
return RegExp('^[0-9]+\$').hasMatch(app.id);
|
return RegExp('^[0-9]+\$').hasMatch(app.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String? extractVersion(String? versionExtractionRegEx, String? matchGroupString,
|
||||||
|
String stringToCheck) {
|
||||||
|
if (versionExtractionRegEx?.isNotEmpty == true) {
|
||||||
|
String? version = stringToCheck;
|
||||||
|
var match = RegExp(versionExtractionRegEx!).allMatches(version);
|
||||||
|
if (match.isEmpty) {
|
||||||
|
throw NoVersionError();
|
||||||
|
}
|
||||||
|
matchGroupString = matchGroupString?.trim() ?? '';
|
||||||
|
if (matchGroupString.isEmpty) {
|
||||||
|
matchGroupString = "0";
|
||||||
|
}
|
||||||
|
version = match.last.group(int.parse(matchGroupString));
|
||||||
|
if (version?.isNotEmpty != true) {
|
||||||
|
throw NoVersionError();
|
||||||
|
}
|
||||||
|
return version!;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SourceProvider {
|
class SourceProvider {
|
||||||
// Add more source classes here so they are available via the service
|
// Add more source classes here so they are available via the service
|
||||||
List<AppSource> get sources => [
|
List<AppSource> get sources => [
|
||||||
@@ -705,24 +727,12 @@ class SourceProvider {
|
|||||||
|
|
||||||
if (source.runtimeType != HTML().runtimeType) {
|
if (source.runtimeType != HTML().runtimeType) {
|
||||||
// HTML does it separately
|
// HTML does it separately
|
||||||
var versionExtractionRegEx =
|
String? extractedVersion = extractVersion(
|
||||||
additionalSettings['versionExtractionRegEx'] as String?;
|
additionalSettings['versionExtractionRegEx'] as String?,
|
||||||
if (versionExtractionRegEx?.isNotEmpty == true) {
|
additionalSettings['matchGroupToUse'] as String?,
|
||||||
String? version = apk.version;
|
apk.version);
|
||||||
var match = RegExp(versionExtractionRegEx!).allMatches(apk.version);
|
if (extractedVersion != null) {
|
||||||
if (match.isEmpty) {
|
apk.version = extractedVersion;
|
||||||
throw NoVersionError();
|
|
||||||
}
|
|
||||||
String matchGroupString =
|
|
||||||
(additionalSettings['matchGroupToUse'] as String).trim();
|
|
||||||
if (matchGroupString.isEmpty) {
|
|
||||||
matchGroupString = "0";
|
|
||||||
}
|
|
||||||
version = match.last.group(int.parse(matchGroupString));
|
|
||||||
if (version?.isNotEmpty != true) {
|
|
||||||
throw NoVersionError();
|
|
||||||
}
|
|
||||||
apk.version = version!;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user