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<HotVideoItemModel> list = [];
List<int> blackMidsList = GStorage.blackMidsList; List<int> blackMidsList = GStorage.blackMidsList;
for (var i in res.data['data']['list']) { 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)); list.add(HotVideoItemModel.fromJson(i));
} }
} }
@@ -978,7 +979,8 @@ class VideoHttp {
List<HotVideoItemModel> list = []; List<HotVideoItemModel> list = [];
List<int> blackMidsList = GStorage.blackMidsList; List<int> blackMidsList = GStorage.blackMidsList;
for (var i in res.data['data']['list']) { 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)); list.add(HotVideoItemModel.fromJson(i));
} }
} }

View File

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

View File

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