Skip to content

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

feat(rules): drop bundled default rules

Prediditd34b3a42f6c0
diff --git a/assets/plugins/7sefun.json b/assets/plugins/7sefun.json
deleted file mode 100644
index 165db433..00000000
--- a/assets/plugins/7sefun.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "api": "4",
- "type": "anime",
- "name": "7sefun",
- "version": "1.3",
- "muliSources": true,
- "useWebview": true,
- "useNativePlayer": true,
- "userAgent": "",
- "baseURL": "https://www.7sefun.top/",
- "searchURL": "https://www.7sefun.top/vodsearch/-------------.html?wd=@keyword",
- "searchList": "//div[2]/div[2]/div[2]/div[2]/div",
- "searchName": "//div[2]/text()",
- "searchResult": "//a",
- "chapterRoads": "//div[2]/div[2]/div[2]/div/div[2]/div[1]//div",
- "chapterResult": "//a"
-}
\ No newline at end of file
diff --git a/assets/plugins/DM84.json b/assets/plugins/DM84.json
deleted file mode 100644
index f1dd3272..00000000
--- a/assets/plugins/DM84.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "api": "5",
- "type": "anime",
- "name": "DM84",
- "version": "1.4",
- "muliSources": true,
- "useWebview": true,
- "useNativePlayer": true,
- "userAgent": "",
- "adBlocker": true,
- "baseURL": "https://dmbus.cc/",
- "searchURL":"https://dmbus.cc/s----------.html?wd=@keyword",
- "searchList": "//div/div[3]/ul/li",
- "searchName": "//div/a[2]",
- "searchResult": "//div/a[2]",
- "chapterRoads": "//div/div[4]/div/ul",
- "chapterResult": "//li/a"
-}
diff --git a/lib/pages/info/info_module.dart b/lib/pages/info/info_module.dart
index 9e29e6b3..94062d81 100644
--- a/lib/pages/info/info_module.dart
+++ b/lib/pages/info/info_module.dart
@@ -3,6 +3,7 @@ import 'package:kazumi/modules/bangumi/bangumi_item.dart';
import 'package:kazumi/pages/info/info_controller.dart';
import 'package:kazumi/pages/info/info_page.dart';
import 'package:kazumi/pages/route_error_page.dart';
+import 'package:kazumi/plugins/plugins_controller.dart';
final infoModule = createModule(
path: '/info',
@@ -18,6 +19,7 @@ final infoModule = createModule(
return InfoPage(
inputBangumiItem: bangumiItem,
infoController: context.read<InfoController>(),
+ pluginsController: inject<PluginsController>(),
);
},
);
diff --git a/lib/pages/info/info_page.dart b/lib/pages/info/info_page.dart
index 06ac268f..66ab5806 100644
--- a/lib/pages/info/info_page.dart
+++ b/lib/pages/info/info_page.dart
@@ -19,6 +19,7 @@ import 'package:kazumi/pages/info/info_controller.dart';
import 'package:kazumi/pages/info/info_tabview.dart';
import 'package:kazumi/pages/info/rating_review_dialog.dart';
import 'package:kazumi/pages/info/source_sheet.dart';
+import 'package:kazumi/plugins/plugins_controller.dart';
import 'package:kazumi/services/logging/logger.dart';
import 'package:kazumi/services/platform/desktop_window_config.dart';
import 'package:kazumi/services/storage/storage.dart';
@@ -29,10 +30,12 @@ class InfoPage extends StatefulWidget {
super.key,
required this.inputBangumiItem,
required this.infoController,
+ required this.pluginsController,
});
final BangumiItem inputBangumiItem;
final InfoController infoController;
+ final PluginsController pluginsController;
@override
State<InfoPage> createState() => _InfoPageState();
@@ -297,6 +300,26 @@ class _InfoPageState extends State<InfoPage>
}
}
+ void _startWatching() {
+ if (widget.pluginsController.pluginList.isEmpty) {
+ KazumiDialog.showToast(
+ message: '还没有规则,无法开始观看',
+ showActionButton: true,
+ actionLabel: '添加规则',
+ onActionPressed: () {
+ if (mounted) context.pushNamed('/settings/plugin/');
+ },
+ duration: const Duration(seconds: 4),
+ );
+ return;
+ }
+ showAdaptiveBottomSheet<void>(
+ context: context,
+ maxHeightFactor: 0.88,
+ builder: (_) => SourceSheet(infoController: infoController),
+ );
+ }
+
Future<void> _waitForMinimumBangumiInfoLoadingDuration(
DateTime loadingStartedAt) async {
final elapsed = DateTime.now().difference(loadingStartedAt);
@@ -447,15 +470,7 @@ class _InfoPageState extends State<InfoPage>
),
floatingActionButton: FloatingActionButton.extended(
tooltip: '开始观看',
- onPressed: () {
- showAdaptiveBottomSheet<void>(
- context: context,
- maxHeightFactor: 0.88,
- builder: (context) {
- return SourceSheet(infoController: infoController);
- },
- );
- },
+ onPressed: _startWatching,
label: const Text('开始观看'),
icon: const Icon(Icons.play_arrow_rounded),
),
diff --git a/lib/pages/info/source_sheet_view.dart b/lib/pages/info/source_sheet_view.dart
index f157f26d..60a180da 100644
--- a/lib/pages/info/source_sheet_view.dart
+++ b/lib/pages/info/source_sheet_view.dart
@@ -142,33 +142,25 @@ class _SourceSheetViewState extends State<_SourceSheetView> {
child: CustomScrollView(
controller: _scrollController,
slivers: [
- if (widget.groups.isEmpty)
- const SliverToBoxAdapter(
- child: GeneralEmptyState(
- icon: Icons.extension_rounded,
- title: '请先在规则管理中添加来源',
- ),
- )
- else
- SliverPadding(
- padding: const EdgeInsets.symmetric(horizontal: 24),
- sliver: SliverList.builder(
- itemCount: widget.groups.length,
- findChildIndexCallback: (key) {
- final index = widget.groups.indexWhere(
- (group) => ValueKey(group.name) == key);
- return index < 0 ? null : index;
- },
- itemBuilder: (context, index) {
- final group = widget.groups[index];
- return Padding(
- key: ValueKey(group.name),
- padding: const EdgeInsets.only(bottom: 12),
- child: _buildSourceGroup(group),
- );
- },
- ),
+ SliverPadding(
+ padding: const EdgeInsets.symmetric(horizontal: 24),
+ sliver: SliverList.builder(
+ itemCount: widget.groups.length,
+ findChildIndexCallback: (key) {
+ final index = widget.groups
+ .indexWhere((group) => ValueKey(group.name) == key);
+ return index < 0 ? null : index;
+ },
+ itemBuilder: (context, index) {
+ final group = widget.groups[index];
+ return Padding(
+ key: ValueKey(group.name),
+ padding: const EdgeInsets.only(bottom: 12),
+ child: _buildSourceGroup(group),
+ );
+ },
),
+ ),
const SliverToBoxAdapter(
child: SafeArea(top: false, child: SizedBox(height: 24)),
),
diff --git a/lib/pages/init_page.dart b/lib/pages/init_page.dart
index be3a8d62..21efa0de 100644
--- a/lib/pages/init_page.dart
+++ b/lib/pages/init_page.dart
@@ -76,25 +76,19 @@ class _InitPageState extends State<InitPage> {
if (!mounted) {
return;
}
- // First launch: no installed rules yet, hand over to the onboarding flow.
- // OnboardingPage takes care of navigating to the default page and
- // triggering the auto update check afterwards.
- if (pluginsController.pluginList.isEmpty) {
+ // Installs that predate the flag already have rules; don't re-onboard them.
+ if (!GStorage.getSetting(SettingsKeys.onboardingCompleted) &&
+ pluginsController.pluginList.isEmpty) {
context.navigate('/onboarding');
return;
}
- if (!mounted) {
- return;
- }
final updateController = myController;
unawaited(runStartupUpdateCheck(
isEnabled: () => GStorage.getSetting(SettingsKeys.autoUpdate),
- checkForUpdate: () async {
- await updateController.checkUpdate(type: 'auto');
- },
+ checkForUpdate: () => updateController.checkUpdate(type: 'auto'),
));
- _startDefaultPage();
+ context.navigate(GStorage.getSetting(SettingsKeys.defaultStartupPage));
}
void _setupBackgroundDownloadNavigation() {
@@ -146,15 +140,6 @@ class _InitPageState extends State<InitPage> {
};
}
- void _startDefaultPage() {
- final defaultStartupPage =
- GStorage.getSetting(SettingsKeys.defaultStartupPage);
- if (!mounted) {
- return;
- }
- context.navigate(defaultStartupPage);
- }
-
// migrate collect from old version (favorites)
Future<void> _migrateStorage() async {
await collectController.migrateCollect();
diff --git a/lib/pages/onboarding/onboarding_page.dart b/lib/pages/onboarding/onboarding_page.dart
index 49cae9be..8504f6a2 100644
--- a/lib/pages/onboarding/onboarding_page.dart
+++ b/lib/pages/onboarding/onboarding_page.dart
@@ -6,15 +6,12 @@ import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/bean/appbar/sys_app_bar.dart';
import 'package:kazumi/bean/dialog/dialog_helper.dart';
-import 'package:kazumi/bean/widget/loading_indicator.dart';
import 'package:kazumi/pages/my/my_controller.dart';
import 'package:kazumi/pages/onboarding/steps/disclaimer_step.dart';
import 'package:kazumi/pages/onboarding/steps/mirror_settings_step.dart';
import 'package:kazumi/pages/onboarding/steps/plugin_shop_step.dart';
import 'package:kazumi/pages/onboarding/steps/update_source_step.dart';
-import 'package:kazumi/plugins/plugins.dart' show pluginNameKey;
import 'package:kazumi/plugins/plugins_controller.dart';
-import 'package:kazumi/services/logging/logger.dart';
import 'package:kazumi/services/storage/storage.dart';
import 'package:kazumi/services/update/startup_update_check.dart';
@@ -53,10 +50,8 @@ class _OnboardingPageState extends State<OnboardingPage> {
];
int _currentIndex = 0;
bool _agreed = false;
- bool _installingBundled = false;
bool _busy = false;
late bool _useGithubUpdate;
- late Set<String> _initialPluginNames;
PluginsController get _pluginsController => widget.pluginsController;
bool get _isLastStep => _currentIndex == _steps.length - 1;
@@ -96,8 +91,7 @@ class _OnboardingPageState extends State<OnboardingPage> {
if (_busy || (!forward && _currentIndex == 0)) return;
_busy = true;
try {
- if (forward && !_agreed && !await _installBundledRules()) return;
- if (!mounted) return;
+ if (forward && !_agreed) setState(() => _agreed = true);
if (forward && _isLastStep) {
await _finish();
} else {
@@ -121,43 +115,15 @@ class _OnboardingPageState extends State<OnboardingPage> {
}
}
- Future<bool> _installBundledRules() async {
- setState(() => _installingBundled = true);
- try {
- await _pluginsController.copyPluginsToExternalDirectory();
- } catch (error, stackTrace) {
- KazumiLogger().e(
- 'Plugin: failed to install bundled rules',
- error: error,
- stackTrace: stackTrace,
- );
- if (!mounted) return false;
- setState(() => _installingBundled = false);
- KazumiDialog.showToast(context: context, message: '初始化规则失败');
- return false;
- }
- if (!mounted) return false;
- _initialPluginNames = _pluginsController.pluginList
- .map((plugin) => pluginNameKey(plugin.name))
- .toSet();
- setState(() {
- _agreed = true;
- _installingBundled = false;
- });
- return true;
- }
-
Future<void> _finish() async {
- // Updating a bundled rule must not count as installing an extra source.
- final hasExtraRules = _pluginsController.pluginList.any(
- (plugin) => !_initialPluginNames.contains(pluginNameKey(plugin.name)));
- if (!hasExtraRules) {
+ if (_pluginsController.pluginList.isEmpty) {
final confirmed = await KazumiDialog.show<bool>(
context: context,
builder: (_) => const _SkipRulesDialog(),
);
if (confirmed != true) return;
}
+ await GStorage.putSetting(SettingsKeys.onboardingCompleted, true);
if (!mounted) return;
final myController = widget.myController;
unawaited(runStartupUpdateCheck(
@@ -177,11 +143,9 @@ class _OnboardingPageState extends State<OnboardingPage> {
minimumSize: const Size(88, 56),
foregroundColor: theme.colorScheme.onSurfaceVariant,
),
- onPressed: _installingBundled
- ? null
- : _currentIndex == 0
- ? () => exit(0)
- : () => _navigate(forward: false),
+ onPressed: _currentIndex == 0
+ ? () => exit(0)
+ : () => _navigate(forward: false),
child: Text(_currentIndex == 0 ? '退出' : '上一步'),
);
final primary = FilledButton.icon(
@@ -191,14 +155,11 @@ class _OnboardingPageState extends State<OnboardingPage> {
textStyle: theme.textTheme.titleMedium
?.copyWith(fontWeight: FontWeight.w600),
),
- onPressed: _installingBundled ? null : () => _navigate(forward: true),
+ onPressed: () => _navigate(forward: true),
iconAlignment: IconAlignment.end,
- icon: _installingBundled
- ? const LoadingIndicator(size: 24, semanticsLabel: '正在准备内置规则')
- : Icon(_isLastStep
- ? Icons.check_rounded
- : Icons.arrow_forward_rounded),
- label: Text(_installingBundled ? '正在准备' : _primaryLabel),
+ icon: Icon(
+ _isLastStep ? Icons.check_rounded : Icons.arrow_forward_rounded),
+ label: Text(_primaryLabel),
);
return Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
@@ -274,7 +235,7 @@ class _SkipRulesDialog extends StatelessWidget {
icon: const Icon(Icons.warning_amber_rounded),
title: const Text('暂不添加规则?'),
content: const Text(
- '你还没有安装额外规则。仅使用内置规则可能导致部分番剧无法搜索或播放,影响观看体验。\n\n确定仍要继续吗?',
+ '没有规则时无法搜索和播放番剧。之后也可以在规则管理中添加。',
),
actions: [
TextButton(
@@ -284,7 +245,7 @@ class _SkipRulesDialog extends StatelessWidget {
FilledButton(
autofocus: true,
onPressed: () => Navigator.of(context).pop(false),
- child: const Text('返回安装'),
+ child: const Text('返回添加'),
),
],
);
diff --git a/lib/pages/onboarding/steps/plugin_shop_step.dart b/lib/pages/onboarding/steps/plugin_shop_step.dart
index d11a8c89..326325c7 100644
--- a/lib/pages/onboarding/steps/plugin_shop_step.dart
+++ b/lib/pages/onboarding/steps/plugin_shop_step.dart
@@ -19,8 +19,8 @@ class PluginShopStep extends StatelessWidget {
icon: Icons.extension_rounded,
shape: OnboardingIconShape.flower,
),
- title: '发现更多番剧来源',
- subtitle: '添加喜欢的规则,拓展搜索来源。也可以先开始使用,稍后在规则管理中添加。',
+ title: '添加番剧来源',
+ subtitle: '规则决定从哪些站点搜索和播放番剧,添加至少一条即可开始观看。',
slivers: slivers,
),
);
diff --git a/lib/plugins/plugins_controller.dart b/lib/plugins/plugins_controller.dart
index 5ed69efe..f34b962c 100644
--- a/lib/plugins/plugins_controller.dart
+++ b/lib/plugins/plugins_controller.dart
@@ -1,11 +1,9 @@
import 'dart:io';
import 'dart:convert';
import 'package:mobx/mobx.dart';
-import 'package:flutter/services.dart' show rootBundle, AssetManifest;
import 'package:path_provider/path_provider.dart';
import 'package:kazumi/plugins/plugins.dart';
import 'package:kazumi/services/plugin/plugin_validity_tracker.dart';
-import 'package:kazumi/services/plugin/plugin_install_time_tracker.dart';
import 'package:kazumi/request/apis/plugin_catalog_api.dart';
import 'package:kazumi/modules/plugin/plugin_http_module.dart';
import 'package:kazumi/services/logging/logger.dart';
@@ -15,9 +13,6 @@ import 'package:kazumi/utils/version.dart';
part 'plugins_controller.g.dart';
-// 从 1.5.1 版本开始,规则文件储存在单一的 plugins.json 文件中。
-// 之前的版本中,规则以分离文件形式存储,版本更新后将这些分离文件合并为单一的 plugins.json 文件。
-
class PluginsController = _PluginsController with _$PluginsController;
enum PluginUpdateAvailability { unknown, notInCatalog, latest, updatable }
@@ -95,108 +90,44 @@ abstract class _PluginsController with Store {
@observable
ObservableList<PluginHTTPItem> pluginHTTPList = ObservableList.of([]);
- // 规则有效性追踪器
final validityTracker = PluginValidityTracker();
- // 规则安装时间追踪器
- final installTimeTracker = PluginInstallTimeTracker();
-
- String pluginsFileName = "plugins.json";
-
- Directory? oldPluginDirectory;
+ static const _pluginsFileName = 'plugins.json';
+ File? _pluginsFile;
- Directory? newPluginDirectory;
-
- // Initializes the plugin directory and loads all plugins
Future<void> init() async {
- final directory = await getApplicationSupportDirectory();
- oldPluginDirectory = Directory('${directory.path}/plugins');
- if (!await oldPluginDirectory!.exists()) {
- await oldPluginDirectory!.create(recursive: true);
- }
- newPluginDirectory = Directory('${directory.path}/plugins/v2');
- if (!await newPluginDirectory!.exists()) {
- await newPluginDirectory!.create(recursive: true);
- }
- await _loadAllPlugins();
- }
-
- // Loads all plugins from the directory, populates the plugin list, and saves to plugins.json if needed
- Future<void> _loadAllPlugins() async {
+ final supportDirectory = await getApplicationSupportDirectory();
+ final legacyDirectory = Directory('${supportDirectory.path}/plugins');
+ final directory = Directory('${legacyDirectory.path}/v2');
+ await directory.create(recursive: true);
+ KazumiLogger().i('Plugins Directory: ${directory.path}');
+ final pluginsFile = File('${directory.path}/$_pluginsFileName');
+ _pluginsFile = pluginsFile;
pluginList.clear();
- KazumiLogger().i('Plugins Directory: ${newPluginDirectory!.path}');
- if (await newPluginDirectory!.exists()) {
- final pluginsFile = File('${newPluginDirectory!.path}/$pluginsFileName');
- if (await pluginsFile.exists()) {
- final jsonString = await pluginsFile.readAsString();
- pluginList.addAll(_getPluginListFromJson(jsonString));
- KazumiLogger().i('Plugin: Current Plugin number: ${pluginList.length}');
- } else {
- // No plugins.json
- var jsonFiles = await _getPluginFiles();
- for (var filePath in jsonFiles) {
- final file = File(filePath);
- final jsonString = await file.readAsString();
- final data = jsonDecode(jsonString);
- final plugin = Plugin.fromJson(data);
- pluginList.add(plugin);
- await file.delete(recursive: true);
- }
- await _savePlugins();
- }
+ if (await pluginsFile.exists()) {
+ final List<dynamic> json = jsonDecode(await pluginsFile.readAsString());
+ pluginList.addAll([for (final item in json) Plugin.fromJson(item)]);
+ KazumiLogger().i('Plugin: Current Plugin number: ${pluginList.length}');
} else {
- KazumiLogger().w('Plugin: plugin directory does not exist');
+ await _migrateLegacyPlugins(legacyDirectory);
}
}
- // Retrieves a list of JSON plugin file paths from the plugin directory
- Future<List<String>> _getPluginFiles() async {
- if (await oldPluginDirectory!.exists()) {
- final jsonFiles = oldPluginDirectory!
- .listSync()
- .where((file) => file.path.endsWith('.json') && file is File)
- .map((file) => file.path)
- .toList();
- return jsonFiles;
- } else {
- return [];
- }
- }
-
- // Copies plugin JSON files from the assets to the plugin directory
- Future<void> copyPluginsToExternalDirectory() async {
- final assetManifest = await AssetManifest.loadFromAssetBundle(rootBundle);
- final assets = assetManifest.listAssets();
- final jsonFiles = assets.where((String asset) =>
- asset.startsWith('assets/plugins/') && asset.endsWith('.json'));
-
- for (var filePath in jsonFiles) {
- final jsonString = await rootBundle.loadString(filePath);
- final plugin = Plugin.fromJson(jsonDecode(jsonString));
- pluginList.add(plugin);
+ // Before 1.5.1 each rule was a separate JSON file in the parent directory.
+ Future<void> _migrateLegacyPlugins(Directory legacyDirectory) async {
+ final legacyFiles = legacyDirectory
+ .listSync()
+ .whereType<File>()
+ .where((file) => file.path.endsWith('.json'));
+ for (final file in legacyFiles) {
+ pluginList.add(Plugin.fromJson(jsonDecode(await file.readAsString())));
+ await file.delete();
}
await _savePlugins();
- KazumiLogger().i(
- 'Plugin: ${jsonFiles.length} plugin files copied to ${newPluginDirectory!.path}');
}
- List<dynamic> _pluginListToJson() {
- final List<dynamic> json = [];
- for (var plugin in pluginList) {
- json.add(plugin.toJson());
- }
- return json;
- }
-
- // Converts a JSON string into a list of Plugin objects.
- List<Plugin> _getPluginListFromJson(String jsonString) {
- List<dynamic> json = jsonDecode(jsonString);
- List<Plugin> plugins = [];
- for (var j in json) {
- plugins.add(Plugin.fromJson(j));
- }
- return plugins;
- }
+ List<dynamic> _pluginListToJson() =>
+ [for (final plugin in pluginList) plugin.toJson()];
Future<void> removePlugin(Plugin plugin) {
return _mutateAndPersist(
@@ -311,9 +242,8 @@ abstract class _PluginsController with Store {
if (writer != null) {
await writer(jsonData);
} else {
- final pluginsFile = File('${newPluginDirectory!.path}/$pluginsFileName');
- await pluginsFile.writeAsString(jsonData);
- KazumiLogger().i('Plugin: updated plugin file $pluginsFileName');
+ await _pluginsFile!.writeAsString(jsonData);
+ KazumiLogger().i('Plugin: updated plugin file $_pluginsFileName');
}
}
diff --git a/lib/services/plugin/plugin_install_time_tracker.dart b/lib/services/plugin/plugin_install_time_tracker.dart
deleted file mode 100644
index f20e543d..00000000
--- a/lib/services/plugin/plugin_install_time_tracker.dart
+++ /dev/null
@@ -1,16 +0,0 @@
-// 记录规则安装时间
-// 使用文件修改时间作为规则的安装时间
-class PluginInstallTimeTracker {
- // 记录规则安装时间的映射
- final Map<String, int> _installTimes = {};
-
- // 设置规则的安装时间
- void setInstallTime(String pluginName, int timestamp) {
- _installTimes[pluginName] = timestamp;
- }
-
- // 获取规则的安装时间,如果不存在返回0
- int getInstallTime(String pluginName) {
- return _installTimes[pluginName] ?? 0;
- }
-}
diff --git a/lib/services/storage/settings_keys.dart b/lib/services/storage/settings_keys.dart
index e6b4377b..54e262f3 100644
--- a/lib/services/storage/settings_keys.dart
+++ b/lib/services/storage/settings_keys.dart
@@ -502,6 +502,11 @@ class SettingsKeys {
false,
group: SettingGroup.misc,
);
+ static const onboardingCompleted = SettingKey<bool>(
+ 'onboardingCompleted',
+ false,
+ group: SettingGroup.misc,
+ );
static const bangumiSyncEnable = SettingKey<bool>(
_SettingBoxKey.bangumiSyncEnable,
false,
@@ -650,6 +655,7 @@ class SettingsKeys {
downloadDirectory,
downloadDirectoryBookmark,
shortcutDialogShown,
+ onboardingCompleted,
bangumiSyncEnable,
bangumiAccessToken,
bangumiSyncPriority,
diff --git a/pubspec.yaml b/pubspec.yaml
index 68b39415..62598cf8 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -157,7 +157,6 @@ flutter:
uses-material-design: true
assets:
- assets/images/
- - assets/plugins/
- assets/shaders/
- assets/images/logo/
- assets/statements/