基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
add webdav interface
Predidit70f285b4df17
diff --git a/lib/request/webdav.dart b/lib/request/webdav.dartnew file mode 100644index 00000000..76d3de24--- /dev/null+++ b/lib/request/webdav.dart@@ -0,0 +1,85 @@+import 'dart:io';+import 'package:webdav_client/webdav_client.dart' as webdav;+import 'package:hive/hive.dart';+import 'package:flutter/material.dart' show debugPrint;+import 'package:path_provider/path_provider.dart';+import 'package:kazumi/utils/storage.dart';++class WebDav {+ late String webDavURL;+ late String webDavUsername;+ late String webDavPassword;+ late String fileName;+ late Directory webDavLocalTempDirectory;+ late webdav.Client client;++ WebDav._internal();+ static final WebDav _instance = WebDav._internal();+ factory WebDav() => _instance;++ Future init() async {+ fileName = 'histories.tmp';+ var directory = await getApplicationSupportDirectory();+ webDavLocalTempDirectory = Directory('${directory.path}/webdavTemp');+ Box setting = GStorage.setting;+ webDavURL = setting.get(SettingBoxKey.webDavURL, defaultValue: '');+ webDavUsername =+ setting.get(SettingBoxKey.webDavUsername, defaultValue: '');+ webDavPassword =+ setting.get(SettingBoxKey.webDavPassword, defaultValue: '');+ client = webdav.newClient(+ webDavURL,+ user: webDavUsername,+ password: webDavPassword,+ debug: true,+ );+ client.setHeaders({'accept-charset': 'utf-8'});+ try {+ debugPrint('webDav backup diretory not exists, creating');+ await client.mkdir('/kazumiSync');+ debugPrint('webDav backup diretory create success');+ } catch (_) {+ debugPrint('webDav backup diretory create failed');+ }+ }++ Future update() async {+ if (!await webDavLocalTempDirectory.exists()) {+ await webDavLocalTempDirectory.create(recursive: true);+ }+ final existingFile = File('${webDavLocalTempDirectory.path}/$fileName');+ if (await existingFile.exists()) {+ await existingFile.delete();+ }+ await GStorage.backupBox('histories', existingFile.path);+ try {+ client.remove('/kazumiSync/$fileName.cache');+ } catch (_) {}+ await client.writeFromFile(existingFile.path, '/kazumiSync/$fileName.cache',+ onProgress: (c, t) {+ print(c / t);+ });+ try {+ client.remove('/kazumiSync/$fileName');+ } catch (_) {+ debugPrint('webDav former backup file not exist');+ }+ await client.rename(+ '/kazumiSync/$fileName.cache', '/kazumiSync/$fileName', true);+ }++ Future download() async {+ if (!await webDavLocalTempDirectory.exists()) {+ await webDavLocalTempDirectory.create(recursive: true);+ }+ final existingFile = File('${webDavLocalTempDirectory.path}/$fileName');+ if (await existingFile.exists()) {+ await existingFile.delete();+ }+ await client.read2File('/kazumiSync/$fileName', existingFile.path,+ onProgress: (c, t) {+ print(c / t);+ });+ await GStorage.restoreHistory(existingFile.path);+ }+}diff --git a/lib/utils/storage.dart b/lib/utils/storage.dartindex c952dde7..983517f4 100644--- a/lib/utils/storage.dart+++ b/lib/utils/storage.dart@@ -1,4 +1,7 @@+import 'dart:io';+import 'dart:convert';import 'package:hive/hive.dart';+import 'package:path_provider/path_provider.dart';import 'package:kazumi/modules/bangumi/bangumi_item.dart';import 'package:kazumi/modules/history/history_module.dart';@@ -16,13 +19,61 @@ class GStorage {setting = await Hive.openBox('setting');}+ static Future<void> backupBox(String boxName, String backupFilePath) async {+ final appDocumentDir = await getApplicationDocumentsDirectory();+ final hiveBoxFile = File('${appDocumentDir.path}/hive/$boxName.hive');+ if (await hiveBoxFile.exists()) {+ await hiveBoxFile.copy(backupFilePath);+ print('Backup success: ${backupFilePath}');+ } else {+ print('Hive box not exists');+ }+ }++ static Future<void> restoreHistory(String backupFilePath) async {+ final appDocumentDir = await getApplicationDocumentsDirectory();+ final backupFile = File(backupFilePath);+ final hiveBoxFile = File('${appDocumentDir.path}/hive/histories.hive');+ final hiveBoxLockFile = File('${appDocumentDir.path}/hive/histories.lock');+ histories.close();+ try {+ await hiveBoxFile.delete();+ try {+ await hiveBoxLockFile.delete();+ } catch (_) {}+ await backupFile.copy(hiveBoxFile.path);+ } catch (e) {+ print('Hive box restore error: $e');+ }+ histories = await Hive.openBox('histories');+ }++ static Future<void> patchHistory(String backupFilePath) async {+ final backupFile = File(backupFilePath);+ final backupContent = await backupFile.readAsBytes();+ final tempBox = await Hive.openBox('tempBox', bytes: backupContent);+ final tempBoxItems = tempBox.toMap().entries;++ for (var tempBoxItem in tempBoxItems) {+ if (histories.get(tempBoxItem.key) != null) {+ if (histories.get(tempBoxItem.key)!.lastWatchTime.isBefore(tempBoxItem.value.lastWatchTime)) {+ histories.delete(tempBoxItem.key);+ histories.put(tempBoxItem.key, tempBoxItem.value);+ }+ } else {+ histories.put(tempBoxItem.key, tempBoxItem.value);+ }+ }+ await tempBox.close();+ }+// 阻止实例化GStorage._();}class SettingBoxKey {static const String hAenable = 'hAenable',- searchEnhanceEnable = 'searchEnhanceEnable',+ searchEnhanceEnable = 'searchEnhanceEnable',autoUpdate = 'autoUpdate',alwaysOntop = 'alwaysOntop',danmakuEnhance = 'danmakuEnhance',@@ -44,5 +95,9 @@ class SettingBoxKey {displayMode = 'displayMode',enableGitProxy = 'enableGitProxy',enableSystemProxy = 'enableSystemProxy',- isWideScreen = 'isWideScreen';-}\ No newline at end of file+ isWideScreen = 'isWideScreen',+ webDavEnable = 'webDavEnable',+ webDavURL = 'webDavURL',+ webDavUsername = 'webDavUsername',+ webDavPassword = 'webDavPasswd';+}diff --git a/pubspec.lock b/pubspec.lockindex 866f0859..a075f150 100644--- a/pubspec.lock+++ b/pubspec.lock@@ -1378,6 +1378,14 @@ packages:url: "https://pub.dev"source: hostedversion: "2.4.5"+ webdav_client:+ dependency: "direct main"+ description:+ name: webdav_client+ sha256: "682fffc50b61dc0e8f46717171db03bf9caaa17347be41c0c91e297553bf86b2"+ url: "https://pub.dev"+ source: hosted+ version: "1.2.2"webview_cookie_manager:dependency: "direct main"description:diff --git a/pubspec.yaml b/pubspec.yamlindex 9c218b06..6b052296 100644--- a/pubspec.yaml+++ b/pubspec.yaml@@ -75,6 +75,7 @@ dependencies:webview_flutter: ^4.7.0canvas_danmaku: ^0.1.6animated_search_bar: ^2.7.1+ webdav_client: ^1.2.2webview_windows:git:url: https://github.com/Predidit/flutter-webview-windows.git