mirror of
https://github.com/cxfksword/jellyfin-plugin-danmu.git
synced 2026-02-02 17:59:58 +08:00
@@ -42,6 +42,11 @@ public class PluginConfiguration : BasePluginConfiguration
|
||||
/// </summary>
|
||||
public string AssSpeed { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 删除 emoji 表情。
|
||||
/// </summary>
|
||||
public bool AssRemoveEmoji { get; set; } = true;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检测弹幕数和视频剧集数需要一致才自动下载弹幕.
|
||||
|
||||
@@ -15,7 +15,8 @@ namespace Danmaku2Ass
|
||||
{
|
||||
{ "top_filter", false },
|
||||
{ "bottom_filter", false },
|
||||
{ "scroll_filter", false }
|
||||
{ "scroll_filter", false },
|
||||
{ "custom_filter", false }
|
||||
};
|
||||
|
||||
private readonly Dictionary<int, string> mapping = new Dictionary<int, string>
|
||||
@@ -93,6 +94,17 @@ namespace Danmaku2Ass
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用自定义过滤处理
|
||||
/// </summary>
|
||||
/// <param name="isFilter"></param>
|
||||
/// <returns></returns>
|
||||
public Bilibili SetCustomFilter(bool isFilter)
|
||||
{
|
||||
config["custom_filter"] = isFilter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Create(long avid, long cid, Config subtitleConfig, string assFile)
|
||||
{
|
||||
//// 弹幕转换
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Danmaku2Ass
|
||||
{
|
||||
@@ -79,10 +80,21 @@ namespace Danmaku2Ass
|
||||
/// </summary>
|
||||
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<Danmaku> DoFilter(List<Danmaku> danmakus)
|
||||
{
|
||||
// TODO
|
||||
return base.DoFilter(danmakus);
|
||||
{
|
||||
// 过滤 emoji 和非法字符
|
||||
List<Danmaku> keep = new List<Danmaku>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Danmaku> 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;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Danmaku2Ass
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user