diff --git a/Jellyfin.Plugin.Danmu.Test/ToAssTest.cs b/Jellyfin.Plugin.Danmu.Test/ToAssTest.cs index 17f24e2..d354f56 100644 --- a/Jellyfin.Plugin.Danmu.Test/ToAssTest.cs +++ b/Jellyfin.Plugin.Danmu.Test/ToAssTest.cs @@ -15,7 +15,8 @@ namespace Jellyfin.Plugin.Danmu.Test { var xml = @"chat.bilibili.com131130330300000k-v 杨笑汝有受到羽海野千花影响啦 - 风间笑死我了 + 风间🎉笑死我了 + 🥳🥳😂 有搬运车的 杨笑汝最喜欢的就是野海羽千花! 给女儿买衣服哈哈哈哈哈 @@ -24,6 +25,7 @@ namespace Jellyfin.Plugin.Danmu.Test 这个op看得我好迷茫 "; + Danmaku2Ass.Bilibili.GetInstance().SetCustomFilter(true); var ass = Danmaku2Ass.Bilibili.GetInstance().ToASS(Encoding.UTF8.GetBytes(xml), new Config()); Console.WriteLine(ass); Assert.IsNotNull(ass); diff --git a/Jellyfin.Plugin.Danmu/Configuration/PluginConfiguration.cs b/Jellyfin.Plugin.Danmu/Configuration/PluginConfiguration.cs index 69e74ab..bf18a28 100644 --- a/Jellyfin.Plugin.Danmu/Configuration/PluginConfiguration.cs +++ b/Jellyfin.Plugin.Danmu/Configuration/PluginConfiguration.cs @@ -42,6 +42,11 @@ public class PluginConfiguration : BasePluginConfiguration /// public string AssSpeed { get; set; } = string.Empty; + /// + /// 删除 emoji 表情。 + /// + public bool AssRemoveEmoji { get; set; } = true; + /// /// 检测弹幕数和视频剧集数需要一致才自动下载弹幕. diff --git a/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Bilibili.cs b/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Bilibili.cs index fbfe8e6..e702ac3 100644 --- a/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Bilibili.cs +++ b/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Bilibili.cs @@ -15,7 +15,8 @@ namespace Danmaku2Ass { { "top_filter", false }, { "bottom_filter", false }, - { "scroll_filter", false } + { "scroll_filter", false }, + { "custom_filter", false } }; private readonly Dictionary mapping = new Dictionary @@ -93,6 +94,17 @@ namespace Danmaku2Ass return this; } + /// + /// 是否启用自定义过滤处理 + /// + /// + /// + public Bilibili SetCustomFilter(bool isFilter) + { + config["custom_filter"] = isFilter; + return this; + } + public void Create(long avid, long cid, Config subtitleConfig, string assFile) { //// 弹幕转换 diff --git a/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Filter.cs b/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Filter.cs index 85c0771..392ef07 100644 --- a/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Filter.cs +++ b/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Filter.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Text.RegularExpressions; namespace Danmaku2Ass { @@ -79,10 +80,21 @@ namespace Danmaku2Ass /// public class CustomFilter : Filter { + private Regex regEmoj = new Regex(@"(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])", RegexOptions.Compiled); public override List DoFilter(List danmakus) - { - // TODO - return base.DoFilter(danmakus); + { + // 过滤 emoji 和非法字符 + List keep = new List(); + foreach (var danmaku in danmakus) + { + danmaku.Content = this.regEmoj.Replace(danmaku.Content, string.Empty).Trim(); + if (string.IsNullOrWhiteSpace(danmaku.Content)) + { + continue; + } + keep.Add(danmaku); + } + return keep; } } } diff --git a/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Producer.cs b/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Producer.cs index 0cfa506..7fec597 100644 --- a/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Producer.cs +++ b/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Producer.cs @@ -39,10 +39,10 @@ namespace Danmaku2Ass { Filters.Add("scroll_filter", new ScrollFilter()); } - //if (Config["custom_filter"]) - //{ - // Filters.Add("custom_filter", new CustomFilter()); - //} + if (Config["custom_filter"]) + { + Filters.Add("custom_filter", new CustomFilter()); + } } @@ -52,18 +52,17 @@ namespace Danmaku2Ass { "top_filter", 0}, { "bottom_filter", 0}, { "scroll_filter", 0}, - //{ "custom_filter",0} + { "custom_filter", 0} }; List danmakus = Danmakus; - //string[] orders = { "top_filter", "bottom_filter", "scroll_filter", "custom_filter" }; - string[] orders = { "top_filter", "bottom_filter", "scroll_filter" }; + string[] orders = { "top_filter", "bottom_filter", "scroll_filter", "custom_filter" }; foreach (string name in orders) { Filter filter; - if (!this.Filters.TryGetValue(name, out filter)) - { - continue; + if (!this.Filters.TryGetValue(name, out filter)) + { + continue; } int count = danmakus.Count; diff --git a/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Studio.cs b/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Studio.cs index b037bce..7d57734 100644 --- a/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Studio.cs +++ b/Jellyfin.Plugin.Danmu/Core/Danmaku2Ass/Studio.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; namespace Danmaku2Ass { diff --git a/Jellyfin.Plugin.Danmu/LibraryManagerEventsHelper.cs b/Jellyfin.Plugin.Danmu/LibraryManagerEventsHelper.cs index 4ca6d0e..469faf7 100644 --- a/Jellyfin.Plugin.Danmu/LibraryManagerEventsHelper.cs +++ b/Jellyfin.Plugin.Danmu/LibraryManagerEventsHelper.cs @@ -927,6 +927,10 @@ public class LibraryManagerEventsHelper : IDisposable { assConfig.TuneDuration = this.Config.AssSpeed.Trim().ToInt() - 8; } + if (this.Config.AssRemoveEmoji) + { + Danmaku2Ass.Bilibili.GetInstance().SetCustomFilter(true); + } var assPath = Path.Combine(item.ContainingFolderPath, item.FileNameWithoutExtension + ".danmu.ass"); Danmaku2Ass.Bilibili.GetInstance().Create(bytes, assConfig, assPath);