基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
fix(dlna): filter non mediaRenderer devices && send title metadata (#2799)
DSplay12360288c33553f
diff --git a/lib/pages/player/player_controller.dart b/lib/pages/player/player_controller.dartindex 26c6b204..32c8a976 100644--- a/lib/pages/player/player_controller.dart+++ b/lib/pages/player/player_controller.dart@@ -84,6 +84,8 @@ class PlayerController implements Disposable {late String referer;String? coverUrl;String videoUrl = '';+ String _bangumiName = '';+ String _episodeTitle = '';bool isLocalPlayback = false;Timer? hideVolumeUITimer;Timer? _volumeGestureSyncTimer;@@ -163,6 +165,13 @@ class PlayerController implements Disposable {unawaited(GStorage.putSetting<double>(SettingsKeys.defaultVolume, clamped));}+ /// Describes [videoUrl], not the episode the page may still be resolving.+ String get mediaTitle {+ final episode =+ _episodeTitle.isNotEmpty ? _episodeTitle : '第 $currentEpisode 集';+ return _bangumiName.isEmpty ? episode : '$_bangumiName · $episode';+ }+Future<bool> init(PlaybackInitParams params) async {if (_initializations.isClosed) {return false;@@ -170,6 +179,8 @@ class PlayerController implements Disposable {final initialization = _initializations.begin();videoUrl = params.videoUrl;+ _bangumiName = params.bangumiName ?? '';+ _episodeTitle = params.episodeTitle.trim();isLocalPlayback = params.isLocalPlayback;bangumiId = params.bangumiId;currentEpisode = params.episode;diff --git a/lib/pages/player/player_item_panel.dart b/lib/pages/player/player_item_panel.dartindex be7a0fd3..a3df3cd2 100644--- a/lib/pages/player/player_item_panel.dart+++ b/lib/pages/player/player_item_panel.dart@@ -916,11 +916,21 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {),KazumiMenuItem(onPressed: () {+ // Renderers fetch the URL themselves: they cannot reach+ // a file on this device or send the rule's Referer.+ if (playerController.isLocalPlayback) {+ KazumiDialog.showToast(message: '暂不支持离线视频');+ return;+ }+ if (playerController.referer.isNotEmpty) {+ KazumiDialog.showToast(message: '暂不支持该规则');+ return;+ }final needRestart = playerController.playback.playing;playerController.pause();RemotePlay().castVideo(playerController.videoUrl,- videoPageController.currentPlugin.referer)+ title: playerController.mediaTitle).whenComplete(() {if (mounted && needRestart) {playerController.play();diff --git a/lib/services/player/remote.dart b/lib/services/player/remote.dartindex 1a8686e4..93f809d8 100644--- a/lib/services/player/remote.dart+++ b/lib/services/player/remote.dart@@ -6,9 +6,11 @@ import 'package:kazumi/bean/dialog/dialog_helper.dart';import 'package:kazumi/services/logging/logger.dart';class RemotePlay {- Future<void> castVideo(String video, String referer) async {+ Future<void> castVideo(String video, {required String title}) async {final searcher = DLNAManager();final dlna = await searcher.start();+ StreamSubscription<Map<String, DLNADevice>>? subscription;+ final loggedDevices = <String>{};List<Widget> dlnaDevice = [];await KazumiDialog.show(builder: (BuildContext context) {return StatefulBuilder(builder: (context, setState) {@@ -32,46 +34,48 @@ class RemotePlay {),TextButton(onPressed: () {- setState(() {});KazumiDialog.showToast(message: '开始搜索',);- dlna.devices.stream.listen((deviceList) {- dlnaDevice = [];- deviceList.forEach((key, value) async {- KazumiLogger().i('RemotePlay: key: $key');- KazumiLogger().i(- 'RemotePlay: value: ${value.info.friendlyName} ${value.info.deviceType} ${value.info.URLBase}');- setState(() {- dlnaDevice.add(ListTile(- leading: _deviceUPnPIcon(- value.info.deviceType.split(':')[3]),- title: Text(value.info.friendlyName),- subtitle: Text(value.info.deviceType.split(':')[3]),- onTap: () {- try {- KazumiDialog.showToast(- message: '尝试投屏至 ${value.info.friendlyName}',- );- DLNADevice(value.info).setUrl(video);- DLNADevice(value.info).play();- } catch (e) {- KazumiLogger().e(- 'RemotePlay: failed to cast to device',- error: e);- KazumiDialog.showToast(- message: 'DLNA 异常: $e \n尝试重新进入 DLNA 投屏或切换设备',- );- }- }));- });+ // The device stream is single-subscription.+ subscription ??= dlna.devices.stream.listen((deviceList) {+ final tiles = <Widget>[];+ deviceList.forEach((key, value) {+ final castable = _supportsAVTransport(value);+ if (loggedDevices.add(key)) {+ KazumiLogger().i(+ 'RemotePlay: found ${value.info.friendlyName} ${value.info.deviceType} ${value.info.URLBase}${castable ? '' : ', skipped without AVTransport'}');+ }+ if (!castable) {+ return;+ }+ final typeName = _deviceTypeName(value.info.deviceType);+ tiles.add(ListTile(+ leading: _deviceUPnPIcon(typeName),+ title: Text(value.info.friendlyName),+ subtitle: Text(typeName),+ onTap: () async {+ try {+ KazumiDialog.showToast(+ message: '尝试投屏至 ${value.info.friendlyName}',+ );+ await value.setUrl(video, title: title);+ await value.play();+ } catch (e) {+ KazumiLogger().e(+ 'RemotePlay: failed to cast to device',+ error: e);+ KazumiDialog.showToast(+ message: 'DLNA 异常: $e \n尝试重新进入 DLNA 投屏或切换设备',+ );+ }+ }));+ });+ // Also rebuild when empty, so pruned devices disappear.+ setState(() {+ dlnaDevice = tiles;});});- // Timer(const Duration(seconds: 30), () {- // KazumiDialog.showToast(- // message: '已搜索30s,若未发现设备请尝试重新进入 DLNA 投屏',- // );- // });},child: Text('搜索',@@ -82,10 +86,22 @@ class RemotePlay {);});}, onDismiss: () {+ subscription?.cancel();searcher.stop();});}+ // DLNADevice.controlURL resolves every cast request through this service.+ bool _supportsAVTransport(DLNADevice device) {+ return device.info.serviceList+ .any((service) => '${service['serviceId']}'.contains('AVTransport'));+ }++ String _deviceTypeName(String deviceType) {+ final parts = deviceType.split(':');+ return parts.length > 3 ? parts[3] : deviceType;+ }+Icon _deviceUPnPIcon(String deviceType) {switch (deviceType) {case 'MediaRenderer':