57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
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;
|
|
}
|
|
} |