Skip to content

Commit

Permalink
feat: 新增视频标题本地关键词过滤
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Sep 8, 2024
1 parent 993b92d commit 9710a0c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
63 changes: 63 additions & 0 deletions lib/pages/setting/recommend_setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class _RecommendSettingState extends State<RecommendSetting> {
// late int filterUnfollowedRatio;
late int minDurationForRcmd;
late int minLikeRatioForRecommend;
late String banWordForRecommend;

@override
void initState() {
Expand All @@ -44,6 +45,8 @@ class _RecommendSettingState extends State<RecommendSetting> {
setting.get(SettingBoxKey.minDurationForRcmd, defaultValue: 0);
minLikeRatioForRecommend =
setting.get(SettingBoxKey.minLikeRatioForRecommend, defaultValue: 0);
banWordForRecommend =
setting.get(SettingBoxKey.banWordForRecommend, defaultValue: '');
}

@override
Expand Down Expand Up @@ -144,6 +147,66 @@ class _RecommendSettingState extends State<RecommendSetting> {
}
},
),
ListTile(
dense: false,
leading: const Icon(Icons.title_outlined),
title: Text('标题关键词过滤', style: titleStyle),
subtitle: Text(
banWordForRecommend.isEmpty ? "点击添加" : banWordForRecommend,
style: subTitleStyle,
),
onTap: () async {
final TextEditingController textController =
TextEditingController(text: banWordForRecommend);
await showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('标题关键词过滤'),
content: Column(mainAxisSize: MainAxisSize.min, children: [
const Text('使用空格隔开,如:尝试 测试'),
TextField(
controller: textController,
//decoration: InputDecoration(hintText: hintText),
)
]),
actions: <Widget>[
TextButton(
child: const Text('清空'),
onPressed: () {
textController.text = '';
},
),
TextButton(
child: const Text('取消'),
onPressed: () {
Navigator.of(context).pop();
SmartDialog.showToast('关键词未被修改');
},
),
TextButton(
child: const Text('保存'),
onPressed: () async {
Navigator.of(context).pop();
String filter = textController.text.trim();
banWordForRecommend = filter;
setting.put(SettingBoxKey.banWordForRecommend,
banWordForRecommend);
setState(() {});
RecommendFilter.update();
if (filter.isNotEmpty) {
SmartDialog.showToast('已保存:$banWordForRecommend');
} else {
SmartDialog.showToast('已清除全部关键词');
}
},
),
],
);
},
);
},
),
ListTile(
dense: false,
title: Text('视频时长过滤', style: titleStyle),
Expand Down
7 changes: 7 additions & 0 deletions lib/utils/recommend_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class RecommendFilter {
static late int minLikeRatioForRecommend;
static late bool exemptFilterForFollowed;
static late bool applyFilterToRelatedVideos;
static late List<String> banWordList;
RecommendFilter() {
update();
}
Expand All @@ -20,6 +21,9 @@ class RecommendFilter {
setting.get(SettingBoxKey.minDurationForRcmd, defaultValue: 0);
minLikeRatioForRecommend =
setting.get(SettingBoxKey.minLikeRatioForRecommend, defaultValue: 0);
banWordList = (setting.get(SettingBoxKey.banWordForRecommend,
defaultValue: '') as String)
.split(' ');
exemptFilterForFollowed =
setting.get(SettingBoxKey.exemptFilterForFollowed, defaultValue: true);
applyFilterToRelatedVideos = setting
Expand Down Expand Up @@ -47,6 +51,9 @@ class RecommendFilter {
minLikeRatioForRecommend * videoItem.stat.view) {
return true;
}
for (var word in banWordList) {
if (word.isNotEmpty && videoItem.title.contains(word)) return true;
}
return false;
}
}
1 change: 1 addition & 0 deletions lib/utils/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class SettingBoxKey {
minDurationForRcmd = 'minDurationForRcmd',
minLikeRatioForRecommend = 'minLikeRatioForRecommend',
exemptFilterForFollowed = 'exemptFilterForFollowed',
banWordForRecommend = 'banWordForRecommend',
//filterUnfollowedRatio = 'filterUnfollowedRatio',
applyFilterToRelatedVideos = 'applyFilterToRelatedVideos',

Expand Down

0 comments on commit 9710a0c

Please sign in to comment.