mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-01 04:00:42 +00:00
feat: Added support for reading song list from Csv file.
This commit is contained in:
parent
f1a6eefe45
commit
a7ecfbe44f
@ -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>
|
23
src/ZonyLrcTools.Common/MusicScanner/CsvFileMusicScanner.cs
Normal file
23
src/ZonyLrcTools.Common/MusicScanner/CsvFileMusicScanner.cs
Normal 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;
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
6
tests/ZonyLrcTools.Tests/TestData/test.csv
Normal file
6
tests/ZonyLrcTools.Tests/TestData/test.csv
Normal file
@ -0,0 +1,6 @@
|
||||
Song,Artist
|
||||
刀马旦,李玟
|
||||
发如雪,周杰伦
|
||||
说书人,寅子
|
||||
爱的供养,张国荣
|
||||
七里香,周杰伦
|
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user