Skip to content

Commit

Permalink
弹幕筛选抛异常时记录日志
Browse files Browse the repository at this point in the history
  • Loading branch information
ywmoyue committed Jun 1, 2024
1 parent dc9baa7 commit 4869602
Showing 1 changed file with 43 additions and 34 deletions.
77 changes: 43 additions & 34 deletions src/BiliLite.UWP/Controls/PlayerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -851,43 +851,51 @@ public void InitializePlayInfo(List<PlayInfo> playInfos, int index)

private List<DanmakuItem> FilterFrostDanmaku(IEnumerable<DanmakuItem> 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<DanmakuItem>();
}
}

private async Task SelectNsDanmakuAndLoad(int position, double level, bool needDistinct, int max)
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 4869602

Please sign in to comment.