mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-23 18:46:53 +08:00
feat: 补全弹幕关键词过滤
This commit is contained in:
@@ -3,10 +3,12 @@ import 'package:PiliPalaX/models/danmaku/dm.pb.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class PlDanmakuController {
|
||||
PlDanmakuController(this.cid, this.danmakuWeightNotifier);
|
||||
PlDanmakuController(this.cid, this.danmakuWeightNotifier, this.danmakuFilterNotifier);
|
||||
final int cid;
|
||||
final ValueNotifier<int> danmakuWeightNotifier;
|
||||
final ValueNotifier<List<Map<String, dynamic>>> danmakuFilterNotifier;
|
||||
int danmakuWeight = 0;
|
||||
List<Map<String, dynamic>> danmakuFilter = [];
|
||||
Map<int, List<DanmakuElem>> dmSegMap = {};
|
||||
// 已请求的段落标记
|
||||
List<bool> requestedSeg = [];
|
||||
@@ -24,6 +26,10 @@ class PlDanmakuController {
|
||||
"danmakuWeight changed from $danmakuWeight to ${danmakuWeightNotifier.value}");
|
||||
danmakuWeight = danmakuWeightNotifier.value;
|
||||
});
|
||||
danmakuFilterNotifier.addListener(() {
|
||||
print("danmakuFilter changed from $danmakuFilter to ${danmakuFilterNotifier.value}");
|
||||
danmakuFilter = danmakuFilterNotifier.value;
|
||||
});
|
||||
if (requestedSeg.isEmpty) {
|
||||
int segCount = (videoDuration / segmentLength).ceil();
|
||||
requestedSeg = List<bool>.generate(segCount, (index) => false);
|
||||
@@ -32,6 +38,9 @@ class PlDanmakuController {
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
danmakuWeightNotifier.removeListener(() {});
|
||||
danmakuFilterNotifier.removeListener(() {});
|
||||
danmakuFilter.clear();
|
||||
dmSegMap.clear();
|
||||
requestedSeg.clear();
|
||||
}
|
||||
@@ -67,13 +76,36 @@ class PlDanmakuController {
|
||||
if (!requestedSeg[segmentIndex]) {
|
||||
queryDanmaku(segmentIndex);
|
||||
}
|
||||
if (danmakuWeight == 0) {
|
||||
if (danmakuWeight == 0 && danmakuFilter.isEmpty) {
|
||||
return dmSegMap[progress ~/ 100];
|
||||
} else {
|
||||
//using filter
|
||||
return dmSegMap[progress ~/ 100]
|
||||
?.where((element) => element.weight >= danmakuWeight)
|
||||
.where(filterDanmaku)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
bool filterDanmaku(DanmakuElem elem) {
|
||||
for (var filter in danmakuFilter) {
|
||||
switch (filter['type']) {
|
||||
case 0:
|
||||
if (elem.content.contains(filter['filter'])) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (RegExp(filter['filter']).hasMatch(elem.content)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (elem.idStr == filter['filter']) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user