feat: initialize new Flutter project with core feature structure and cross-platform configuration
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
|
||||
abstract class ILinkExtractionService {
|
||||
Future<String?> extractVideoUrl(String pageUrl);
|
||||
}
|
||||
|
||||
class LinkExtractionService implements ILinkExtractionService {
|
||||
HeadlessInAppWebView? _headlessWebView;
|
||||
|
||||
@override
|
||||
Future<String?> extractVideoUrl(String pageUrl) async {
|
||||
// 1. Check if it's already a video link
|
||||
if (_isVideoUrl(pageUrl)) return pageUrl;
|
||||
|
||||
// 2. Use Headless WebView to find the video
|
||||
String? foundUrl;
|
||||
|
||||
_headlessWebView = HeadlessInAppWebView(
|
||||
initialUrlRequest: URLRequest(url: WebUri(pageUrl)),
|
||||
onLoadResource: (controller, resource) {
|
||||
final url = resource.url.toString();
|
||||
if (_isVideoUrl(url)) {
|
||||
foundUrl = url;
|
||||
_headlessWebView?.dispose();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
await _headlessWebView?.run();
|
||||
|
||||
// Wait for some time to catch resources
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
|
||||
return foundUrl;
|
||||
}
|
||||
|
||||
bool _isVideoUrl(String url) {
|
||||
final lower = url.toLowerCase();
|
||||
return lower.contains('.m3u8') ||
|
||||
lower.contains('.mp4') ||
|
||||
lower.contains('.mkv');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user