feat: filter hot/rank video title

Closes #38

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-12-19 21:32:18 +08:00
parent a7ffc3b05f
commit 6f5bd626b4
3 changed files with 45 additions and 36 deletions

View File

@@ -171,7 +171,8 @@ class VideoHttp {
List<HotVideoItemModel> list = [];
List<int> blackMidsList = GStorage.blackMidsList;
for (var i in res.data['data']['list']) {
if (!blackMidsList.contains(i['owner']['mid'])) {
if (!blackMidsList.contains(i['owner']['mid']) &&
!RecommendFilter.filterTitle(i['title'])) {
list.add(HotVideoItemModel.fromJson(i));
}
}
@@ -978,7 +979,8 @@ class VideoHttp {
List<HotVideoItemModel> list = [];
List<int> blackMidsList = GStorage.blackMidsList;
for (var i in res.data['data']['list']) {
if (!blackMidsList.contains(i['owner']['mid'])) {
if (!blackMidsList.contains(i['owner']['mid']) &&
!RecommendFilter.filterTitle(i['title'])) {
list.add(HotVideoItemModel.fromJson(i));
}
}

View File

@@ -155,43 +155,42 @@ class _RecommendSettingState extends State<RecommendSetting> {
context: context,
builder: (context) {
return AlertDialog(
title: const Text('标题关键词过滤'),
content: Column(mainAxisSize: MainAxisSize.min, children: [
const Text('使用空格隔开,如:尝试 测试'),
TextField(
controller: textController,
//decoration: InputDecoration(hintText: hintText),
)
]),
title: const Text(
'标题关键词过滤',
style: TextStyle(fontSize: 18),
),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('使用|隔开,如:尝试|测试'),
TextField(
controller: textController,
textInputAction: TextInputAction.newline,
minLines: 1,
maxLines: 4,
)
],
),
actions: <Widget>[
TextButton(
child: const Text('清空'),
onPressed: () {
textController.text = '';
},
),
TextButton(
child: const Text('取消'),
onPressed: () {
Navigator.of(context).pop();
SmartDialog.showToast('关键词未被修改');
},
onPressed: Get.back,
child: Text(
'取消',
style: TextStyle(
color: Theme.of(context).colorScheme.outline),
),
),
TextButton(
child: const Text('保存'),
onPressed: () async {
Navigator.of(context).pop();
String filter = textController.text.trim();
banWordForRecommend = filter;
Get.back();
banWordForRecommend = textController.text;
setting.put(SettingBoxKey.banWordForRecommend,
banWordForRecommend);
setState(() {});
RecommendFilter.update();
if (filter.isNotEmpty) {
SmartDialog.showToast('已保存:$banWordForRecommend');
} else {
SmartDialog.showToast('已清除全部关键词');
}
SmartDialog.showToast('已保存');
},
),
],
@@ -285,7 +284,7 @@ class _RecommendSettingState extends State<RecommendSetting> {
},
),
SetSwitchItem(
title: '已关注Up豁免推荐过滤',
title: '已关注UP豁免推荐过滤',
subTitle: '推荐中已关注用户发布的内容不会被过滤',
leading: const Icon(Icons.favorite_border_outlined),
setKey: SettingBoxKey.exemptFilterForFollowed,

View File

@@ -8,7 +8,7 @@ class RecommendFilter {
static late int minLikeRatioForRecommend;
static late bool exemptFilterForFollowed;
static late bool applyFilterToRelatedVideos;
static late List<String> banWordList;
static late String banWords;
RecommendFilter() {
update();
}
@@ -21,9 +21,7 @@ class RecommendFilter {
setting.get(SettingBoxKey.minDurationForRcmd, defaultValue: 0);
minLikeRatioForRecommend =
setting.get(SettingBoxKey.minLikeRatioForRecommend, defaultValue: 0);
banWordList = (setting.get(SettingBoxKey.banWordForRecommend,
defaultValue: '') as String)
.split(' ');
banWords = setting.get(SettingBoxKey.banWordForRecommend, defaultValue: '');
exemptFilterForFollowed =
setting.get(SettingBoxKey.exemptFilterForFollowed, defaultValue: true);
applyFilterToRelatedVideos = setting
@@ -51,8 +49,18 @@ class RecommendFilter {
minLikeRatioForRecommend * videoItem.stat.view) {
return true;
}
for (var word in banWordList) {
if (word.isNotEmpty && videoItem.title.contains(word)) return true;
if (filterTitle(videoItem.title)) {
return true;
}
return false;
}
static bool filterTitle(String title, {bool? isFollowed}) {
if (exemptFilterForFollowed && isFollowed == true) {
return false;
}
if (banWords.isNotEmpty && RegExp(banWords).hasMatch(title)) {
return true;
}
return false;
}