Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

plugin editor done

Predidit29e872ba2f0f
diff --git a/assets/plugins/ant.json b/assets/plugins/ant.json
index 4aaa03e7..b3cf8b44 100644
--- a/assets/plugins/ant.json
+++ b/assets/plugins/ant.json
@@ -1,5 +1,5 @@
{
- "name": "Ant",
+ "name": "ant",
"version": "0.0.1",
"muliSources": true,
"useWebview": true,
diff --git a/assets/plugins/girigirilove.json b/assets/plugins/girigirilove.json
index aa28f710..43c2f1ff 100644
--- a/assets/plugins/girigirilove.json
+++ b/assets/plugins/girigirilove.json
@@ -1,5 +1,5 @@
{
- "name": "GiriGiriLove",
+ "name": "giriGiriLove",
"version": "0.0.1",
"muliSources": true,
"useWebview": true,
diff --git a/assets/plugins/sakura.json b/assets/plugins/sakura.json
index 689bc912..5900c566 100644
--- a/assets/plugins/sakura.json
+++ b/assets/plugins/sakura.json
@@ -1,5 +1,5 @@
{
- "name": "Sakura",
+ "name": "sakura",
"version": "0.0.1",
"muliSources": true,
"useWebview": true,
diff --git a/lib/pages/init_page.dart b/lib/pages/init_page.dart
index 38957695..ad04b63f 100644
--- a/lib/pages/init_page.dart
+++ b/lib/pages/init_page.dart
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:kazumi/plugins/plugins_controller.dart';
import 'package:flutter_modular/flutter_modular.dart';
+import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
class InitPage extends StatefulWidget {
const InitPage({super.key});
@@ -18,9 +19,47 @@ class _InitPageState extends State<InitPage> {
super.initState();
}
- _init() {
- pluginsController.loadPlugins();
- Modular.to.navigate('/tab/popular/');
+ _init() async {
+ try {
+ await pluginsController.loadPlugins();
+ } catch (_) {}
+ if (pluginsController.pluginList.isEmpty) {
+ SmartDialog.show(
+ animationType: SmartAnimationType.centerFade_otherSlide,
+ builder: (context) {
+ return AlertDialog(
+ title: const Text('插件管理'),
+ content: const Text('当前规则数为0, 是否加载默认规则'),
+ actions: [
+ TextButton(
+ onPressed: () {
+ SmartDialog.dismiss();
+ Modular.to.navigate('/tab/popular/');
+ },
+ child: Text(
+ '取消',
+ style:
+ TextStyle(color: Theme.of(context).colorScheme.outline),
+ ),
+ ),
+ TextButton(
+ onPressed: () async {
+ try {
+ await pluginsController.copyPluginsToExternalDirectory();
+ await pluginsController.loadPlugins();
+ } catch (_) {}
+ SmartDialog.dismiss();
+ Modular.to.navigate('/tab/popular/');
+ },
+ child: const Text('确认'),
+ ),
+ ],
+ );
+ },
+ );
+ } else {
+ Modular.to.navigate('/tab/popular/');
+ }
}
@override
diff --git a/lib/pages/plugin_editor/plugin_editor_page.dart b/lib/pages/plugin_editor/plugin_editor_page.dart
index 65671e22..221532bc 100644
--- a/lib/pages/plugin_editor/plugin_editor_page.dart
+++ b/lib/pages/plugin_editor/plugin_editor_page.dart
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/plugins/plugins.dart';
+import 'package:kazumi/plugins/plugins_controller.dart';
class PluginEditorPage extends StatefulWidget {
const PluginEditorPage({
@@ -12,6 +13,7 @@ class PluginEditorPage extends StatefulWidget {
}
class _PluginEditorPageState extends State<PluginEditorPage> {
+ final PluginsController pluginsController = Modular.get<PluginsController>();
final TextEditingController nameController = TextEditingController();
final TextEditingController versionController = TextEditingController();
final TextEditingController userAgentController = TextEditingController();
@@ -105,6 +107,27 @@ class _PluginEditorPageState extends State<PluginEditorPage> {
],
),
),
+ floatingActionButton: FloatingActionButton(
+ child: const Icon(Icons.save),
+ onPressed: () async {
+ plugin.name = nameController.text;
+ plugin.version = versionController.text;
+ plugin.userAgent = userAgentController.text;
+ plugin.baseUrl = baseURLController.text;
+ plugin.searchURL = searchURLController.text;
+ plugin.searchList = searchListController.text;
+ plugin.searchName = searchNameController.text;
+ plugin.searchResult = searchResultController.text;
+ plugin.chapterRoads = chapterRoadsController.text;
+ plugin.chapterResult = chapterResultController.text;
+ plugin.muliSources = muliSources;
+ plugin.useWebview = useWebview;
+ plugin.useNativePlayer = useNativePlayer;
+ await pluginsController.savePluginToJsonFile(plugin);
+ await pluginsController.loadPlugins();
+ Modular.to.navigate('/tab/my');
+ },
+ ),
);
}
}
diff --git a/lib/pages/video/video_page.dart b/lib/pages/video/video_page.dart
index 759e5e2b..226c756a 100644
--- a/lib/pages/video/video_page.dart
+++ b/lib/pages/video/video_page.dart
@@ -57,8 +57,10 @@ class _VideoPageState extends State<VideoPage>
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (Platform.isWindows) {
- final WebviewDesktopItemController webviewDesktopItemController = Modular.get<WebviewDesktopItemController>();
- if (!webviewDesktopItemController.webviewController.value.isInitialized) {
+ final WebviewDesktopItemController webviewDesktopItemController =
+ Modular.get<WebviewDesktopItemController>();
+ if (!webviewDesktopItemController
+ .webviewController.value.isInitialized) {
await webviewDesktopItemController.init();
}
}
@@ -78,8 +80,7 @@ class _VideoPageState extends State<VideoPage>
Positioned.fill(
child: Visibility(
visible: videoPageController.loading,
- child: (videoPageController.currentPlugin.useNativePlayer !=
- 'true')
+ child: (!videoPageController.currentPlugin.useNativePlayer)
? Container(
color: Colors.black,
child: const Center(
@@ -87,16 +88,14 @@ class _VideoPageState extends State<VideoPage>
: Container(),
)),
Positioned.fill(
- child: (videoPageController.currentPlugin.useNativePlayer !=
- 'true')
+ child: (!videoPageController.currentPlugin.useNativePlayer)
? Container()
: const PlayerItem(),
),
Positioned(
child: SizedBox(
height: (videoPageController.loading ||
- videoPageController.currentPlugin.useNativePlayer ==
- 'true')
+ videoPageController.currentPlugin.useNativePlayer)
? 0
: null,
child: Platform.isWindows
@@ -156,7 +155,8 @@ class _VideoPageState extends State<VideoPage>
child: InkWell(
onTap: () async {
debugPrint('视频链接为 $urlItem');
- videoPageController.changeEpisode(_count, currentRoad: roadIndex);
+ videoPageController.changeEpisode(_count,
+ currentRoad: roadIndex);
},
child: Padding(
padding: const EdgeInsets.symmetric(
diff --git a/lib/pages/webview/webview_controller.dart b/lib/pages/webview/webview_controller.dart
index a34bca47..c0e5aed7 100644
--- a/lib/pages/webview/webview_controller.dart
+++ b/lib/pages/webview/webview_controller.dart
@@ -26,12 +26,12 @@ class WebviewItemController {
debugPrint(
'由iframe参数获取视频源 ${Utils.decodeVideoSource(message.message)}');
isVideoSourceLoaded = true;
+ videoPageController.loading = false;
if (videoPageController.currentPlugin.useNativePlayer) {
unloadPage();
playerController.videoUrl = Utils.decodeVideoSource(message.message);
playerController.init();
}
- videoPageController.loading = false;
}
}
});
@@ -41,12 +41,12 @@ class WebviewItemController {
if (message.message.contains('http')) {
debugPrint('由video标签获取视频源 ${message.message}');
isVideoSourceLoaded = true;
+ videoPageController.loading = false;
if (videoPageController.currentPlugin.useNativePlayer) {
unloadPage();
playerController.videoUrl = message.message;
playerController.init();
}
- videoPageController.loading = false;
}
});
await webviewController.loadRequest(Uri.parse(url));
diff --git a/lib/pages/webview_desktop/webview_desktop_controller.dart b/lib/pages/webview_desktop/webview_desktop_controller.dart
index 106fee2a..a9fede5c 100644
--- a/lib/pages/webview_desktop/webview_desktop_controller.dart
+++ b/lib/pages/webview_desktop/webview_desktop_controller.dart
@@ -51,13 +51,14 @@ class WebviewDesktopItemController {
isIframeLoaded = true;
if (Utils.decodeVideoSource(messageItem) != messageItem) {
isVideoSourceLoaded = true;
- debugPrint('由iframe参数获取视频源 ${Utils.decodeVideoSource(messageItem)}');
+ videoPageController.loading = false;
+ debugPrint(
+ '由iframe参数获取视频源 ${Utils.decodeVideoSource(messageItem)}');
if (videoPageController.currentPlugin.useNativePlayer) {
unloadPage();
playerController.videoUrl = Utils.decodeVideoSource(messageItem);
playerController.init();
}
- videoPageController.loading = false;
}
}
}
@@ -67,12 +68,12 @@ class WebviewDesktopItemController {
if (messageItem.contains('http')) {
debugPrint('成功获取视频源');
isVideoSourceLoaded = true;
+ videoPageController.loading = false;
if (videoPageController.currentPlugin.useNativePlayer) {
unloadPage();
playerController.videoUrl = messageItem;
playerController.init();
}
- videoPageController.loading = false;
}
}
});
diff --git a/lib/plugins/plugins.dart b/lib/plugins/plugins.dart
index cb293000..b36ecde3 100644
--- a/lib/plugins/plugins.dart
+++ b/lib/plugins/plugins.dart
@@ -56,6 +56,24 @@ class Plugin {
chapterResult: json['chapterResult']);
}
+ Map<String, dynamic> toJson() {
+ final Map<String, dynamic> data = new Map<String, dynamic>();
+ data['name'] = this.name;
+ data['version'] = this.version;
+ data['muliSources'] = this.muliSources;
+ data['useWebview'] = this.useWebview;
+ data['useNativePlayer'] = this.useNativePlayer;
+ data['userAgent'] = this.userAgent;
+ data['baseURL'] = this.baseUrl;
+ data['searchURL'] = this.searchURL;
+ data['searchList'] = this.searchList;
+ data['searchName'] = this.searchName;
+ data['searchResult'] = this.searchResult;
+ data['chapterRoads'] = this.chapterRoads;
+ data['chapterResult'] = this.chapterResult;
+ return data;
+ }
+
queryBangumi(String keyword) async {
String queryURL = searchURL.replaceAll('@keyword', keyword);
List<SearchItem> searchItems = [];
diff --git a/lib/plugins/plugins_controller.dart b/lib/plugins/plugins_controller.dart
index df6efa03..39029623 100644
--- a/lib/plugins/plugins_controller.dart
+++ b/lib/plugins/plugins_controller.dart
@@ -1,13 +1,47 @@
+import 'dart:io';
import 'dart:convert';
import 'package:flutter/services.dart' show rootBundle;
import 'package:flutter/material.dart' show debugPrint;
+import 'package:path_provider/path_provider.dart';
import 'package:kazumi/plugins/plugins.dart';
class PluginsController {
List<Plugin> pluginList = [];
- loadPlugins() async {
+ Future<void> loadPlugins() async {
pluginList.clear();
+
+ final directory = await getApplicationSupportDirectory();
+ final pluginDirectory = Directory('${directory.path}/plugins');
+ debugPrint('插件目录 ${directory.path}/plugins');
+
+ if (await pluginDirectory.exists()) {
+ final jsonFiles = pluginDirectory
+ .listSync()
+ .where((file) => file.path.endsWith('.json') && file is File)
+ .map((file) => file.path)
+ .toList();
+
+ for (var filePath in jsonFiles) {
+ final jsonString = await File(filePath).readAsString();
+ final data = jsonDecode(jsonString);
+ pluginList.add(Plugin.fromJson(data));
+ }
+
+ debugPrint('当前插件数量 ${pluginList.length}');
+ } else {
+ debugPrint('插件目录不存在');
+ }
+ }
+
+ Future<void> copyPluginsToExternalDirectory() async {
+ final directory = await getApplicationSupportDirectory();
+ final pluginDirectory = Directory('${directory.path}/plugins');
+
+ if (!await pluginDirectory.exists()) {
+ await pluginDirectory.create(recursive: true);
+ }
+
final manifestContent = await rootBundle.loadString('AssetManifest.json');
final Map<String, dynamic> manifestMap = json.decode(manifestContent);
@@ -16,10 +50,34 @@ class PluginsController {
for (var filePath in jsonFiles) {
final jsonString = await rootBundle.loadString(filePath);
- final data = jsonDecode(jsonString);
- pluginList.add(Plugin.fromJson(data));
+ // panic
+ final fileName = filePath.split('/').last;
+ final file = File('${pluginDirectory.path}/$fileName');
+ await file.writeAsString(jsonString);
}
- debugPrint('当前插件数量 ${pluginList.length}');
+ debugPrint('已将 ${jsonFiles.length} 个插件文件拷贝到 ${pluginDirectory.path}');
+ }
+
+ Future<void> savePluginToJsonFile(Plugin plugin) async {
+
+ final directory = await getApplicationSupportDirectory();
+ final pluginDirectory = Directory('${directory.path}/plugins');
+
+ if (!await pluginDirectory.exists()) {
+ await pluginDirectory.create(recursive: true);
+ }
+
+ final fileName = '${plugin.name}.json';
+ final existingFile = File('${pluginDirectory.path}/$fileName');
+ if (await existingFile.exists()) {
+ await existingFile.delete();
+ }
+
+ final newFile = File('${pluginDirectory.path}/$fileName');
+ final jsonData = jsonEncode(plugin.toJson());
+ await newFile.writeAsString(jsonData);
+
+ debugPrint('已创建插件文件 $fileName');
}
}