mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-01 20:30:41 +00:00
37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System.Text.RegularExpressions;
|
|
using Microsoft.Extensions.Options;
|
|
using ZonyLrcTools.Cli.Config;
|
|
using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
|
|
|
|
namespace ZonyLrcTools.Cli.Infrastructure.Lyric
|
|
{
|
|
/// <summary>
|
|
/// <see cref="ILyricItemCollectionFactory"/> 的默认实现。
|
|
/// </summary>
|
|
public class LyricItemCollectionFactory : ILyricItemCollectionFactory, ITransientDependency
|
|
{
|
|
private readonly ToolOptions _options;
|
|
|
|
public LyricItemCollectionFactory(IOptions<ToolOptions> options)
|
|
{
|
|
_options = options.Value;
|
|
}
|
|
|
|
public LyricItemCollection Build(string sourceLyric, string translateLyric = null)
|
|
{
|
|
var items = new LyricItemCollection(_options.LyricOption);
|
|
if (string.IsNullOrEmpty(sourceLyric))
|
|
{
|
|
return items;
|
|
}
|
|
|
|
var regex = new Regex(@"\[\d+:\d+.\d+\].+\n?");
|
|
foreach (Match match in regex.Matches(sourceLyric))
|
|
{
|
|
items.Add(new LyricItem(match.Value));
|
|
}
|
|
|
|
return items;
|
|
}
|
|
}
|
|
} |