Skip to content

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

feat(danmaku): add timeline offset setting and refactor danmaku emission

Predidite0aa8d04b46f
diff --git a/lib/modules/danmaku/danmaku_module.dart b/lib/modules/danmaku/danmaku_module.dart
index c8f0a22d..59a6a6cb 100644
--- a/lib/modules/danmaku/danmaku_module.dart
+++ b/lib/modules/danmaku/danmaku_module.dart
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:kazumi/utils/utils.dart';
-class Danmaku {
+class DanmakuEntry {
// 弹幕内容
String message;
// 弹幕时间
@@ -13,27 +13,37 @@ class Danmaku {
// 弹幕来源 ([BiliBili], [Gamer])
String source;
- Danmaku({required this.message, required this.time, required this.type, required this.color, required this.source});
+ DanmakuEntry(
+ {required this.message,
+ required this.time,
+ required this.type,
+ required this.color,
+ required this.source});
- factory Danmaku.fromJson(Map<String, dynamic> json) {
+ factory DanmakuEntry.fromJson(Map<String, dynamic> json) {
String messageValue = json['m'];
List<String> parts = json['p'].split(',');
double timeValue = double.parse(parts[0]);
int typeValue = int.parse(parts[1]);
Color color = Utils.generateDanmakuColor(int.parse(parts[2]));
String sourceValue = parts[3];
- return Danmaku(time: timeValue, message: messageValue, type: typeValue, color: color, source: sourceValue);
+ return DanmakuEntry(
+ time: timeValue,
+ message: messageValue,
+ type: typeValue,
+ color: color,
+ source: sourceValue);
}
/// 序列化为 JSON 格式 (与 fromJson 格式一致)
Map<String, dynamic> toJson() {
// 只存储 RGB 部分 (与 DanDanPlay API 格式一致)
final colorValue = ((color.r * 255).toInt() << 16) |
- ((color.g * 255).toInt() << 8) |
- (color.b * 255).toInt();
+ ((color.g * 255).toInt() << 8) |
+ (color.b * 255).toInt();
return {
'm': message,
'p': '$time,$type,$colorValue,$source',
};
}
-}
\ No newline at end of file
+}
diff --git a/lib/pages/download/download_controller.dart b/lib/pages/download/download_controller.dart
index 35fe034a..8ebf2ce3 100644
--- a/lib/pages/download/download_controller.dart
+++ b/lib/pages/download/download_controller.dart
@@ -79,7 +79,7 @@ abstract class _DownloadController with Store {
}
try {
// danmakuData 已经是弹幕数组的 JSON 字符串,直接拼接成新格式写入
- // 避免 jsonDecode → Danmaku.fromJson × N → toJson × N → jsonEncode 的开销
+ // 避免 jsonDecode → DanmakuEntry.fromJson × N → toJson × N → jsonEncode 的开销
final file = File(_danmakuFilePath(episode.downloadDirectory));
await file.writeAsString(
'{"danDanBangumiID":${episode.danDanBangumiID},"danmakus":${episode.danmakuData}}');
@@ -345,8 +345,8 @@ abstract class _DownloadController with Store {
/// 从文件读取弹幕数据
/// 支持新格式 (带 danDanBangumiID 的 wrapper) 和旧格式 (纯数组)
- Future<({List<Danmaku> danmakus, int danDanBangumiID})?> _readDanmakuFromFile(
- String downloadDirectory) async {
+ Future<({List<DanmakuEntry> danmakus, int danDanBangumiID})?>
+ _readDanmakuFromFile(String downloadDirectory) async {
if (downloadDirectory.isEmpty) return null;
final file = File(_danmakuFilePath(downloadDirectory));
if (!await file.exists()) return null;
@@ -355,14 +355,15 @@ abstract class _DownloadController with Store {
final decoded = jsonDecode(content);
if (decoded is List) {
// 旧格式:纯弹幕数组
- final danmakus = decoded.map((json) => Danmaku.fromJson(json)).toList();
+ final danmakus =
+ decoded.map((json) => DanmakuEntry.fromJson(json)).toList();
return (danmakus: danmakus, danDanBangumiID: 0);
} else if (decoded is Map<String, dynamic>) {
// 新格式:带 danDanBangumiID 的 wrapper
final danDanBangumiID = decoded['danDanBangumiID'] as int? ?? 0;
final List<dynamic> jsonList = decoded['danmakus'] as List? ?? [];
final danmakus =
- jsonList.map((json) => Danmaku.fromJson(json)).toList();
+ jsonList.map((json) => DanmakuEntry.fromJson(json)).toList();
return (danmakus: danmakus, danDanBangumiID: danDanBangumiID);
}
return null;
@@ -375,7 +376,7 @@ abstract class _DownloadController with Store {
/// 写入弹幕数据到文件 (新格式,包含 danDanBangumiID)
Future<void> _writeDanmakuToFile(String downloadDirectory,
- List<Danmaku> danmakus, int danDanBangumiID) async {
+ List<DanmakuEntry> danmakus, int danDanBangumiID) async {
if (downloadDirectory.isEmpty) return;
final file = File(_danmakuFilePath(downloadDirectory));
final wrapper = {
@@ -385,7 +386,7 @@ abstract class _DownloadController with Store {
await file.writeAsString(jsonEncode(wrapper));
}
- Future<List<Danmaku>?> getCachedDanmakus(
+ Future<List<DanmakuEntry>?> getCachedDanmakus(
int bangumiId, String pluginName, int episodeNumber) async {
final episode =
_repository.getEpisode(bangumiId, pluginName, episodeNumber);
@@ -404,7 +405,7 @@ abstract class _DownloadController with Store {
int bangumiId,
String pluginName,
int episodeNumber,
- List<Danmaku> danmakus,
+ List<DanmakuEntry> danmakus,
int danDanBangumiID,
) async {
final recordKey = '${pluginName}_$bangumiId';
diff --git a/lib/pages/player/controller/player_danmaku_controller.dart b/lib/pages/player/controller/player_danmaku_controller.dart
index d89ea273..c340e3b8 100644
--- a/lib/pages/player/controller/player_danmaku_controller.dart
+++ b/lib/pages/player/controller/player_danmaku_controller.dart
@@ -23,10 +23,34 @@ class DanmakuLoadResult {
required this.bangumiID,
});
- final List<Danmaku> danmakus;
+ final List<DanmakuEntry> danmakus;
final int bangumiID;
}
+class DanmakuTimeline {
+ static int? resolveSourceSecond(
+ Duration playbackPosition,
+ double timelineOffsetSeconds,
+ ) {
+ final sourceMilliseconds = playbackPosition.inMilliseconds -
+ (timelineOffsetSeconds * 1000).round();
+ if (sourceMilliseconds < 0) {
+ return null;
+ }
+ return Duration(milliseconds: sourceMilliseconds).inSeconds;
+ }
+
+ static int staggerDelayMilliseconds({
+ required int index,
+ required int total,
+ }) {
+ if (total <= 0) {
+ return 0;
+ }
+ return index * 1000 ~/ total;
+ }
+}
+
abstract class _PlayerDanmakuController with Store {
_PlayerDanmakuController({
required this.setting,
@@ -39,7 +63,7 @@ abstract class _PlayerDanmakuController with Store {
late canvas.DanmakuController canvasController;
@observable
- Map<int, List<Danmaku>> danDanmakus = {};
+ Map<int, List<DanmakuEntry>> danDanmakus = {};
@observable
bool danmakuOn = false;
@observable
@@ -47,6 +71,35 @@ abstract class _PlayerDanmakuController with Store {
DanmakuDestination danmakuDestination = DanmakuDestination.remoteDanmaku;
int bangumiID = 0;
+ int _scheduledDanmakuGeneration = 0;
+
+ int get scheduledDanmakuGeneration => _scheduledDanmakuGeneration;
+
+ double get timelineOffsetSeconds {
+ final offset =
+ setting.get(SettingBoxKey.danmakuTimeOffset, defaultValue: 0.0);
+ return offset is num ? offset.toDouble() : 0.0;
+ }
+
+ int? resolveDanmakuSecond(Duration playbackPosition) {
+ return DanmakuTimeline.resolveSourceSecond(
+ playbackPosition,
+ timelineOffsetSeconds,
+ );
+ }
+
+ List<DanmakuEntry> danmakusForPlaybackPosition(Duration playbackPosition) {
+ final danmakuSecond = resolveDanmakuSecond(playbackPosition);
+ if (danmakuSecond == null) {
+ return const [];
+ }
+ return danDanmakus[danmakuSecond] ?? const [];
+ }
+
+ void clearAndInvalidateScheduledDanmakus() {
+ _scheduledDanmakuGeneration++;
+ canvasController.clear();
+ }
// Fetching must not mutate current danmaku state; VideoPageController applies
// the result only after confirming the playback session is still current.
@@ -135,8 +188,13 @@ abstract class _PlayerDanmakuController with Store {
return DanmakuLoadResult(danmakus: const [], bangumiID: nextBangumiID);
}
- void _saveDanmakuToCache(DownloadController downloadController, int bangumiId,
- String pluginName, int episode, List<Danmaku> danmakus, int danDanID) {
+ void _saveDanmakuToCache(
+ DownloadController downloadController,
+ int bangumiId,
+ String pluginName,
+ int episode,
+ List<DanmakuEntry> danmakus,
+ int danDanID) {
try {
downloadController.updateCachedDanmakus(
bangumiId,
@@ -185,11 +243,11 @@ abstract class _PlayerDanmakuController with Store {
}
}
- void addDanmakus(List<Danmaku> danmakus) {
+ void addDanmakus(List<DanmakuEntry> danmakus) {
final bool danmakuDeduplicationEnable =
setting.get(SettingBoxKey.danmakuDeduplication, defaultValue: false);
- final List<Danmaku> listToAdd = danmakuDeduplicationEnable
+ final List<DanmakuEntry> listToAdd = danmakuDeduplicationEnable
? Utils.mergeDuplicateDanmakus(danmakus, timeWindowSeconds: 5)
: danmakus;
diff --git a/lib/pages/player/controller/player_danmaku_controller.g.dart b/lib/pages/player/controller/player_danmaku_controller.g.dart
index c190438f..dc842c46 100644
--- a/lib/pages/player/controller/player_danmaku_controller.g.dart
+++ b/lib/pages/player/controller/player_danmaku_controller.g.dart
@@ -13,13 +13,13 @@ mixin _$PlayerDanmakuController on _PlayerDanmakuController, Store {
Atom(name: '_PlayerDanmakuController.danDanmakus', context: context);
@override
- Map<int, List<Danmaku>> get danDanmakus {
+ Map<int, List<DanmakuEntry>> get danDanmakus {
_$danDanmakusAtom.reportRead();
return super.danDanmakus;
}
@override
- set danDanmakus(Map<int, List<Danmaku>> value) {
+ set danDanmakus(Map<int, List<DanmakuEntry>> value) {
_$danDanmakusAtom.reportWrite(value, super.danDanmakus, () {
super.danDanmakus = value;
});
diff --git a/lib/pages/player/player_item.dart b/lib/pages/player/player_item.dart
index 8f78b170..afdb7f8b 100644
--- a/lib/pages/player/player_item.dart
+++ b/lib/pages/player/player_item.dart
@@ -27,6 +27,8 @@ import 'package:kazumi/utils/storage.dart';
import 'package:kazumi/request/apis/danmaku_api.dart';
import 'package:kazumi/modules/danmaku/danmaku_search_response.dart';
import 'package:kazumi/modules/danmaku/danmaku_episode_response.dart';
+import 'package:kazumi/modules/danmaku/danmaku_module.dart';
+import 'package:kazumi/pages/player/controller/player_danmaku_controller.dart';
import 'package:kazumi/pages/player/player_item_surface.dart';
import 'package:mobx/mobx.dart' as mobx;
import 'package:kazumi/pages/my/my_controller.dart';
@@ -868,58 +870,82 @@ class _PlayerItemState extends State<PlayerItem>
hideTimer = null;
}
+ bool _isDanmakuSourceEnabled(DanmakuEntry danmaku) {
+ if (!_danmakuBiliBiliSource && danmaku.source.contains('BiliBili')) {
+ return false;
+ }
+ if (!_danmakuGamerSource && danmaku.source.contains('Gamer')) {
+ return false;
+ }
+ if (!_danmakuDanDanSource &&
+ !(danmaku.source.contains('BiliBili') ||
+ danmaku.source.contains('Gamer'))) {
+ return false;
+ }
+ return true;
+ }
+
+ DanmakuItemType _danmakuItemType(DanmakuEntry danmaku) {
+ if (danmaku.type == 4) {
+ return DanmakuItemType.bottom;
+ }
+ if (danmaku.type == 5) {
+ return DanmakuItemType.top;
+ }
+ return DanmakuItemType.scroll;
+ }
+
+ void _emitDanmakusForCurrentPosition() {
+ if (playerController.playback.currentPosition.inMicroseconds == 0 ||
+ playerController.playback.playerPlaying != true ||
+ playerController.danmaku.danmakuOn != true) {
+ return;
+ }
+
+ final danmakus = playerController.danmaku
+ .danmakusForPlaybackPosition(playerController.playback.currentPosition);
+ final danmakuCount = danmakus.length;
+ for (final entry in danmakus.asMap().entries) {
+ final idx = entry.key;
+ final danmaku = entry.value;
+ if (!_isDanmakuSourceEnabled(danmaku)) {
+ continue;
+ }
+
+ final color = _danmakuColor ? danmaku.color : Colors.white;
+ final delay = DanmakuTimeline.staggerDelayMilliseconds(
+ index: idx,
+ total: danmakuCount,
+ );
+ final scheduledDanmakuGeneration =
+ playerController.danmaku.scheduledDanmakuGeneration;
+ Future.delayed(Duration(milliseconds: delay), () {
+ if (!mounted ||
+ !playerController.playback.playerPlaying ||
+ playerController.playback.playerBuffering ||
+ !playerController.danmaku.danmakuOn ||
+ playerController.danmaku.scheduledDanmakuGeneration !=
+ scheduledDanmakuGeneration ||
+ myController.isDanmakuBlocked(danmaku.message)) {
+ return;
+ }
+ playerController.danmaku.canvasController.addDanmaku(
+ DanmakuContentItem(
+ danmaku.message,
+ color: color,
+ type: _danmakuItemType(danmaku),
+ ),
+ );
+ });
+ }
+ }
+
Timer getPlayerTimer() {
return Timer.periodic(const Duration(seconds: 1), (timer) {
playerController.syncPlaybackState();
unawaited(_updateAndroidPIPActions());
_syncAudioServiceState();
- // 弹幕相关
- if (playerController.playback.currentPosition.inMicroseconds != 0 &&
- playerController.playback.playerPlaying == true &&
- playerController.danmaku.danmakuOn == true) {
- playerController.danmaku
- .danDanmakus[playerController.playback.currentPosition.inSeconds]
- ?.asMap()
- .forEach((idx, danmaku) async {
- if (!_danmakuColor) {
- danmaku.color = Colors.white;
- }
- if (!_danmakuBiliBiliSource && danmaku.source.contains('BiliBili')) {
- return;
- }
- if (!_danmakuGamerSource && danmaku.source.contains('Gamer')) {
- return;
- }
- if (!_danmakuDanDanSource &&
- !(danmaku.source.contains('BiliBili') ||
- danmaku.source.contains('Gamer'))) {
- return;
- }
- await Future.delayed(
- Duration(
- milliseconds: idx *
- 1000 ~/
- playerController
- .danmaku
- .danDanmakus[playerController
- .playback.currentPosition.inSeconds]!
- .length),
- () => mounted &&
- playerController.playback.playerPlaying &&
- !playerController.playback.playerBuffering &&
- playerController.danmaku.danmakuOn &&
- !myController.isDanmakuBlocked(danmaku.message)
- ? playerController.danmaku.canvasController.addDanmaku(
- DanmakuContentItem(danmaku.message,
- color: danmaku.color,
- type: danmaku.type == 4
- ? DanmakuItemType.bottom
- : (danmaku.type == 5
- ? DanmakuItemType.top
- : DanmakuItemType.scroll)))
- : null);
- });
- }
+ _emitDanmakusForCurrentPosition();
// 音量相关
if (!playerController.panel.volumeSeeking) {
if (Utils.isDesktop()) {
diff --git a/lib/pages/player/player_item_panel.dart b/lib/pages/player/player_item_panel.dart
index 12200dc7..82e912f4 100644
--- a/lib/pages/player/player_item_panel.dart
+++ b/lib/pages/player/player_item_panel.dart
@@ -816,6 +816,9 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
onUpdateDanmakuSpeed:
playerController
.updateDanmakuSpeed,
+ onTimelineOffsetChanged:
+ playerController.danmaku
+ .clearAndInvalidateScheduledDanmakus,
);
});
},
@@ -867,6 +870,9 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
.danmaku.canvasController,
onUpdateDanmakuSpeed:
playerController.updateDanmakuSpeed,
+ onTimelineOffsetChanged: playerController
+ .danmaku
+ .clearAndInvalidateScheduledDanmakus,
);
});
},
diff --git a/lib/pages/player/smallest_player_item_panel.dart b/lib/pages/player/smallest_player_item_panel.dart
index 2fc68a2c..e99e1990 100644
--- a/lib/pages/player/smallest_player_item_panel.dart
+++ b/lib/pages/player/smallest_player_item_panel.dart
@@ -850,6 +850,8 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {
playerController.danmaku.canvasController,
onUpdateDanmakuSpeed:
playerController.updateDanmakuSpeed,
+ onTimelineOffsetChanged: playerController
+ .danmaku.clearAndInvalidateScheduledDanmakus,
);
},
);
diff --git a/lib/pages/settings/danmaku/danmaku_settings_sheet.dart b/lib/pages/settings/danmaku/danmaku_settings_sheet.dart
index a9286e4d..80643fcd 100644
--- a/lib/pages/settings/danmaku/danmaku_settings_sheet.dart
+++ b/lib/pages/settings/danmaku/danmaku_settings_sheet.dart
@@ -9,11 +9,13 @@ import 'package:card_settings_ui/card_settings_ui.dart';
class DanmakuSettingsSheet extends StatefulWidget {
final DanmakuController danmakuController;
final VoidCallback? onUpdateDanmakuSpeed;
+ final VoidCallback? onTimelineOffsetChanged;
const DanmakuSettingsSheet({
super.key,
required this.danmakuController,
this.onUpdateDanmakuSpeed,
+ this.onTimelineOffsetChanged,
});
@override
@@ -22,6 +24,30 @@ class DanmakuSettingsSheet extends StatefulWidget {
class _DanmakuSettingsSheetState extends State<DanmakuSettingsSheet> {
Box setting = GStorage.setting;
+ late double _danmakuTimeOffset;
+
+ double _readDanmakuTimeOffset() {
+ final offset =
+ setting.get(SettingBoxKey.danmakuTimeOffset, defaultValue: 0.0);
+ if (offset is num) {
+ return offset.toDouble().clamp(-60.0, 60.0).toDouble();
+ }
+ return 0.0;
+ }
+
+ String _formatDanmakuTimeOffset(double value) {
+ if (value == 0) {
+ return '无偏移';
+ }
+ final direction = value > 0 ? '延后' : '提前';
+ return '$direction ${value.abs().toStringAsFixed(1)} 秒';
+ }
+
+ @override
+ void initState() {
+ super.initState();
+ _danmakuTimeOffset = _readDanmakuTimeOffset();
+ }
void showDanmakuShieldSheet() {
showModalBottomSheet(
@@ -36,7 +62,7 @@ class _DanmakuSettingsSheetState extends State<DanmakuSettingsSheet> {
builder: (context) {
return SafeArea(
bottom: false,
- child: DanmakuShieldSettingsSheet(),
+ child: DanmakuShieldSettingsSheet(),
);
});
}
@@ -105,6 +131,24 @@ class _DanmakuSettingsSheetState extends State<DanmakuSettingsSheet> {
SettingsSection(
title: Text('弹幕显示', style: TextStyle(fontFamily: fontFamily)),
tiles: [
+ SettingsTile(
+ title: Text('时间轴偏移', style: TextStyle(fontFamily: fontFamily)),
+ description: Slider(
+ value: _danmakuTimeOffset,
+ min: -60,
+ max: 60,
+ divisions: 240,
+ label: _formatDanmakuTimeOffset(_danmakuTimeOffset),
+ onChanged: (value) {
+ final offset = double.parse(value.toStringAsFixed(1));
+ setState(() {
+ _danmakuTimeOffset = offset;
+ });
+ setting.put(SettingBoxKey.danmakuTimeOffset, offset);
+ widget.onTimelineOffsetChanged?.call();
+ },
+ ),
+ ),
SettingsTile(
title: Text('弹幕区域', style: TextStyle(fontFamily: fontFamily)),
description: Slider(
@@ -124,21 +168,22 @@ class _DanmakuSettingsSheetState extends State<DanmakuSettingsSheet> {
},
),
),
- SettingsTile(title: Text('持续时间', style: TextStyle(fontFamily: fontFamily)),
+ SettingsTile(
+ title: Text('持续时间', style: TextStyle(fontFamily: fontFamily)),
description: Slider(
value: widget.danmakuController.option.duration.toDouble(),
min: 2,
max: 16,
divisions: 14,
- label:
- '${widget.danmakuController.option.duration.round()}',
+ label: '${widget.danmakuController.option.duration.round()}',
onChanged: (value) {
setState(() => widget.danmakuController.updateOption(
widget.danmakuController.option.copyWith(
duration: value,
),
));
- setting.put(SettingBoxKey.danmakuDuration, value.round().toDouble());
+ setting.put(SettingBoxKey.danmakuDuration,
+ value.round().toDouble());
},
),
),
@@ -149,14 +194,16 @@ class _DanmakuSettingsSheetState extends State<DanmakuSettingsSheet> {
min: 0,
max: 3,
divisions: 30,
- label: widget.danmakuController.option.lineHeight.toStringAsFixed(1),
+ label: widget.danmakuController.option.lineHeight
+ .toStringAsFixed(1),
onChanged: (value) {
setState(() => widget.danmakuController.updateOption(
widget.danmakuController.option.copyWith(
lineHeight: double.parse(value.toStringAsFixed(1)),
),
));
- setting.put(SettingBoxKey.danmakuLineHeight, double.parse(value.toStringAsFixed(1)));
+ setting.put(SettingBoxKey.danmakuLineHeight,
+ double.parse(value.toStringAsFixed(1)));
},
),
),
@@ -175,7 +222,8 @@ class _DanmakuSettingsSheetState extends State<DanmakuSettingsSheet> {
),
SettingsTile.switchTile(
onToggle: (value) async {
- bool show = value ?? widget.danmakuController.option.hideBottom;
+ bool show =
+ value ?? widget.danmakuController.option.hideBottom;
setState(() => widget.danmakuController.updateOption(
widget.danmakuController.option.copyWith(
hideBottom: !show,
@@ -188,7 +236,8 @@ class _DanmakuSettingsSheetState extends State<DanmakuSettingsSheet> {
),
SettingsTile.switchTile(
onToggle: (value) async {
- bool show = value ?? widget.danmakuController.option.hideScroll;
+ bool show =
+ value ?? widget.danmakuController.option.hideScroll;
setState(() => widget.danmakuController.updateOption(
widget.danmakuController.option.copyWith(
hideScroll: !show,
@@ -201,14 +250,18 @@ class _DanmakuSettingsSheetState extends State<DanmakuSettingsSheet> {
),
SettingsTile.switchTile(
onToggle: (value) async {
- bool followSpeed = value ?? !setting.get(SettingBoxKey.danmakuFollowSpeed, defaultValue: true);
+ bool followSpeed = value ??
+ !setting.get(SettingBoxKey.danmakuFollowSpeed,
+ defaultValue: true);
setting.put(SettingBoxKey.danmakuFollowSpeed, followSpeed);
widget.onUpdateDanmakuSpeed?.call();
setState(() {});
},
title: Text('跟随视频倍速', style: TextStyle(fontFamily: fontFamily)),
- description: Text('弹幕速度随视频倍速变化', style: TextStyle(fontFamily: fontFamily)),
- initialValue: setting.get(SettingBoxKey.danmakuFollowSpeed, defaultValue: true),
+ description: Text('弹幕速度随视频倍速变化',
+ style: TextStyle(fontFamily: fontFamily)),
+ initialValue: setting.get(SettingBoxKey.danmakuFollowSpeed,
+ defaultValue: true),
),
],
),
diff --git a/lib/request/apis/danmaku_api.dart b/lib/request/apis/danmaku_api.dart
index 20b29abe..16a5464b 100644
--- a/lib/request/apis/danmaku_api.dart
+++ b/lib/request/apis/danmaku_api.dart
@@ -90,8 +90,9 @@ class DanmakuApi {
return danmakuSearchResponse;
}
- static Future<List<Danmaku>> getDanDanmaku(int bangumiID, int episode) async {
- List<Danmaku> danmakus = [];
+ static Future<List<DanmakuEntry>> getDanDanmaku(
+ int bangumiID, int episode) async {
+ List<DanmakuEntry> danmakus = [];
if (bangumiID == 0) {
return danmakus;
}
@@ -108,16 +109,17 @@ class DanmakuApi {
List<dynamic> comments = jsonData['comments'];
for (var comment in comments) {
- Danmaku danmaku = Danmaku.fromJson(comment);
+ DanmakuEntry danmaku = DanmakuEntry.fromJson(comment);
danmakus.add(danmaku);
}
return danmakus;
}
- static Future<List<Danmaku>> getDanDanmakuByEpisodeID(int episodeID) async {
+ static Future<List<DanmakuEntry>> getDanDanmakuByEpisodeID(
+ int episodeID) async {
var path = ApiEndpoints.dandanAPIComment + episodeID.toString();
var endPoint = ApiEndpoints.dandanAPIDomain + path;
- List<Danmaku> danmakus = [];
+ List<DanmakuEntry> danmakus = [];
Map<String, String> withRelated = {
'withRelated': 'true',
};
@@ -125,7 +127,7 @@ class DanmakuApi {
List<dynamic> comments = jsonData['comments'];
for (var comment in comments) {
- Danmaku danmaku = Danmaku.fromJson(comment);
+ DanmakuEntry danmaku = DanmakuEntry.fromJson(comment);
danmakus.add(danmaku);
}
return danmakus;
diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart
index 0b000b32..c9407400 100644
--- a/lib/utils/storage.dart
+++ b/lib/utils/storage.dart
@@ -356,6 +356,7 @@ class SettingBoxKey {
danmakuColor = 'danmakuColor',
danmakuDuration = 'danmakuDuration',
danmakuLineHeight = 'danmakuLineHeight',
+ danmakuTimeOffset = 'danmakuTimeOffset',
danmakuEnabledByDefault = 'danmakuEnabledByDefault',
danmakuBiliBiliSource = 'danmakuBiliBiliSource',
danmakuGamerSource = 'danmakuGamerSource',
diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart
index 857ea76d..cb58714a 100644
--- a/lib/utils/utils.dart
+++ b/lib/utils/utils.dart
@@ -310,11 +310,11 @@ class Utils {
return color;
}
- static List<Danmaku> mergeDuplicateDanmakus(
- List<Danmaku> danmakus, {
+ static List<DanmakuEntry> mergeDuplicateDanmakus(
+ List<DanmakuEntry> danmakus, {
double timeWindowSeconds = 0,
}) {
- final Map<String, List<Danmaku>> grouped = {};
+ final Map<String, List<DanmakuEntry>> grouped = {};
// 弹幕规范化处理
// 去首尾空格并小写,全角转半角,去掉所有空白、标点符号,连续重复内容压缩,保留日语字符
@@ -354,7 +354,7 @@ class Utils {
grouped[text]!.add(d);
}
- final List<Danmaku> result = [];
+ final List<DanmakuEntry> result = [];
grouped.forEach((normalized, list) {
if (list.isEmpty) return;
@@ -364,7 +364,7 @@ class Utils {
result.add(list.first);
} else {
result.add(
- Danmaku(
+ DanmakuEntry(
message: '${list.first.message} x${list.length}',
time: list.first.time, // 默认取第一条
type: 5,
@@ -378,7 +378,7 @@ class Utils {
list.sort((a, b) => a.time.compareTo(b.time));
- List<Danmaku> currentGroup = [];
+ List<DanmakuEntry> currentGroup = [];
for (var item in list) {
if (currentGroup.isEmpty) {
currentGroup.add(item);
@@ -392,7 +392,7 @@ class Utils {
result.add(currentGroup.first);
} else {
result.add(
- Danmaku(
+ DanmakuEntry(
message:
'${currentGroup.first.message} x${currentGroup.length}',
time: currentGroup.first.time,
@@ -411,7 +411,7 @@ class Utils {
result.add(currentGroup.first);
} else {
result.add(
- Danmaku(
+ DanmakuEntry(
message: '${currentGroup.first.message} x${currentGroup.length}',
time: currentGroup.first.time,
type: 5,