/// <summary> /// Sets a new front cover on the instance. /// </summary> /// <param name="imageFilePath">Path to the new front cover image file.</param> /// <exception cref="ArgumentException">The specified <paramref name="imageFilePath"/> is invalid.</exception> /// <exception cref="InvalidOperationException">Tags are in an invalid state on the track; the action cannot be performed.</exception> public void SetFrontCover(string imageFilePath) { if (!System.IO.File.Exists(imageFilePath)) { throw new ArgumentException($"The specified path is invalid.", nameof(imageFilePath)); } TagLib.File file = TagLib.File.Create(FilePath); if (file?.Tag == null) { throw new InvalidOperationException("Tags are in an invalid state on the track; the action cannot be performed."); } List <TagLib.IPicture> currentPictures = new List <TagLib.IPicture>(); if (file.Tag.Pictures != null) { currentPictures.AddRange(file.Tag.Pictures); currentPictures.RemoveAll(p => p.Type == TagLib.PictureType.FrontCover); } currentPictures.Add(new TagLib.Picture(imageFilePath)); file.Tag.Pictures = currentPictures.ToArray(); file.Save(); // reload the instance informations. _frontCoverDatas.Clear(); _frontCoverDatas.AddRange(LibraryEngine.ExtractFrontCoverInformations(file?.Tag, out string mimeType)); FrontCoverMimeType = mimeType; }
/// <summary> /// Constructor. /// </summary> /// <param name="year"><see cref="Year"/></param> /// <param name="library"><see cref="LibraryEngine"/></param> /// <exception cref="ArgumentNullException"><paramref name="library"/> is <c>Null</c>.</exception> public YearItemData(uint year, LibraryEngine library) : base(null) { if (library == null) { throw new ArgumentNullException(nameof(library)); } IEnumerable <TrackData> tracks = library.Tracks.Where(t => t.Year == year); Year = year; AlbumsCount = tracks.GroupBy(t => t.Album).Count(); TracksCount = tracks.Count(); TracksLength = new TimeSpan(0, 0, (int)tracks.Sum(t => t.Length.TotalSeconds)); }
/// <summary> /// Constructor. /// </summary> /// <param name="sourceData"><see cref="BaseItemData.SourceData"/></param> /// <param name="library"><see cref="LibraryEngine"/></param> /// <exception cref="ArgumentNullException"><paramref name="library"/> is <c>Null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="sourceData"/> is <c>Null</c>.</exception> public PerformerItemData(PerformerData sourceData, LibraryEngine library) : base(sourceData) { if (library == null) { throw new ArgumentNullException(nameof(library)); } if (sourceData == null) { throw new ArgumentNullException(nameof(sourceData)); } IEnumerable <TrackData> tracks = library.Tracks.Where(t => t.Performers.Contains(sourceData)); TracksCount = tracks.Count(); TracksLength = new TimeSpan(0, 0, (int)tracks.Sum(t => t.Length.TotalSeconds)); }
/// <summary> /// Constructor. /// </summary> /// <param name="sourceData"><see cref="BaseItemData.SourceData"/></param> /// <param name="library"><see cref="LibraryEngine"/></param> /// <exception cref="ArgumentNullException"><paramref name="library"/> is <c>Null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="sourceData"/> is <c>Null</c>.</exception> public AlbumItemData(AlbumData sourceData, LibraryEngine library) : base(sourceData) { if (library == null) { throw new ArgumentNullException(nameof(library)); } if (sourceData == null) { throw new ArgumentNullException(nameof(sourceData)); } AlbumArtist = sourceData.AlbumArtist.Name; _tracks = library.Tracks.Where(t => t.Album == sourceData).OrderBy(t => t.Number).ToList(); Genre = _tracks.First().Genres.FirstOrDefault()?.Name ?? string.Empty; TracksLength = new TimeSpan(0, 0, (int)_tracks.Sum(t => t.Length.TotalSeconds)); }
/// <summary> /// Constructor. /// </summary> /// <param name="sourceData"><see cref="BaseItemData.SourceData"/></param> /// <param name="library"><see cref="LibraryEngine"/></param> /// <exception cref="ArgumentNullException"><paramref name="library"/> is <c>Null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="sourceData"/> is <c>Null</c>.</exception> public AlbumArtistItemData(AlbumArtistData sourceData, LibraryEngine library) : base(sourceData) { if (library == null) { throw new ArgumentNullException(nameof(library)); } if (sourceData == null) { throw new ArgumentNullException(nameof(sourceData)); } IEnumerable <TrackData> tracks = library.Tracks.Where(t => t.Album.AlbumArtist == sourceData); AlbumsCount = tracks.Select(t => t.Album).Distinct().Count(); TracksCount = tracks.Count(); TracksLength = new TimeSpan(0, 0, (int)tracks.Sum(t => t.Length.TotalSeconds)); }
/// <summary> /// Constructor. /// Instanciates the inner <see cref="LibraryEngine"/> itself. /// </summary> /// <param name="bgwCallback">Delegate to get at runtime the <see cref="BackgroundWorker"/> which report progress.</param> /// <exception cref="ArgumentNullException"><paramref name="bgwCallback"/> is <c>Null</c>.</exception> public LibraryViewData(Func <BackgroundWorker> bgwCallback) { if (bgwCallback == null) { throw new ArgumentNullException(nameof(bgwCallback)); } _library = new LibraryEngine(Tools.ParseConfigurationList(Properties.Settings.Default.LibraryDirectories), Tools.ParseConfigurationList(Properties.Settings.Default.LibraryExtensions), false); _library.LoadingLogHandler += delegate(object sender, LoadingLogEventArgs e) { if (e?.Log != null && TotalFilesCount > -1) { int progressPercentage = e.TrackIndex == -1 ? 100 : Convert.ToInt32(e.TrackIndex / (decimal)TotalFilesCount * 100); bgwCallback.Invoke().ReportProgress(progressPercentage, e.Log); } }; }
private async Task LoadLibraryDiskAsync() { try { Debug.WriteLine("Library Initialize"); var result = await LibraryEngine.Initialize(IsFirstUse); foreach (var i in result) { if (i.Value.GetType().Name == "StorageFile") //Add/Update DataBase { //Debug.WriteLine("StorageFile"); if (i.Key == StorageLibraryChangeType.ContentsChanged) { //Debug.WriteLine("ContentChanged"); await DataBaseEngine.Update(i.Value as StorageFile); } else if (i.Key == StorageLibraryChangeType.MovedIntoLibrary) { //Debug.WriteLine("MovedIntoLibrary"); await DataBaseEngine.Add((StorageFile)i.Value); } } else if (i.Value.GetType().Name == "String") //Moved Out { //Debug.WriteLine("Move out"); DataBaseEngine.Delete(i.Value.ToString()); } else if (i.Value.GetType().Name == "KeyValuePair`2") //Moved or Renamed { //Debug.WriteLine("Moved or Renamed"); DataBaseEngine.Update((KeyValuePair <string, string>)i.Value); } } //InitializeFinished?.Invoke(null, EventArgs.Empty); } catch (Exception e) { Debug.WriteLine(e.Message); } }