From 5b147b82e0b0d39e342977f50835f3f45b57fd0e Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Sat, 30 Aug 2025 23:59:21 -0400 Subject: [PATCH] Added LiteAPKs as a source (#1799) --- lib/app_sources/liteapks.dart | 87 ++++++++++++++++++++++++++++++ lib/providers/source_provider.dart | 2 + 2 files changed, 89 insertions(+) create mode 100644 lib/app_sources/liteapks.dart diff --git a/lib/app_sources/liteapks.dart b/lib/app_sources/liteapks.dart new file mode 100644 index 0000000..ff07fbb --- /dev/null +++ b/lib/app_sources/liteapks.dart @@ -0,0 +1,87 @@ +import 'dart:convert'; + +import 'package:http/http.dart'; +import 'package:obtainium/custom_errors.dart'; +import 'package:obtainium/providers/source_provider.dart'; + +class LiteAPKs extends AppSource { + LiteAPKs() { + hosts = ['liteapks.com']; + name = 'LiteAPKs'; + } + + @override + String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) { + RegExp standardUrlRegEx = RegExp( + '^https?://(www\\.)?${getSourceRegex(hosts)}/+[^/]+', + caseSensitive: false, + ); + RegExpMatch? match = standardUrlRegEx.firstMatch(url); + if (match == null) { + throw InvalidURLError(name); + } + return match.group(0)!; + } + + @override + Future getLatestAPKDetails( + String standardUrl, + Map additionalSettings, + ) async { + var standardUri = Uri.parse(standardUrl); + var slug = standardUri.path + .split('.') + .reversed + .toList() + .sublist(1) + .reversed + .join('.'); + Response res1 = await sourceRequest( + '${standardUri.origin}/wp-json/wp/v2/posts?slug=$slug', + additionalSettings, + ); + if (res1.statusCode != 200) { + throw getObtainiumHttpError(res1); + } + + var liteAppId = jsonDecode(res1.body)[0]['id']; + if (liteAppId == null) { + throw NoReleasesError(); + } + + Response res2 = await sourceRequest( + '${standardUri.origin}/wp-json/v2/posts/$liteAppId', + additionalSettings, + ); + if (res2.statusCode != 200) { + throw getObtainiumHttpError(res2); + } + var json = jsonDecode(res2.body); + + var appName = json['data']?['title'] as String?; + var author = json['data']?['publisher'] as String?; + var version = json['data']?['versions']?[0]?['version'] as String?; + if (version == null) { + throw NoVersionError(); + } + var apkUrls = + ((json['data']?['versions']?[0]?['version_downloads'] as List?) + ?.map((l) => l['version_download_link']) ?? + []) + .map( + (l) => MapEntry( + Uri.decodeComponent(Uri.parse(l).pathSegments.last), + l, + ), + ) + .toList(); + return APKDetails( + version, + apkUrls, + AppNames( + author ?? Uri.parse(standardUrl).host, + appName ?? standardUrl.split('/').last, + ), + ); + } +} diff --git a/lib/providers/source_provider.dart b/lib/providers/source_provider.dart index 54dcab9..aa338f3 100644 --- a/lib/providers/source_provider.dart +++ b/lib/providers/source_provider.dart @@ -25,6 +25,7 @@ import 'package:obtainium/app_sources/huaweiappgallery.dart'; import 'package:obtainium/app_sources/izzyondroid.dart'; import 'package:obtainium/app_sources/html.dart'; import 'package:obtainium/app_sources/jenkins.dart'; +import 'package:obtainium/app_sources/liteapks.dart'; import 'package:obtainium/app_sources/neutroncode.dart'; import 'package:obtainium/app_sources/rustore.dart'; import 'package:obtainium/app_sources/sourceforge.dart'; @@ -1076,6 +1077,7 @@ class SourceProvider { HuaweiAppGallery(), Tencent(), CoolApk(), + LiteAPKs(), VivoAppStore(), Jenkins(), APKMirror(),