示例#1
0
        public async Task UpdateTracksAsync(List <IFileMetadata> fileMetadatas, bool updateAlbumArtwork)
        {
            // Make sure that cached artwork cannot be out of date
            lock (this.cachedArtworkLock)
            {
                this.cachedArtwork = null;
            }

            // Set event args
            var args = new MetadataChangedEventArgs();

            foreach (IFileMetadata fmd in fileMetadatas)
            {
                if (fmd.Artists.IsValueChanged)
                {
                    args.IsArtistChanged = true;
                }
                if (fmd.Genres.IsValueChanged)
                {
                    args.IsGenreChanged = true;
                }
                if (fmd.Album.IsValueChanged || fmd.AlbumArtists.IsValueChanged || fmd.Year.IsValueChanged)
                {
                    args.IsAlbumChanged = true;
                }
                if (fmd.ArtworkData.IsValueChanged)
                {
                    args.IsArtworkChanged = true;
                }
                if (fmd.Title.IsValueChanged || fmd.Year.IsValueChanged || fmd.TrackNumber.IsValueChanged ||
                    fmd.TrackCount.IsValueChanged || fmd.DiscNumber.IsValueChanged || fmd.DiscCount.IsValueChanged ||
                    fmd.Lyrics.IsValueChanged)
                {
                    args.IsTrackChanged = true;
                }
            }

            // Update the metadata in the database
            await this.UpdateDatabaseMetadataAsync(fileMetadatas, updateAlbumArtwork);

            // Queue update of the file metadata
            await this.QueueUpdateFileMetadata(fileMetadatas);

            // Update the metadata in the PlaybackService
            await this.playbackService.UpdateQueueMetadataAsync(fileMetadatas);

            // Raise event
            this.MetadataChanged(args);
        }
示例#2
0
        public async Task UpdateAlbumAsync(string albumKey, MetadataArtworkValue artwork, bool updateFileArtwork)
        {
            // Make sure that cached artwork cannot be out of date
            lock (this.cachedArtworkLock)
            {
                this.cachedArtwork = null;
            }

            // Set event args
            var args = new MetadataChangedEventArgs()
            {
                IsArtworkChanged = true
            };

            // Cache new artwork
            string artworkID = await this.cacheService.CacheArtworkAsync(artwork.Value);

            // Update artwork in database
            // TODO await this.albumRepository.UpdateAlbumArtworkAsync(album.AlbumTitle, album.AlbumArtist, artworkID);

            IList <Track> tracks = await this.trackRepository.GetAlbumTracksAsync(new List <string> {
                albumKey
            });

            IList <TrackViewModel> albumTracks = await this.container.ResolveTrackViewModelsAsync(tracks);

            var fileMetadatas = new List <IFileMetadata>();

            foreach (TrackViewModel track in albumTracks)
            {
                var fmd = await this.GetFileMetadataAsync(track.Path);

                fmd.ArtworkData = artwork;
                fileMetadatas.Add(fmd);
            }

            if (updateFileArtwork)
            {
                // Queue update of the file metadata
                await this.QueueUpdateFileMetadata(fileMetadatas);
            }

            // Update the metadata in the PlaybackService
            await this.playbackService.UpdateQueueMetadataAsync(fileMetadatas);

            // Raise event
            this.MetadataChanged(args);
        }