From 4869602457a809cb8e8f19f408027294ba1dd6d6 Mon Sep 17 00:00:00 2001 From: ywmoyue Date: Sat, 1 Jun 2024 11:02:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=B9=E5=B9=95=E7=AD=9B=E9=80=89=E6=8A=9B?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=97=B6=E8=AE=B0=E5=BD=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controls/PlayerControl.xaml.cs | 77 +++++++++++-------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/src/BiliLite.UWP/Controls/PlayerControl.xaml.cs b/src/BiliLite.UWP/Controls/PlayerControl.xaml.cs index 5ffeae35..59c33b3c 100644 --- a/src/BiliLite.UWP/Controls/PlayerControl.xaml.cs +++ b/src/BiliLite.UWP/Controls/PlayerControl.xaml.cs @@ -851,43 +851,51 @@ public void InitializePlayInfo(List playInfos, int index) private List FilterFrostDanmaku(IEnumerable danmakus) { - var needDistinct = DanmuSettingMerge.IsOn; - var level = DanmuSettingShieldLevel.Value; - var max = Convert.ToInt32(DanmuSettingMaxNum.Value); - //云屏蔽 - danmakus = danmakus.Where(x => x.Weight >= level); - //去重 - danmakus = danmakus.DistinctIf(needDistinct, new CompareDanmakuItem()); - - //关键词 - foreach (var item in settingVM.ShieldWords) - { - danmakus = danmakus.Where(x => !x.Text.Contains(item)); - } - //用户 - foreach (var item in settingVM.ShieldUsers) - { - danmakus = danmakus.Where(x => !x.MidHash.Equals(item)); - } - //正则 - foreach (var item in settingVM.ShieldRegulars) + try { - danmakus = danmakus.Where(x => !Regex.IsMatch(x.Text, item)); - } + var needDistinct = DanmuSettingMerge.IsOn; + var level = DanmuSettingShieldLevel.Value; + var max = Convert.ToInt32(DanmuSettingMaxNum.Value); + //云屏蔽 + danmakus = danmakus.Where(x => x.Weight >= level); + //去重 + danmakus = danmakus.DistinctIf(needDistinct, new CompareDanmakuItem()); - // 同屏密度 - if (max > 0) - { - // 弹幕按每秒分组,每组取前x项 - danmakus = danmakus.GroupBy(x => (x.StartMs / 1000) * 1000) - .ToDictionary(x => (int)x.Key, x => x.ToList()) - .SelectMany(x => x.Value.Take(max)); - } + //关键词 + foreach (var item in settingVM.ShieldWords) + { + danmakus = danmakus.Where(x => !x.Text.Contains(item)); + } + //用户 + foreach (var item in settingVM.ShieldUsers) + { + danmakus = danmakus.Where(x => !x.MidHash.Equals(item)); + } + //正则 + foreach (var item in settingVM.ShieldRegulars) + { + danmakus = danmakus.Where(x => !Regex.IsMatch(x.Text, item)); + } + + // 同屏密度 + if (max > 0) + { + // 弹幕按每秒分组,每组取前x项 + danmakus = danmakus.GroupBy(x => (x.StartMs / 1000) * 1000) + .ToDictionary(x => (int)x.Key, x => x.ToList()) + .SelectMany(x => x.Value.Take(max)); + } - // 移除当前播放时间之前的弹幕,避免弹幕堆叠 - danmakus = danmakus.Where(x => x.StartMs > Player.Position * 1000); + // 移除当前播放时间之前的弹幕,避免弹幕堆叠 + danmakus = danmakus.Where(x => x.StartMs > Player.Position * 1000); - return danmakus.ToList(); + return danmakus.ToList(); + } + catch (Exception ex) + { + _logger.Error("弹幕筛选错误:" + ex.Message, ex); + return new List(); + } } private async Task SelectNsDanmakuAndLoad(int position, double level, bool needDistinct, int max) @@ -929,8 +937,9 @@ private async Task SelectNsDanmakuAndLoad(int position, double level, bool needD data = null; } } - catch (Exception) + catch (Exception ex) { + _logger.Error("弹幕筛选错误:" + ex.Message, ex); } }