基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
add anime follow list sync draft
Predidit66f1f74f3937
diff --git a/lib/pages/favorite/favorite_controller.dart b/lib/pages/favorite/favorite_controller.dartindex 34701df4..c95b46d8 100644--- a/lib/pages/favorite/favorite_controller.dart+++ b/lib/pages/favorite/favorite_controller.dart@@ -1,5 +1,9 @@+import 'package:flutter/material.dart';+import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';import 'package:kazumi/modules/bangumi/bangumi_item.dart';import 'package:kazumi/utils/storage.dart';+import 'package:kazumi/utils/webdav.dart';+import 'package:hive/hive.dart';import 'package:mobx/mobx.dart';part 'favorite_controller.g.dart';@@ -7,19 +11,45 @@ part 'favorite_controller.g.dart';class FavoriteController = _FavoriteController with _$FavoriteController;abstract class _FavoriteController with Store {- late var storedFavorites = GStorage.favorites;+ // late var storedFavorites = GStorage.favorites;+ Box setting = GStorage.setting;- List<BangumiItem> get favorites => storedFavorites.values.toList();+ List<BangumiItem> get favorites => GStorage.favorites.values.toList();bool isFavorite(BangumiItem bangumiItem) {- return !(storedFavorites.get(bangumiItem.id) == null);+ return !(GStorage.favorites.get(bangumiItem.id) == null);}- void addFavorite(BangumiItem bangumiItem) {- storedFavorites.put(bangumiItem.id, bangumiItem);+ Future addFavorite(BangumiItem bangumiItem) async {+ await GStorage.favorites.put(bangumiItem.id, bangumiItem);+ await GStorage.favorites.flush();+ bool webDavEnable = await setting.get(SettingBoxKey.webDavEnable, defaultValue: false);+ bool webDavEnableFavorite = await setting.get(SettingBoxKey.webDavEnableFavorite, defaultValue: false);+ if (webDavEnable && webDavEnableFavorite) {+ try {+ await updateFavorite();+ } catch (e) {+ SmartDialog.showToast('更新webDav记录失败 ${e.toString()}');+ }+ }}- void deleteFavorite(BangumiItem bangumiItem) {- storedFavorites.delete(bangumiItem.id);+ Future deleteFavorite(BangumiItem bangumiItem) async {+ await GStorage.favorites.delete(bangumiItem.id);+ await GStorage.favorites.flush();+ bool webDavEnable = await setting.get(SettingBoxKey.webDavEnable, defaultValue: false);+ bool webDavEnableFavorite = await setting.get(SettingBoxKey.webDavEnableFavorite, defaultValue: false);+ if (webDavEnable && webDavEnableFavorite) {+ try {+ await updateFavorite();+ } catch (e) {+ SmartDialog.showToast('更新webDav记录失败 ${e.toString()}');+ }+ }}-}\ No newline at end of file++ Future updateFavorite() async{+ debugPrint('提交到WebDav的追番列表长度 ${GStorage.favorites.length}');+ await WebDav().updateFavorite();+ }+}diff --git a/lib/pages/init_page.dart b/lib/pages/init_page.dartindex 47e9aa9d..40a57ce1 100644--- a/lib/pages/init_page.dart+++ b/lib/pages/init_page.dart@@ -25,17 +25,32 @@ class _InitPageState extends State<InitPage> {}_webDavInit() async {- bool webDavEnable = setting.get(SettingBoxKey.webDavEnable, defaultValue: false);+ bool webDavEnable =+ setting.get(SettingBoxKey.webDavEnable, defaultValue: false);+ bool webDavEnableFavorite =+ setting.get(SettingBoxKey.webDavEnableFavorite, defaultValue: false);if (webDavEnable) {var webDav = WebDav();- debugPrint('开始从WEBDAV同步观看记录');+ debugPrint('开始从WEBDAV同步记录');try {await webDav.init();- await webDav.download();- debugPrint('同步完成');+ try {+ await webDav.downloadHistory();+ debugPrint('同步观看记录完成');+ } catch (e) {+ debugPrint('同步观看记录失败 ${e.toString()}');+ }+ if (webDavEnableFavorite) {+ try {+ await webDav.downloadFavorite();+ debugPrint('同步追番列表完成');+ } catch (e) {+ debugPrint('同步追番列表失败 ${e.toString()}');+ }+ }} catch (e) {- debugPrint('同步失败 ${e.toString()}');- }+ debugPrint('初始化WebDav失败 ${e.toString()}');+ }}}@@ -87,7 +102,10 @@ class _InitPageState extends State<InitPage> {Widget build(BuildContext context) {/// 适配平板设备Box setting = GStorage.setting;- bool isWideScreen = MediaQuery.of(context).size.shortestSide >= 600 && (MediaQuery.of(context).size.shortestSide / MediaQuery.of(context).size.longestSide >= 9 /16);+ bool isWideScreen = MediaQuery.of(context).size.shortestSide >= 600 &&+ (MediaQuery.of(context).size.shortestSide /+ MediaQuery.of(context).size.longestSide >=+ 9 / 16);if (isWideScreen) {debugPrint('当前设备宽屏');} else {diff --git a/lib/pages/player/player_item.dart b/lib/pages/player/player_item.dartindex 8606bdb0..076f864a 100644--- a/lib/pages/player/player_item.dart+++ b/lib/pages/player/player_item.dart@@ -181,7 +181,7 @@ class _PlayerItemState extends State<PlayerItem> with WindowListener {if (webDavEnable) {try {var webDav = WebDav();- webDav.update();+ webDav.updateHistory();} catch (e) {SmartDialog.showToast('同步记录失败 ${e.toString()}');}diff --git a/lib/pages/webdav_editor/webdav_setting.dart b/lib/pages/webdav_editor/webdav_setting.dartindex b4291369..89d3b14c 100644--- a/lib/pages/webdav_editor/webdav_setting.dart+++ b/lib/pages/webdav_editor/webdav_setting.dart@@ -6,7 +6,6 @@ import 'package:kazumi/utils/storage.dart';import 'package:kazumi/utils/webdav.dart';import 'package:provider/provider.dart';import 'package:hive/hive.dart';-import 'package:kazumi/utils/storage.dart';import 'package:kazumi/pages/menu/menu.dart';import 'package:kazumi/pages/menu/side_menu.dart';import 'package:flutter_modular/flutter_modular.dart';@@ -50,7 +49,7 @@ class _PlayerSettingsPageState extends State<WebDavSettingsPage> {SmartDialog.showToast('尝试从WebDav同步');var webDav = WebDav();webDav.init();- await webDav.download();+ await webDav.downloadHistory();SmartDialog.showToast('同步成功');} catch (e) {SmartDialog.showToast('同步失败 ${e.toString()}');diff --git a/lib/utils/storage.dart b/lib/utils/storage.dartindex ddefa360..b90ab191 100644--- a/lib/utils/storage.dart+++ b/lib/utils/storage.dart@@ -1,4 +1,5 @@import 'dart:io';+import 'package:flutter/material.dart';import 'package:hive/hive.dart';import 'package:path_provider/path_provider.dart';import 'package:kazumi/modules/bangumi/bangumi_item.dart';@@ -51,22 +52,39 @@ class GStorage {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 tempBox = await Hive.openBox('tempHistoryBox', 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);+ if (histories+ .get(tempBoxItem.key)!+ .lastWatchTime+ .isBefore(tempBoxItem.value.lastWatchTime)) {+ await histories.delete(tempBoxItem.key);+ await histories.put(tempBoxItem.key, tempBoxItem.value);}} else {- histories.put(tempBoxItem.key, tempBoxItem.value);+ await histories.put(tempBoxItem.key, tempBoxItem.value);}}await tempBox.close();}+ static Future<void> patchFavorites(String backupFilePath) async {+ final backupFile = File(backupFilePath);+ final backupContent = await backupFile.readAsBytes();+ final tempBox = await Hive.openBox('tempFavoritesBox', bytes: backupContent);+ final tempBoxItems = tempBox.toMap().entries;+ debugPrint('webDav追番列表长度 ${tempBoxItems.length}');++ await favorites.clear();+ for (var tempBoxItem in tempBoxItems) {+ await favorites.put(tempBoxItem.key, tempBoxItem.value);+ }+ await tempBox.close();+ }+// 阻止实例化GStorage._();}@@ -97,6 +115,7 @@ class SettingBoxKey {enableSystemProxy = 'enableSystemProxy',isWideScreen = 'isWideScreen',webDavEnable = 'webDavEnable',+ webDavEnableFavorite = 'webDavEnableFavorite',webDavURL = 'webDavURL',webDavUsername = 'webDavUsername',webDavPassword = 'webDavPasswd';diff --git a/lib/utils/webdav.dart b/lib/utils/webdav.dartindex 5b8fe5cd..f773416d 100644--- a/lib/utils/webdav.dart+++ b/lib/utils/webdav.dart@@ -9,7 +9,6 @@ class WebDav {late String webDavURL;late String webDavUsername;late String webDavPassword;- late String fileName;late Directory webDavLocalTempDirectory;late webdav.Client client;@@ -18,7 +17,6 @@ class WebDav {factory WebDav() => _instance;Future init() async {- fileName = 'histories.tmp';var directory = await getApplicationSupportDirectory();webDavLocalTempDirectory = Directory('${directory.path}/webdavTemp');Box setting = GStorage.setting;@@ -43,32 +41,50 @@ class WebDav {}}- 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);+ Future update(String boxName) async {+ var directory = await getApplicationSupportDirectory();try {- await client.remove('/kazumiSync/$fileName.cache');+ await client.remove('/kazumiSync/$boxName.tmp.cache');} catch (_) {}- await client.writeFromFile(existingFile.path, '/kazumiSync/$fileName.cache',+ await client.writeFromFile('${directory.path}/hive/$boxName.hive', '/kazumiSync/$boxName.tmp.cache',onProgress: (c, t) {print(c / t);});try {- await client.remove('/kazumiSync/$fileName');+ await client.remove('/kazumiSync/$boxName.tmp');} catch (_) {debugPrint('webDav former backup file not exist');}await client.rename(- '/kazumiSync/$fileName.cache', '/kazumiSync/$fileName', true);+ '/kazumiSync/$boxName.tmp.cache', '/kazumiSync/$boxName.tmp', true);+ }++ Future updateHistory() async {+ await update('histories');+ }++ Future updateFavorite() async {+ await update('favorites');}- Future download() async {+ Future downloadHistory() async {+ String fileName = 'histories.tmp';+ 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.patchHistory(existingFile.path);+ }++ Future downloadFavorite() async {+ String fileName = 'favorites.tmp';if (!await webDavLocalTempDirectory.exists()) {await webDavLocalTempDirectory.create(recursive: true);}@@ -80,7 +96,7 @@ class WebDav {onProgress: (c, t) {print(c / t);});- await GStorage.patchHistory(existingFile.path);+ await GStorage.patchFavorites(existingFile.path);}Future ping() async {