mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-01 20:30:41 +00:00
feat: NetEase Cloud Music Downloader support dual language lyrics.
This commit is contained in:
parent
c380fd83f6
commit
2c2c34f1a6
@ -11,5 +11,13 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric
|
||||
/// <param name="sourceLyric">原始歌词数据。</param>
|
||||
/// <returns>构建完成的 <see cref="LyricItemCollection"/> 对象。</returns>
|
||||
LyricItemCollection Build(string sourceLyric);
|
||||
|
||||
/// <summary>
|
||||
/// 根据指定的歌曲数据构建新的 <see cref="LyricItemCollection"/> 实例。
|
||||
/// </summary>
|
||||
/// <param name="sourceLyric">原始歌词数据。</param>
|
||||
/// <param name="translationLyric">翻译歌词数据。</param>
|
||||
/// <returns>构建完成的 <see cref="LyricItemCollection"/> 对象。</returns>
|
||||
LyricItemCollection Build(string sourceLyric, string translationLyric);
|
||||
}
|
||||
}
|
@ -19,19 +19,45 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric
|
||||
|
||||
public LyricItemCollection Build(string sourceLyric)
|
||||
{
|
||||
var items = new LyricItemCollection(_options.Provider.Lyric.Config);
|
||||
var lyric = new LyricItemCollection(_options.Provider.Lyric.Config);
|
||||
if (string.IsNullOrEmpty(sourceLyric))
|
||||
{
|
||||
return items;
|
||||
return lyric;
|
||||
}
|
||||
|
||||
var regex = new Regex(@"\[\d+:\d+.\d+\].+\n?");
|
||||
foreach (Match match in regex.Matches(sourceLyric))
|
||||
InternalBuildLyricObject(lyric, sourceLyric);
|
||||
|
||||
return lyric;
|
||||
}
|
||||
|
||||
public LyricItemCollection Build(string sourceLyric, string translationLyric)
|
||||
{
|
||||
var lyric = new LyricItemCollection(_options.Provider.Lyric.Config);
|
||||
if (string.IsNullOrEmpty(sourceLyric))
|
||||
{
|
||||
items.Add(new LyricItem(match.Value));
|
||||
return lyric;
|
||||
}
|
||||
|
||||
return items;
|
||||
lyric = InternalBuildLyricObject(lyric, sourceLyric);
|
||||
|
||||
if (_options.Provider.Lyric.Config.IsEnableTranslation && !string.IsNullOrEmpty(translationLyric))
|
||||
{
|
||||
var translatedLyric = InternalBuildLyricObject(new LyricItemCollection(_options.Provider.Lyric.Config), translationLyric);
|
||||
return lyric + translatedLyric;
|
||||
}
|
||||
|
||||
return lyric;
|
||||
}
|
||||
|
||||
private LyricItemCollection InternalBuildLyricObject(LyricItemCollection lyric, string sourceText)
|
||||
{
|
||||
var regex = new Regex(@"\[\d+:\d+.\d+\].+\n?");
|
||||
foreach (Match match in regex.Matches(sourceText))
|
||||
{
|
||||
lyric.Add(new LyricItem(match.Value));
|
||||
}
|
||||
|
||||
return lyric;
|
||||
}
|
||||
}
|
||||
}
|
@ -70,7 +70,8 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase
|
||||
}
|
||||
|
||||
return _lyricItemCollectionFactory.Build(
|
||||
json.OriginalLyric.Text);
|
||||
json.OriginalLyric.Text,
|
||||
json.TranslationLyric.Text);
|
||||
}
|
||||
|
||||
protected virtual void ValidateSongSearchResponse(SongSearchResponse response, LyricDownloaderArgs args)
|
||||
|
@ -43,4 +43,4 @@ globalOption:
|
||||
config:
|
||||
isOneLine: true # 双语歌词是否合并为一行展示。
|
||||
lineBreak: '\n' # 换行符的类型。
|
||||
isEnableTranslation: false # 是否启用翻译歌词。
|
||||
isEnableTranslation: true # 是否启用翻译歌词。
|
@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Lyric;
|
||||
@ -50,5 +49,17 @@ namespace ZonyLrcTools.Tests.Infrastructure.Lyric
|
||||
lyric.ShouldNotBeNull();
|
||||
lyric.IsPruneMusic.ShouldBe(false);
|
||||
}
|
||||
|
||||
// About the new feature mentioned in issue #87.
|
||||
// Github Issue: https://github.com/real-zony/ZonyLrcToolsX/issues/87
|
||||
[Fact]
|
||||
public async Task DownloadAsync_Issue85_Test()
|
||||
{
|
||||
var lyric = await _lyricDownloader.DownloadAsync("Looking at Me", "Sabrina Carpenter");
|
||||
|
||||
lyric.ShouldNotBeNull();
|
||||
lyric.IsPruneMusic.ShouldBeFalse();
|
||||
lyric.ToString().ShouldContain("你看起来失了呼吸");
|
||||
}
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ namespace ZonyLrcTools.Tests.Infrastructure.Lyric
|
||||
[Fact]
|
||||
public async Task DownloadAsync_Test()
|
||||
{
|
||||
var lyric = await _lyricDownloader.DownloadAsync("东风破", "胡歌");
|
||||
var lyric = await _lyricDownloader.DownloadAsync("东风破", "周杰伦");
|
||||
lyric.ShouldNotBeNull();
|
||||
lyric.IsPruneMusic.ShouldBe(false);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user