基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
chore: clean code
Prediditff5ccc53a412
diff --git a/lib/plugins/plugins.dart b/lib/plugins/plugins.dartindex 05ea5275..731869a5 100644--- a/lib/plugins/plugins.dart+++ b/lib/plugins/plugins.dart@@ -15,6 +15,7 @@ class Plugin {String version;bool muliSources;bool useWebview;+ /// Deprecated (always true)bool useNativePlayer;bool usePost;bool useLegacyParser;diff --git a/lib/webview/webview_controller.dart b/lib/webview/webview_controller.dartindex 3a95e60a..2d680c3d 100644--- a/lib/webview/webview_controller.dart+++ b/lib/webview/webview_controller.dart@@ -48,7 +48,7 @@ abstract class WebviewItemController<T> {Stream<(String, int)> get onVideoURLParser => videoParserEventController.stream;/// Webview load URL method- Future<void> loadUrl(String url, bool useNativePlayer, bool useLegacyParser,+ Future<void> loadUrl(String url, bool useLegacyParser,{int offset = 0});/// Webview unload page methoddiff --git a/lib/webview/webview_controller_impel/webview_android_controller_impel.dart b/lib/webview/webview_controller_impel/webview_android_controller_impel.dartindex 242a22f7..80225fb2 100644--- a/lib/webview/webview_controller_impel/webview_android_controller_impel.dart+++ b/lib/webview/webview_controller_impel/webview_android_controller_impel.dart@@ -14,7 +14,6 @@ class WebviewAndroidItemControllerImpelTimer? loadingMonitorTimer;bool hasInjectedScripts = false;bool shouldInjectIframeRedirect = false;- bool useNativePlayer = false;@overrideFuture<void> init() async {@@ -39,9 +38,6 @@ class WebviewAndroidItemControllerImpel},onLoadStart: (controller, url) async {logEventController.add('started loading: $url');- if (url.toString() != 'about:blank') {- await onLoadStart();- }},onLoadStop: (controller, url) {logEventController.add('loading completed: $url');@@ -52,12 +48,12 @@ class WebviewAndroidItemControllerImpel}@override- Future<void> loadUrl(String url, bool useNativePlayer, bool useLegacyParser,+ Future<void> loadUrl(String url, bool useLegacyParser,{int offset = 0}) async {await unloadPage();if (!hasInjectedScripts) {- addJavaScriptHandlers(useNativePlayer, useLegacyParser);- await addUserScripts(useNativePlayer, useLegacyParser);+ addJavaScriptHandlers(useLegacyParser);+ await addUserScripts(useLegacyParser);hasInjectedScripts = true;}count = 0;@@ -65,7 +61,6 @@ class WebviewAndroidItemControllerImpelisIframeLoaded = false;isVideoSourceLoaded = false;shouldInjectIframeRedirect = true;- this.useNativePlayer = useNativePlayer;videoLoadingEventController.add(true);await webviewController?.loadUrl(urlRequest: URLRequest(url: WebUri(url)));@@ -86,7 +81,7 @@ class WebviewAndroidItemControllerImpel});}- void addJavaScriptHandlers(bool useNativePlayer, bool useLegacyParser) {+ void addJavaScriptHandlers(bool useLegacyParser) {logEventController.add('Adding LogBridge handler');webviewController?.addJavaScriptHandler(handlerName: 'LogBridge',@@ -98,19 +93,7 @@ class WebviewAndroidItemControllerImpellogEventController.add(message);});- if (!useNativePlayer) {- logEventController.add('Adding IframeRedirectBridge handler');- webviewController?.addJavaScriptHandler(- handlerName: 'IframeRedirectBridge',- callback: (args) {- String message = args[0].toString();- logEventController.add('Redirect to: $message');- Future.delayed(const Duration(seconds: 2), () {- isIframeLoaded = true;- videoLoadingEventController.add(false);- });- });- } else if (useLegacyParser) {+ if (useLegacyParser) {logEventController.add('Adding JSBridgeDebug handler');webviewController?.addJavaScriptHandler(handlerName: 'JSBridgeDebug',@@ -158,11 +141,7 @@ class WebviewAndroidItemControllerImpel}}- Future<void> addUserScripts(- bool useNativePlayer, bool useLegacyParser) async {- if (!useNativePlayer) {- return;- }+ Future<void> addUserScripts(bool useLegacyParser) async {final List<UserScript> scripts = [];if (useLegacyParser) {@@ -310,64 +289,6 @@ class WebviewAndroidItemControllerImpel);}- Future<void> onLoadStart() async {- if (!useNativePlayer && shouldInjectIframeRedirect) {- logEventController.add('Adding IframeRedirectBridge UserScript');- shouldInjectIframeRedirect = false;- await webviewController?.evaluateJavascript(source: """- window.flutter_inappwebview.callHandler('LogBridge', 'IframeRedirectBridge script loaded: ' + window.location.href);- const _observer = new MutationObserver((mutations) => {- window.flutter_inappwebview.callHandler('LogBridge', 'Scanning for iframes...');- for (const mutation of mutations) {- if (mutation.type === "attributes" && mutation.target.nodeName === "IFRAME") {- if (processIframeElement(mutation.target)) return;- continue;- }- for (const node of mutation.addedNodes) {- if (node.nodeName === "IFRAME") {- if (processIframeElement(node)) return;- }- if (node.querySelectorAll) {- for (const iframe of node.querySelectorAll("iframe")) {- if (processIframeElement(iframe)) return;- }- }- }- }- });-- function processIframeElement(iframe) {- window.flutter_inappwebview.callHandler('LogBridge', 'Processing iframe element');- let src = iframe.getAttribute("src");- if (src && src.trim() !== '' && (src.startsWith('http') || src.startsWith('//')) && !src.includes('googleads') && !src.includes('adtrafficquality') && !src.includes('googlesyndication.com') && !src.includes('google.com') && !src.includes('prestrain.html') && !src.includes('prestrain%2Ehtml')) {- _observer.disconnect();- window.flutter_inappwebview.callHandler("IframeRedirectBridge", src);- window.location.href = src;- return true;- }- }-- function setupIframeProcessing() {- for (const iframe of document.querySelectorAll("iframe")) {- if (processIframeElement(iframe)) return;- }- _observer.observe(document.body, {- childList: true,- subtree: true,- attributes: true,- attributeFilter: ["src"],- });- }-- if (document.readyState === 'loading') {- document.addEventListener('DOMContentLoaded', setupIframeProcessing);- } else {- setupIframeProcessing();- }- """);- }- }-@overrideFuture<void> unloadPage() async {loadingMonitorTimer?.cancel();diff --git a/lib/webview/webview_controller_impel/webview_apple_controller_impel.dart b/lib/webview/webview_controller_impel/webview_apple_controller_impel.dartindex 918aa894..fe441e15 100644--- a/lib/webview/webview_controller_impel/webview_apple_controller_impel.dart+++ b/lib/webview/webview_controller_impel/webview_apple_controller_impel.dart@@ -123,12 +123,12 @@ class WebviewAppleItemControllerImpel}@override- Future<void> loadUrl(String url, bool useNativePlayer, bool useLegacyParser,+ Future<void> loadUrl(String url, bool useLegacyParser,{int offset = 0}) async {await unloadPage();if (!hasInjectedScripts) {- addJavaScriptHandlers(useNativePlayer, useLegacyParser);- await addUserScripts(useNativePlayer, useLegacyParser);+ addJavaScriptHandlers(useLegacyParser);+ await addUserScripts(useLegacyParser);hasInjectedScripts = true;}count = 0;@@ -156,7 +156,7 @@ class WebviewAppleItemControllerImpel});}- void addJavaScriptHandlers(bool useNativePlayer, bool useLegacyParser) {+ void addJavaScriptHandlers(bool useLegacyParser) {logEventController.add('Adding LogBridge handler');webviewController?.addJavaScriptHandler(handlerName: 'LogBridge',@@ -168,19 +168,7 @@ class WebviewAppleItemControllerImpellogEventController.add(message);});- if (!useNativePlayer) {- logEventController.add('Adding IframeRedirectBridge handler');- webviewController?.addJavaScriptHandler(- handlerName: 'IframeRedirectBridge',- callback: (args) {- String message = args[0].toString();- logEventController.add('Redirect to: $message');- Future.delayed(const Duration(seconds: 2), () {- isIframeLoaded = true;- videoLoadingEventController.add(false);- });- });- } else if (useLegacyParser) {+ if (useLegacyParser) {logEventController.add('Adding JSBridgeDebug handler');webviewController?.addJavaScriptHandler(handlerName: 'JSBridgeDebug',@@ -229,30 +217,10 @@ class WebviewAppleItemControllerImpel}Future<void> addUserScripts(- bool useNativePlayer, bool useLegacyParser) async {+ bool useLegacyParser) async {final List<UserScript> scripts = [];- if (!useNativePlayer) {- logEventController.add('Adding IframeRedirectBridge UserScript');- const String iframeRedirectScript = """- window.flutter_inappwebview.callHandler('LogBridge', 'IframeRedirectBridge script loaded: ' + window.location.href);- var iframes = document.getElementsByTagName('iframe');- for (var i = 0; i < iframes.length; i++) {- var iframe = iframes[i];- var src = iframe.getAttribute('src');- if (src && src.trim() !== '' && (src.startsWith('http') || src.startsWith('//')) && !src.includes('googleads') && !src.includes('adtrafficquality') && !src.includes('googlesyndication.com') && !src.includes('google.com') && !src.includes('prestrain.html') && !src.includes('prestrain%2Ehtml')) {- window.flutter_inappwebview.callHandler('IframeRedirectBridge', src);- window.location.href = src;- break;- }- }- """;- scripts.add(UserScript(- source: iframeRedirectScript,- injectionTime: UserScriptInjectionTime.AT_DOCUMENT_END,- forMainFrameOnly: true,- ));- } else if (useLegacyParser) {+ if (useLegacyParser) {logEventController.add('Adding JSBridgeDebug UserScript');const String jsBridgeDebugScript = """window.flutter_inappwebview.callHandler('LogBridge', 'JSBridgeDebug script loaded: ' + window.location.href);diff --git a/lib/webview/webview_controller_impel/webview_controller_impel.dart b/lib/webview/webview_controller_impel/webview_controller_impel.dartindex bc005c2d..5516c82c 100644--- a/lib/webview/webview_controller_impel/webview_controller_impel.dart+++ b/lib/webview/webview_controller_impel/webview_controller_impel.dart@@ -14,7 +14,6 @@ class WebviewItemControllerImpelTimer? loadingMonitorTimer;bool hasRegisteredHandlers = false;bool shouldInjectIframeRedirect = false;- bool useNativePlayer = false;bool useLegacyParser = false;@override@@ -56,16 +55,15 @@ class WebviewItemControllerImpel}@override- Future<void> loadUrl(String url, bool useNativePlayer, bool useLegacyParser,+ Future<void> loadUrl(String url, bool useLegacyParser,{int offset = 0}) async {await unloadPage();if (!hasRegisteredHandlers) {- _addJavaScriptHandlers(useNativePlayer, useLegacyParser);+ _addJavaScriptHandlers(useLegacyParser);hasRegisteredHandlers = true;}count = 0;this.offset = offset;- this.useNativePlayer = useNativePlayer;this.useLegacyParser = useLegacyParser;isIframeLoaded = false;isVideoSourceLoaded = false;@@ -89,7 +87,7 @@ class WebviewItemControllerImpel});}- void _addJavaScriptHandlers(bool useNativePlayer, bool useLegacyParser) {+ void _addJavaScriptHandlers(bool useLegacyParser) {logEventController.add('Adding LogBridge handler');webviewController?.addJavaScriptHandler(handlerName: 'LogBridge',@@ -101,19 +99,7 @@ class WebviewItemControllerImpellogEventController.add(message);});- if (!useNativePlayer) {- logEventController.add('Adding IframeRedirectBridge handler');- webviewController?.addJavaScriptHandler(- handlerName: 'IframeRedirectBridge',- callback: (args) {- String message = args[0].toString();- logEventController.add('Redirect to: $message');- Future.delayed(const Duration(seconds: 2), () {- isIframeLoaded = true;- videoLoadingEventController.add(false);- });- });- } else if (useLegacyParser) {+ if (useLegacyParser) {logEventController.add('Adding JSBridgeDebug handler');webviewController?.addJavaScriptHandler(handlerName: 'JSBridgeDebug',@@ -162,7 +148,7 @@ class WebviewItemControllerImpel}Future<void> _onLoadStart() async {- if (useNativePlayer && !useLegacyParser) {+ if (!useLegacyParser) {logEventController.add('Injecting blob parser script (onLoadStart)');await webviewController?.evaluateJavascript(source: """try { window.flutter_inappwebview.callHandler('LogBridge', 'BlobParser script loaded: ' + window.location.href); } catch(e) {}@@ -270,66 +256,10 @@ class WebviewItemControllerImpel}""");}-- if (!useNativePlayer && shouldInjectIframeRedirect) {- logEventController.add('Injecting IframeRedirect script (onLoadStart)');- shouldInjectIframeRedirect = false;- await webviewController?.evaluateJavascript(source: """- try { window.flutter_inappwebview.callHandler('LogBridge', 'IframeRedirectBridge script loaded: ' + window.location.href); } catch(e) {}- const _observer = new MutationObserver((mutations) => {- window.flutter_inappwebview.callHandler('LogBridge', 'Scanning for iframes...');- for (const mutation of mutations) {- if (mutation.type === "attributes" && mutation.target.nodeName === "IFRAME") {- if (processIframeElement(mutation.target)) return;- continue;- }- for (const node of mutation.addedNodes) {- if (node.nodeName === "IFRAME") {- if (processIframeElement(node)) return;- }- if (node.querySelectorAll) {- for (const iframe of node.querySelectorAll("iframe")) {- if (processIframeElement(iframe)) return;- }- }- }- }- });-- function processIframeElement(iframe) {- window.flutter_inappwebview.callHandler('LogBridge', 'Processing iframe element');- let src = iframe.getAttribute("src");- if (src && src.trim() !== '' && (src.startsWith('http') || src.startsWith('//')) && !src.includes('googleads') && !src.includes('adtrafficquality') && !src.includes('googlesyndication.com') && !src.includes('google.com') && !src.includes('prestrain.html') && !src.includes('prestrain%2Ehtml')) {- _observer.disconnect();- window.flutter_inappwebview.callHandler("IframeRedirectBridge", src);- window.location.href = src;- return true;- }- }-- function setupIframeProcessing() {- for (const iframe of document.querySelectorAll("iframe")) {- if (processIframeElement(iframe)) return;- }- _observer.observe(document.body, {- childList: true,- subtree: true,- attributes: true,- attributeFilter: ["src"],- });- }-- if (document.readyState === 'loading') {- document.addEventListener('DOMContentLoaded', setupIframeProcessing);- } else {- setupIframeProcessing();- }- """);- }}Future<void> _onLoadStop() async {- if (useNativePlayer && !useLegacyParser) {+ if (!useLegacyParser) {logEventController.add('Injecting video tag parser script (onLoadStop)');await webviewController?.evaluateJavascript(source: """window.flutter_inappwebview.callHandler('LogBridge', 'VideoTagParser script loaded: ' + window.location.href);@@ -392,7 +322,7 @@ class WebviewItemControllerImpel""");}- if (useNativePlayer && useLegacyParser) {+ if (useLegacyParser) {logEventController.add('Injecting JSBridgeDebug script (onLoadStop)');await webviewController?.evaluateJavascript(source: """window.flutter_inappwebview.callHandler('LogBridge', 'JSBridgeDebug script loaded: ' + window.location.href);diff --git a/lib/webview/webview_controller_impel/webview_linux_controller_impel.dart b/lib/webview/webview_controller_impel/webview_linux_controller_impel.dartindex 28fd63cf..8f4b1f62 100644--- a/lib/webview/webview_controller_impel/webview_linux_controller_impel.dart+++ b/lib/webview/webview_controller_impel/webview_linux_controller_impel.dart@@ -56,17 +56,17 @@ class WebviewLinuxItemControllerImpel extends WebviewItemController<Webview> {return ProxyConfiguration(host: host, port: port);}- Future<void> initBridge(bool useNativePlayer, bool useLegacyParser) async {- await initJSBridge(useNativePlayer, useLegacyParser);+ Future<void> initBridge(bool useLegacyParser) async {+ await initJSBridge(useLegacyParser);bridgeInited = true;}@override- Future<void> loadUrl(String url, bool useNativePlayer, bool useLegacyParser,+ Future<void> loadUrl(String url, bool useLegacyParser,{int offset = 0}) async {await unloadPage();if (!bridgeInited) {- await initBridge(useNativePlayer, useLegacyParser);+ await initBridge(useLegacyParser);}count = 0;this.offset = offset;@@ -87,7 +87,7 @@ class WebviewLinuxItemControllerImpel extends WebviewItemController<Webview> {bridgeInited = false;}- Future<void> initJSBridge(bool useNativePlayer, bool useLegacyParser) async {+ Future<void> initJSBridge(bool useLegacyParser) async {webviewController!.addOnWebMessageReceivedCallback((message) async {if (message.contains('iframeMessage:')) {String messageItem =@@ -102,7 +102,6 @@ class WebviewLinuxItemControllerImpel extends WebviewItemController<Webview> {!messageItem.contains('adtrafficquality')) {if (Utils.decodeVideoSource(messageItem) !=Uri.encodeFull(messageItem) &&- useNativePlayer &&useLegacyParser) {logEventController.add('Parsing video source $messageItem');isIframeLoaded = true;@@ -127,10 +126,8 @@ class WebviewLinuxItemControllerImpel extends WebviewItemController<Webview> {isIframeLoaded = true;isVideoSourceLoaded = true;videoLoadingEventController.add(false);- if (useNativePlayer) {- unloadPage();- videoParserEventController.add((videoUrl, offset));- }+ unloadPage();+ videoParserEventController.add((videoUrl, offset));}}});@@ -216,6 +213,6 @@ class WebviewLinuxItemControllerImpel extends WebviewItemController<Webview> {""";Future<void> redirect2Blank() async {- webviewController?.launch("about:blank");+ webviewController?.launch("about:blank");}}diff --git a/lib/webview/webview_controller_impel/webview_windows_controller_impel.dart b/lib/webview/webview_controller_impel/webview_windows_controller_impel.dartindex 46dd573b..26800667 100644--- a/lib/webview/webview_controller_impel/webview_windows_controller_impel.dart+++ b/lib/webview/webview_controller_impel/webview_windows_controller_impel.dart@@ -47,7 +47,7 @@ class WebviewWindowsItemControllerImpel}@override- Future<void> loadUrl(String url, bool useNativePlayer, bool useLegacyParser,+ Future<void> loadUrl(String url, bool useLegacyParser,{int offset = 0}) async {await unloadPage();count = 0;