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("-------------------------------------------"); }
public FavoriteRepository(IDatabase database, IAlbumArtistRepository albumArtistRepository, IAlbumRepository albumRepository, IArtistRepository artistRepository, IFolderRepository folderRepository, IGenreRepository genreRepository, IPlaylistRepository playlistRepository, ISongRepository songRepository, IVideoRepository videoRepository, IItemRepository itemRepository) { if (database == null) { throw new ArgumentNullException("database"); } if (albumRepository == null) { throw new ArgumentNullException("albumRepository"); } if (albumArtistRepository == null) { throw new ArgumentNullException("albumArtistRepository"); } if (artistRepository == null) { throw new ArgumentNullException("artistRepository"); } if (folderRepository == null) { throw new ArgumentNullException("folderRepository"); } if (genreRepository == null) { throw new ArgumentNullException("genreRepository"); } if (playlistRepository == null) { throw new ArgumentNullException("playlistRepository"); } if (songRepository == null) { throw new ArgumentNullException("songRepository"); } if (videoRepository == null) { throw new ArgumentNullException("videoRepository"); } if (itemRepository == null) { throw new ArgumentNullException("itemRepository"); } this.database = database; this.albumArtistRepository = albumArtistRepository; this.albumRepository = albumRepository; this.artistRepository = artistRepository; this.folderRepository = folderRepository; this.genreRepository = genreRepository; this.playlistRepository = playlistRepository; this.songRepository = songRepository; this.videoRepository = videoRepository; this.itemRepository = itemRepository; }
private int ScanAlbumArtists(IDictionary <string, string> existingIds, IList <AlbumArtist> albumArtistsMissingId) { if (isRestart) { return(0); } // Lock to prevent race conditions on MusicBrainzID insert object albumArtistsLock = new object(); // Count of number of IDs retrieved int count = 0; IAlbumArtistRepository albumArtistRepository = Injection.Kernel.Get <IAlbumArtistRepository>(); Parallel.ForEach(albumArtistsMissingId, albumArtist => { // First check if the id already exists string musicBrainzId = null; existingIds.TryGetValue(albumArtist.AlbumArtistName, out musicBrainzId); // If ID not found, try to fetch it if (musicBrainzId == null) { musicBrainzId = this.MusicBrainzIdForArtistName(albumArtist.AlbumArtistName); } if (musicBrainzId != null) { // We found one, so update the record and our cache lock (albumArtistsLock) { existingIds[albumArtist.AlbumArtistName] = musicBrainzId; albumArtist.MusicBrainzId = musicBrainzId; albumArtistRepository.InsertAlbumArtist(albumArtist, true); logger.IfInfo(albumArtist.AlbumArtistName + " = " + musicBrainzId); count++; } } else { logger.IfInfo("No musicbrainz id found for " + albumArtist.AlbumArtistName); } }); return(count); }
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("---------------------------------------------"); }
public AlbumArtistService(IAlbumArtistRepository repository) { this._repository = repository; }