feat: Added support for reading song list from Csv file.

This commit is contained in:
real-zony 2023-02-08 20:56:47 +08:00
parent f1a6eefe45
commit a7ecfbe44f
6 changed files with 61 additions and 0 deletions

View File

@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QQ/@EntryIndexedValue">QQ</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Zony/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -0,0 +1,23 @@
using ZonyLrcTools.Common.Infrastructure.DependencyInject;
namespace ZonyLrcTools.Common.MusicScanner;
public class CsvFileMusicScanner : ITransientDependency
{
public async Task<List<MusicInfo>> GetMusicInfoFromCsvFileAsync(string csvFilePath, ManualDownloadOptions options)
{
var csvFileContent = await File.ReadAllTextAsync(csvFilePath);
var csvFileLines = csvFileContent.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
return csvFileLines.Skip(1).Select(line => GetMusicInfoFromCsvFileLine(line, options)).ToList();
}
private MusicInfo GetMusicInfoFromCsvFileLine(string csvFileLine, ManualDownloadOptions options)
{
var csvFileLineItems = csvFileLine.Split(',');
var name = csvFileLineItems[0];
var artist = csvFileLineItems[1];
var fakeFilePath = Path.Combine(options.OutputDirectory, options.OutputFileNamePattern.Replace("{Name}", name).Replace("{Artist}", artist));
var musicInfo = new MusicInfo(fakeFilePath, name, artist);
return musicInfo;
}
}

View File

@ -0,0 +1,7 @@
namespace ZonyLrcTools.Common.MusicScanner;
public class ManualDownloadOptions
{
public string OutputFileNamePattern { get; set; } = "{Artist} - {Name}.lrc";
public string OutputDirectory { get; set; } = "DownloadedLrc";
}

View File

@ -0,0 +1,21 @@
using System.IO;
using System.Threading.Tasks;
using Shouldly;
using Xunit;
using ZonyLrcTools.Common.MusicScanner;
namespace ZonyLrcTools.Tests.MusicScanner;
public class CsvFileMusicScannerTests : TestBase
{
[Fact]
public async Task GetMusicInfoFromCsvFileAsync_Test()
{
var musicScanner = GetService<CsvFileMusicScanner>();
var musicInfo = await musicScanner.GetMusicInfoFromCsvFileAsync(Path.Combine("TestData", "test.csv"), new ManualDownloadOptions());
musicInfo.ShouldNotBeNull();
musicInfo.Count.ShouldBeGreaterThan(0);
musicInfo.Count.ShouldBe(5);
}
}

View File

@ -0,0 +1,6 @@
Song,Artist
刀马旦,李玟
发如雪,周杰伦
说书人,寅子
爱的供养,张国荣
七里香,周杰伦
1 Song Artist
2 刀马旦 李玟
3 发如雪 周杰伦
4 说书人 寅子
5 爱的供养 张国荣
6 七里香 周杰伦

View File

@ -33,6 +33,9 @@
<Content Include="MusicFiles\Loren Gray - Queen.ncm">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Update="TestData\test.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>