public async Task <IEnumerable <MusicArtist> > GetByName(string searchQuery = null) { try { return(await artistData.GetArtistsByNameAsync(searchQuery)); } catch (Exception e) { logger.LogCritical(e, "Cannot retrieve artists"); throw; } }
public async Task <ActionResult> ImportTracks(string[] files) { Console.WriteLine("importing tracks..."); string supportedExtensions = "*.wav,*.aac,*.wma,*.wmv,*.mp3"; string musicLibraryPath = configuration.GetSection("FoldersMapping")["MusicLibrary"]; IEnumerable <string> filePaths = Directory.EnumerateFiles(musicLibraryPath, "*.*", SearchOption.AllDirectories) .Where(s => supportedExtensions.Contains(Path.GetExtension(s).ToLower())); var nonExistingTracks = filePaths.Except(await trackData.GetAllFilePath()); var musicTracks = MusicWorkerService.Instance.GetTracksFromFiles(nonExistingTracks); if (musicTracks != null) { await Add(musicTracks.ToArray()); // Create albums var albumsName = (await albumData.GetAlbumsByNameAsync(string.Empty)).Select(x => x.Title); var addedAlbumsName = new List <string>(); var tracks = musicTracks.Where(x => !albumsName.Contains(x.Album)).GroupBy(x => x.Album); foreach (IGrouping <string, MusicTrack> mtg in tracks) { albumData.Add(new MusicAlbum { Title = mtg.Key, Artists = mtg.ElementAt(0).Artist, SortableTitle = mtg.Key }); } // Create artists var artistsName = (await artistData.GetArtistsByNameAsync(string.Empty)).Select(x => x.Name); tracks = musicTracks.Where(x => !artistsName.Contains(x.Artist)).GroupBy(x => x.Artist); foreach (IGrouping <string, MusicTrack> mtg in tracks) { artistData.Add(new MusicArtist { Name = mtg.Key, SortName = mtg.Key }); } } return(Ok()); }