基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
feat: customize syncplay server
Predidit94bea502dd2d
diff --git a/lib/pages/player/player_controller.dart b/lib/pages/player/player_controller.dartindex 1c1f1778..4fb3f15e 100644--- a/lib/pages/player/player_controller.dart+++ b/lib/pages/player/player_controller.dart@@ -523,7 +523,27 @@ abstract class _PlayerController with Store {changeEpisode,{bool enableTLS = false}) async {await syncplayController?.disconnect();- syncplayController = SyncplayClient(host: 'syncplay.pl', port: 8995);+ final String syncPlayEndPoint = setting.get(SettingBoxKey.syncPlayEndPoint,+ defaultValue: defaultSyncPlayEndPoint);+ String syncPlayEndPointHost = '';+ int syncPlayEndPointPort = 0;+ debugPrint('SyncPlay: 连接到服务器 $syncPlayEndPoint');+ try {+ final parts = syncPlayEndPoint.split(':');+ if (parts.length == 2) {+ syncPlayEndPointHost = parts[0];+ syncPlayEndPointPort = int.parse(parts[1]);+ }+ } catch (_) {}+ if (syncPlayEndPointHost == '' || syncPlayEndPointPort == 0) {+ KazumiDialog.showToast(+ message: 'SyncPlay: 服务器地址不合法 $syncPlayEndPoint',+ );+ KazumiLogger().log(Level.error, 'SyncPlay: 服务器地址不合法 $syncPlayEndPoint');+ return;+ }+ syncplayController =+ SyncplayClient(host: syncPlayEndPointHost, port: syncPlayEndPointPort);try {await syncplayController!.connect(enableTLS: enableTLS);syncplayController!.onGeneralMessage.listen(diff --git a/lib/pages/player/player_item.dart b/lib/pages/player/player_item.dartindex d00a3512..e4bb1a5a 100644--- a/lib/pages/player/player_item.dart+++ b/lib/pages/player/player_item.dart@@ -321,7 +321,8 @@ class _PlayerItemState extends State<PlayerItem>() => mounted &&playerController.playerPlaying &&!playerController.playerBuffering &&- playerController.danmakuOn && !myController.isDanmakuBlocked(danmaku.message)+ playerController.danmakuOn &&+ !myController.isDanmakuBlocked(danmaku.message)? playerController.danmakuController.addDanmaku(DanmakuContentItem(danmaku.message,color: danmaku.color,@@ -662,6 +663,126 @@ class _PlayerItemState extends State<PlayerItem>});}+ void showSyncPlayEndPointSwitchDialog() {+ if (playerController.syncplayController != null) {+ KazumiDialog.showToast(message: 'SyncPlay: 请先退出当前房间再切换服务器');+ return;+ }++ final String defaultCustomSyncPlayEndPoint = '自定义服务器';+ String customSyncPlayEndPoint = defaultCustomSyncPlayEndPoint;+ String selectedSyncPlayEndPoint = setting.get(+ SettingBoxKey.syncPlayEndPoint,+ defaultValue: defaultSyncPlayEndPoint);++ KazumiDialog.show(+ builder: (context) {+ return StatefulBuilder(builder: (context, setDialogState) {+ List<String> syncPlayEndPoints = [];+ syncPlayEndPoints.addAll(defaultSyncPlayEndPoints);+ syncPlayEndPoints.add(customSyncPlayEndPoint);+ if (!syncPlayEndPoints.contains(selectedSyncPlayEndPoint)) {+ syncPlayEndPoints.add(selectedSyncPlayEndPoint);+ }+ return AlertDialog(+ title: const Text('选择服务器'),+ content: SingleChildScrollView(+ child: ListBody(+ children: <Widget>[+ DropdownButtonFormField<String>(+ decoration: InputDecoration(+ border: OutlineInputBorder(),+ ),+ value: selectedSyncPlayEndPoint,+ items: syncPlayEndPoints.map((String value) {+ return DropdownMenuItem<String>(+ value: value,+ child: Text(+ value,+ overflow: TextOverflow.ellipsis,+ ),+ );+ }).toList(),+ onChanged: (String? newValue) {+ if (newValue != null) {+ if (newValue == defaultCustomSyncPlayEndPoint) {+ final serverTextController = TextEditingController();+ KazumiDialog.show(+ builder: (context) {+ return AlertDialog(+ title: const Text('自定义服务器'),+ content: TextField(+ controller: serverTextController,+ decoration: const InputDecoration(+ hintText: '请输入服务器地址',+ ),+ ),+ actions: <Widget>[+ TextButton(+ child: const Text('取消'),+ onPressed: () {+ KazumiDialog.dismiss();+ },+ ),+ TextButton(+ child: const Text('确认'),+ onPressed: () {+ if (serverTextController+ .text.isNotEmpty &&+ !syncPlayEndPoints.contains(+ serverTextController.text)) {+ KazumiDialog.dismiss();+ setDialogState(() {+ customSyncPlayEndPoint =+ serverTextController.text;+ selectedSyncPlayEndPoint =+ serverTextController.text;+ });+ } else {+ KazumiDialog.showToast(+ message: '服务器地址不能重复或为空');+ }+ },+ ),+ ],+ );+ },+ );+ } else {+ setDialogState(() {+ selectedSyncPlayEndPoint = newValue;+ });+ }+ }+ },+ ),+ ],+ ),+ ),+ actions: <Widget>[+ TextButton(+ child: const Text('取消'),+ onPressed: () {+ KazumiDialog.dismiss();+ },+ ),+ TextButton(+ child: const Text('确认'),+ onPressed: () {+ setting.put(+ SettingBoxKey.syncPlayEndPoint,+ selectedSyncPlayEndPoint,+ );+ KazumiDialog.dismiss();+ },+ ),+ ],+ );+ });+ },+ );+ }+void showSyncPlayRoomCreateDialog() {final formKey = GlobalKey<FormState>();final TextEditingController roomController = TextEditingController();@@ -1093,6 +1214,8 @@ class _PlayerItemState extends State<PlayerItem>showVideoInfo: showVideoInfo,showSyncPlayRoomCreateDialog:showSyncPlayRoomCreateDialog,+ showSyncPlayEndPointSwitchDialog:+ showSyncPlayEndPointSwitchDialog,): SmallestPlayerItemPanel(onBackPressed: widget.onBackPressed,@@ -1111,6 +1234,8 @@ class _PlayerItemState extends State<PlayerItem>showVideoInfo: showVideoInfo,showSyncPlayRoomCreateDialog:showSyncPlayRoomCreateDialog,+ showSyncPlayEndPointSwitchDialog:+ showSyncPlayEndPointSwitchDialog,),// 播放器手势控制Positioned.fill(diff --git a/lib/pages/player/player_item_panel.dart b/lib/pages/player/player_item_panel.dartindex a3bbd4c7..9453737b 100644--- a/lib/pages/player/player_item_panel.dart+++ b/lib/pages/player/player_item_panel.dart@@ -37,6 +37,7 @@ class PlayerItemPanel extends StatefulWidget {required this.handleDanmaku,required this.showVideoInfo,required this.showSyncPlayRoomCreateDialog,+ required this.showSyncPlayEndPointSwitchDialog,});final void Function(BuildContext) onBackPressed;@@ -55,6 +56,7 @@ class PlayerItemPanel extends StatefulWidget {final void Function(String) sendDanmaku;final void Function() showVideoInfo;final void Function() showSyncPlayRoomCreateDialog;+ final void Function() showSyncPlayEndPointSwitchDialog;@overrideState<PlayerItemPanel> createState() => _PlayerItemPanelState();@@ -718,6 +720,16 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {child: Text("加入房间"),),),+ MenuItemButton(+ onPressed: () {+ widget.showSyncPlayEndPointSwitchDialog();+ },+ child: const Padding(+ padding:+ EdgeInsets.fromLTRB(0, 10, 10, 10),+ child: Text("切换服务器"),+ ),+ ),MenuItemButton(onPressed: () async {await playerControllerdiff --git a/lib/pages/player/smallest_player_item_panel.dart b/lib/pages/player/smallest_player_item_panel.dartindex 4f594b58..8ca63a79 100644--- a/lib/pages/player/smallest_player_item_panel.dart+++ b/lib/pages/player/smallest_player_item_panel.dart@@ -34,6 +34,7 @@ class SmallestPlayerItemPanel extends StatefulWidget {required this.handleDanmaku,required this.showVideoInfo,required this.showSyncPlayRoomCreateDialog,+ required this.showSyncPlayEndPointSwitchDialog,});final void Function(BuildContext) onBackPressed;@@ -50,6 +51,7 @@ class SmallestPlayerItemPanel extends StatefulWidget {final void Function() cancelHideTimer;final void Function() showVideoInfo;final void Function() showSyncPlayRoomCreateDialog;+ final void Function() showSyncPlayEndPointSwitchDialog;@overrideState<SmallestPlayerItemPanel> createState() =>@@ -552,6 +554,15 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {child: Text("加入房间"),),),+ MenuItemButton(+ onPressed: () {+ widget.showSyncPlayEndPointSwitchDialog();+ },+ child: const Padding(+ padding: EdgeInsets.fromLTRB(0, 10, 10, 10),+ child: Text("切换服务器"),+ ),+ ),MenuItemButton(onPressed: () async {await playerController.exitSyncPlayRoom();diff --git a/lib/utils/constants.dart b/lib/utils/constants.dartindex 571fbd4e..f468321f 100644--- a/lib/utils/constants.dart+++ b/lib/utils/constants.dart@@ -63,6 +63,17 @@ const List<String> userAgentsList = ['Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0',];+// 默认 SyncPlay 服务器列表+const List<String> defaultSyncPlayEndPoints = [+ 'syncplay.pl:8995',+ 'syncplay.pl:8996',+ 'syncplay.pl:8997',+ 'syncplay.pl:8998',+ 'syncplay.pl:8999',+];++const String defaultSyncPlayEndPoint = 'syncplay.pl:8996';+// 随机HTTP请求头accept-language字段列表const List<String> acceptLanguageList = ['zh-CN,zh;q=0.9',diff --git a/lib/utils/storage.dart b/lib/utils/storage.dartindex 958d8740..ad4cb0a1 100644--- a/lib/utils/storage.dart+++ b/lib/utils/storage.dart@@ -242,5 +242,6 @@ class SettingBoxKey {useDynamicColor = 'useDynamicColor',exitBehavior = 'exitBehavior',playerDebugMode = 'playerDebugMode',+ syncPlayEndPoint = 'syncPlayEndPoint',defaultSuperResolutionType = 'defaultSuperResolutionType';}