Esempio n. 1
0
        /// <summary>Loads the specified album.</summary>
        /// <param name="mdb">The MDB.</param>
        /// <param name="album">The album.</param>
        /// <returns></returns>
        public static RPCAlbum Load(MusicDataBase mdb, MDBAlbum album)
        {
            MDBArtist artist = mdb.Artists.GetStruct(album.ArtistID);
            var       files  = mdb.AudioFiles.GetStructs(nameof(MDBAudioFile.AlbumID), album.ID);
            var       result = new RPCAlbum()
            {
                ID         = album.ID,
                Name       = album.Name,
                ArtistID   = artist.ID,
                ArtistName = artist.Name,
                Duration   = new TimeSpan(files.Sum(f => f.Duration.Ticks)),
                Tags       = files.SelectMany(f => f.TagNames).Distinct().Join(";"),
                Genres     = files.SelectMany(f => f.GenreNames).Distinct().Join(";"),
                TrackCount = files.Count,
                Errors     = (MDBMetaErrors)files.BinaryOr(f => (long)f.MetaErrors),
            };

            return(result);
        }
Esempio n. 2
0
        /// <summary>Gets the album folder.</summary>
        /// <param name="album">The album.</param>
        /// <returns></returns>
        MDBFolder GetAlbumFolder(MDBAlbum album)
        {
            var paths = new Set <MDBFolder>();

            foreach (var audioFile in mdb.AudioFiles.GetStructs(
                         Search.FieldEquals(nameof(MDBAudioFile.AlbumID), album.ID) &
                         Search.FieldEquals(nameof(MDBAudioFile.AlbumArtistID), album.ArtistID)))
            {
                if (audioFile.FileID <= 0)
                {
                    continue;
                }
                MDBFile file;
                if (!mdb.Files.TryGetStruct(audioFile.FileID, out file))
                {
                    continue;
                }
                MDBFolder folder;
                if (!mdb.Folders.TryGetStruct(file.FolderID, out folder))
                {
                    continue;
                }
                paths.Include(folder);
            }
            if (paths.Count > 1)
            {
                this.LogWarning("Multiple folders for album {0}", album);
            }
            if (paths.Count > 0)
            {
                return(paths.First());
            }
            return(new MDBFolder()
            {
                ID = 0
            });
        }
Esempio n. 3
0
        /// <summary>Saves the album image.</summary>
        /// <param name="folder">The folder.</param>
        /// <param name="name">The name.</param>
        /// <param name="imageType">Type of the image.</param>
        /// <param name="album">The album.</param>
        /// <param name="data">The data.</param>
        /// <exception cref="Exception">Invalid image type!</exception>
        public void SaveAlbumImage(MDBFolder folder, string name, MDBImageType imageType, MDBAlbum album, byte[] data)
        {
            var image = new MDBImage()
            {
                MusicBrainzGuid = album.MusicBrainzReleaseGroupGuid,
                Type            = imageType,
            };

            if (!image.IsAlbumArt)
            {
                throw new Exception("Invalid image type!");
            }

            SaveImage(data, folder, name, ref image, album);
        }