Added AudioFileScanner and AudioImageExtractor logic.
This commit is contained in:
57
Harmonia.Core/Scanner/AudioFileScanner.cs
Normal file
57
Harmonia.Core/Scanner/AudioFileScanner.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using Harmonia.Core.Imaging;
|
||||
using Harmonia.Core.Models;
|
||||
using Harmonia.Core.Tags;
|
||||
|
||||
namespace Harmonia.Core.Scanner;
|
||||
|
||||
public class AudioFileScanner(ITagResolver tagResolver, IAudioImageExtractor audioImageExtractor) : IAudioFileScanner
|
||||
{
|
||||
public Song[] GetSongs(string[] fileNames)
|
||||
{
|
||||
List<Song> songs = [];
|
||||
|
||||
foreach (string fileName in fileNames)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(fileName) || File.Exists(fileName) == false)
|
||||
continue;
|
||||
|
||||
Song? song = GetSong(fileName);
|
||||
|
||||
if (song == null)
|
||||
continue;
|
||||
|
||||
songs.Add(song);
|
||||
}
|
||||
|
||||
return [.. songs];
|
||||
}
|
||||
|
||||
private Song GetSong(string fileName)
|
||||
{
|
||||
FileInfo fileInfo = new(fileName);
|
||||
SongTagInfo songTagInfo = tagResolver.GetSongTagInfo(fileName);
|
||||
using SongPictureInfo songPictureInfo = audioImageExtractor.ExtractImage(fileName, songTagInfo);
|
||||
|
||||
Song song = new()
|
||||
{
|
||||
FileName = fileName,
|
||||
Size = (ulong)fileInfo.Length,
|
||||
LastModified = fileInfo.LastWriteTime,
|
||||
Title = songTagInfo.Title,
|
||||
Album = songTagInfo.Album,
|
||||
Artists = songTagInfo.Artists,
|
||||
AlbumArtists = songTagInfo.AlbumArtists,
|
||||
DiscNumber = songTagInfo.DiscNumber,
|
||||
TrackNumber = songTagInfo.TrackNumber,
|
||||
Length = songTagInfo.Length,
|
||||
Year = songTagInfo.Year,
|
||||
Genre = songTagInfo.Genre,
|
||||
BitRate = songTagInfo.BitRate,
|
||||
SampleRate = songTagInfo.SampleRate,
|
||||
ImageName = songPictureInfo.ImageName,
|
||||
ImageHash = songPictureInfo.ImageHash
|
||||
};
|
||||
|
||||
return song;
|
||||
}
|
||||
}
|
||||
8
Harmonia.Core/Scanner/IAudioFileScanner.cs
Normal file
8
Harmonia.Core/Scanner/IAudioFileScanner.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Harmonia.Core.Models;
|
||||
|
||||
namespace Harmonia.Core.Scanner;
|
||||
|
||||
public interface IAudioFileScanner
|
||||
{
|
||||
Song[] GetSongs(string[] fileNames);
|
||||
}
|
||||
Reference in New Issue
Block a user