public override void Start()
        {
            logger.IfInfo("------------- ARTIST ART SCAN -------------");

            Stopwatch testTotalScanTime = new Stopwatch();

            testTotalScanTime.Start();

            // Create the cache directory if it doesn't exist yet
            if (!Directory.Exists(cachePath))
            {
                Directory.CreateDirectory(cachePath);
            }

            // Keep a set of all MusicBrainz IDs known to WaveBox
            ISet <string> musicBrainzIds = new HashSet <string>();

            // Find artists and album artists missing art
            IArtistRepository artistRepository = Injection.Kernel.Get <IArtistRepository>();
            IList <Artist>    allArtists       = artistRepository.AllArtists();

            foreach (Artist artist in allArtists)
            {
                string musicBrainzId = artist.MusicBrainzId;
                if (musicBrainzId != null)
                {
                    if (!File.Exists(this.ArtPathForMusicBrainzId(musicBrainzId)))
                    {
                        musicBrainzIds.Add(musicBrainzId);
                    }
                }
            }

            IAlbumArtistRepository albumArtistRepository = Injection.Kernel.Get <IAlbumArtistRepository>();
            IList <AlbumArtist>    allAlbumArtists       = albumArtistRepository.AllAlbumArtists();

            foreach (AlbumArtist albumArtist in allAlbumArtists)
            {
                string musicBrainzId = albumArtist.MusicBrainzId;
                if (musicBrainzId != null)
                {
                    if (!File.Exists(this.ArtPathForMusicBrainzId(musicBrainzId)))
                    {
                        musicBrainzIds.Add(musicBrainzId);
                    }
                }
            }

            // Scan all MusicBrainz IDs collected by WaveBox
            int downloadCount = this.ScanIds(musicBrainzIds);

            testTotalScanTime.Stop();

            logger.IfInfo("------------- ARTIST ART SCAN -------------");
            logger.IfInfo("items retrieved: " + downloadCount);
            logger.IfInfo("total scan time: " + testTotalScanTime.ElapsedMilliseconds + "ms");
            logger.IfInfo("-------------------------------------------");
        }
Beispiel #2
0
        public override void Start()
        {
            // Stopwatches to track scanning times
            Stopwatch testTotalScanTime       = new Stopwatch();
            Stopwatch testArtistScanTime      = new Stopwatch();
            Stopwatch testAlbumArtistScanTime = new Stopwatch();

            // Dictionary of artists and existing IDs
            IDictionary <string, string> existingIds = new Dictionary <string, string>();

            // List of artists who don't have IDs
            IList <Artist> artistsMissingId = new List <Artist>();

            logger.IfInfo("------------- MUSICBRAINZ SCAN -------------");

            testTotalScanTime.Start();

            // Find artists and album artists missing ids, and all existing musicbrainz ids, to avoid extra lookups
            IArtistRepository artistRepository = Injection.Kernel.Get <IArtistRepository>();
            IList <Artist>    allArtists       = artistRepository.AllArtists();

            foreach (Artist artist in allArtists)
            {
                if (artist.MusicBrainzId == null)
                {
                    artistsMissingId.Add(artist);
                }
                else
                {
                    existingIds[artist.ArtistName] = artist.MusicBrainzId;
                }
            }

            IList <AlbumArtist> albumArtistsMissingId = new List <AlbumArtist>();

            IAlbumArtistRepository albumArtistRepository = Injection.Kernel.Get <IAlbumArtistRepository>();
            IList <AlbumArtist>    allAlbumArtists       = albumArtistRepository.AllAlbumArtists();

            foreach (AlbumArtist albumArtist in allAlbumArtists)
            {
                if (albumArtist.MusicBrainzId == null)
                {
                    albumArtistsMissingId.Add(albumArtist);
                }
                else
                {
                    existingIds[albumArtist.AlbumArtistName] = albumArtist.MusicBrainzId;
                }
            }

            testArtistScanTime.Start();
            int artistCount = this.ScanArtists(existingIds, artistsMissingId);

            testArtistScanTime.Stop();

            testAlbumArtistScanTime.Start();
            int albumArtistCount = this.ScanAlbumArtists(existingIds, albumArtistsMissingId);

            testAlbumArtistScanTime.Stop();

            testTotalScanTime.Stop();

            logger.IfInfo("------------- MUSICBRAINZ SCAN -------------");
            logger.IfInfo("total scan time: " + testTotalScanTime.ElapsedMilliseconds + "ms");
            logger.IfInfo("---------------------------------------------");
            logger.IfInfo("artist IDs retrieved: " + artistCount);
            logger.IfInfo("artist scan time: " + testArtistScanTime.ElapsedMilliseconds + "ms");
            logger.IfInfo("albumArtist IDs retrieved: " + albumArtistCount);
            logger.IfInfo("albumArtist scan time: " + testAlbumArtistScanTime.ElapsedMilliseconds + "ms");
            logger.IfInfo("---------------------------------------------");
        }