Example #1
0
 public static Library CreateLibrary(CoreSettings settings  = null, ILibraryReader reader            = null, ILibraryWriter writer = null,
                                     IFileSystem fileSystem = null, ILocalSongFinder localSongFinder = null)
 {
     return(new LibraryBuilder().WithReader(reader)
            .WithWriter(writer)
            .WithSettings(settings)
            .WithFileSystem(fileSystem)
            .WithSongFinder(localSongFinder)
            .Build());
 }
 public LibraryBuilder WithSongFinder(ILocalSongFinder songFinder)
 {
     this.songFinder = songFinder;
     return this;
 }
Example #3
0
        private async Task UpdateSongsAsync(string path)
        {
            if (this.currentSongFinderSubscription != null)
            {
                this.currentSongFinderSubscription.Dispose();
                this.currentSongFinderSubscription = null;
            }

            this.IsUpdating = true;

            await this.RemoveMissingSongsAsync(path);

            ILocalSongFinder songFinder = this.localSongFinderFunc(path);

            this.currentSongFinderSubscription = songFinder.GetSongsAsync()
                                                 .ObserveOn(RxApp.TaskpoolScheduler)
                                                 .Subscribe(t =>
            {
                LocalSong song = t.Item1;

                this.songLock.EnterWriteLock();

                bool added = this.songs.Add(song);

                LocalSong realSong;
                bool needsUpdate = false;

                if (added)
                {
                    realSong    = song;
                    needsUpdate = true;
                }

                else
                {
                    LocalSong existing = this.songs.First(x => x.OriginalPath == song.OriginalPath);

                    if (existing.UpdateMetadataFrom(song))
                    {
                        needsUpdate = true;
                    }

                    realSong = existing;
                }

                this.songLock.ExitWriteLock();

                byte[] artworkData = t.Item2;

                if (artworkData != null)
                {
                    string key = BlobCacheKeys.GetKeyForArtwork(artworkData);

                    if (realSong.ArtworkKey != key)
                    {
                        ArtworkCache.Instance.Store(key, artworkData).ToObservable()
                        .Subscribe(x => realSong.ArtworkKey = key);
                    }
                }

                if (needsUpdate)
                {
                    this.songsUpdated.OnNext(Unit.Default);
                }
            }, () =>
            {
                this.Save();

                this.StartOnlineArtworkLookup();

                this.songLock.EnterReadLock();
                int songCount = this.songs.Count;
                this.songLock.ExitReadLock();

                AnalyticsClient.Instance.RecordLibrarySize(songCount);

                this.IsUpdating = false;
            });
        }
Example #4
0
 public LibraryBuilder WithSongFinder(ILocalSongFinder songFinder)
 {
     this.songFinder = songFinder;
     return(this);
 }