mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-11-03 06:43:29 +01:00 
			
		
		
		
	- All Sources now have a "Track-Only" option that will prevent Obtainium from looking for APKs (though the App must still have a release of some kind so that a version string can be grabbed).
    - These Apps cannot be installed through Obtainium, but update notifications will still be sent.
    - The user needs to manually mark them as updated when appropriate.
    - This addresses issue #119.
    - It also partially addresses #44 by allowing some sources to be configured as "Track-Only"-only. The first such source (APKMirror) will be added later.
- Includes various UI changes to accommodate the above change.
- Also makes App loading a bit more responsive (sending Obtainium to the background then returning will now cause App re-load to pick up changes in App versioning that may have been made in the meantime, for instance through update checking).
		
	
		
			
				
	
	
		
			64 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
import 'package:html/parser.dart';
 | 
						|
import 'package:http/http.dart';
 | 
						|
import 'package:obtainium/custom_errors.dart';
 | 
						|
import 'package:obtainium/providers/source_provider.dart';
 | 
						|
 | 
						|
class SourceForge extends AppSource {
 | 
						|
  SourceForge() {
 | 
						|
    host = 'sourceforge.net';
 | 
						|
  }
 | 
						|
 | 
						|
  @override
 | 
						|
  String standardizeURL(String url) {
 | 
						|
    RegExp standardUrlRegEx = RegExp('^https?://$host/projects/[^/]+');
 | 
						|
    RegExpMatch? match = standardUrlRegEx.firstMatch(url.toLowerCase());
 | 
						|
    if (match == null) {
 | 
						|
      throw InvalidURLError(runtimeType.toString());
 | 
						|
    }
 | 
						|
    return url.substring(0, match.end);
 | 
						|
  }
 | 
						|
 | 
						|
  @override
 | 
						|
  String? changeLogPageFromStandardUrl(String standardUrl) => null;
 | 
						|
 | 
						|
  @override
 | 
						|
  Future<APKDetails> getLatestAPKDetails(
 | 
						|
      String standardUrl, List<String> additionalData) async {
 | 
						|
    Response res = await get(Uri.parse('$standardUrl/rss?path=/'));
 | 
						|
    if (res.statusCode == 200) {
 | 
						|
      var parsedHtml = parse(res.body);
 | 
						|
      var allDownloadLinks =
 | 
						|
          parsedHtml.querySelectorAll('guid').map((e) => e.innerHtml).toList();
 | 
						|
      getVersion(String url) {
 | 
						|
        try {
 | 
						|
          var tokens = url.split('/');
 | 
						|
          return tokens[tokens.length - 3];
 | 
						|
        } catch (e) {
 | 
						|
          return null;
 | 
						|
        }
 | 
						|
      }
 | 
						|
 | 
						|
      String? version = getVersion(allDownloadLinks[0]);
 | 
						|
      if (version == null) {
 | 
						|
        throw NoVersionError();
 | 
						|
      }
 | 
						|
      var apkUrlListAllReleases = allDownloadLinks
 | 
						|
          .where((element) => element.toLowerCase().endsWith('.apk/download'))
 | 
						|
          .toList();
 | 
						|
      var apkUrlList =
 | 
						|
          apkUrlListAllReleases // This can be used skipped for fallback support later
 | 
						|
              .where((element) => getVersion(element) == version)
 | 
						|
              .toList();
 | 
						|
      return APKDetails(version, apkUrlList);
 | 
						|
    } else {
 | 
						|
      throw NoReleasesError();
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  @override
 | 
						|
  AppNames getAppNames(String standardUrl) {
 | 
						|
    return AppNames(runtimeType.toString(),
 | 
						|
        standardUrl.substring(standardUrl.lastIndexOf('/') + 1));
 | 
						|
  }
 | 
						|
}
 |