aurora/Aurora/Backend/Services/LibraryService.cs

58 lines
1.6 KiB
C#
Raw Normal View History

2019-05-20 00:21:54 +00:00
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using Aurora.Backend.Models.Media;
2019-05-20 00:21:54 +00:00
using Aurora.Backend.Utils;
namespace Aurora.Backend.Services
{
public class LibraryService : BaseService<LibraryService>
{
#region Fields
private string _pathName = "/Users/brandonwatson/Music/iTunes/iTunes Media/Music";
private string _extensions = ".wav,.mp3,.aiff,.flac,.m4a,.m4b,.wma";
private Dictionary<string, BaseMedia> _library;
2019-05-20 00:21:54 +00:00
#endregion Fields
public LibraryService()
{
_library = new Dictionary<string, BaseMedia>();
2019-05-20 00:21:54 +00:00
LoadLibrary();
}
/// <summary>
/// Gets the songs.
/// </summary>
/// <returns>The songs.</returns>
public ObservableCollection<BaseMedia> GetLibrary()
2019-05-20 00:21:54 +00:00
{
ObservableCollection<BaseMedia> collection = new ObservableCollection<BaseMedia>();
foreach (KeyValuePair<string, BaseMedia> pair in _library)
2019-05-20 00:21:54 +00:00
{
collection.Add(pair.Value);
}
return collection;
}
/// <summary>
/// Loads library from files.
/// </summary>
private void LoadLibrary()
{
//Get songs
List<FileInfo> musicFiles = FileSystemUtils.TraverseFoldersAsync(_pathName, _extensions);
foreach (FileInfo file in musicFiles)
{
TagLib.File tagFile = TagLib.File.Create(file.FullName);
BaseMedia song = new LocalAudio(file);
2019-05-20 00:21:54 +00:00
_library.Add(song.Id, song);
}
}
}
}