/// <summary> /// Generates a cryptographically random and unique collection of fingerprints. /// </summary> /// <param name="baelorApiKey">An Api Key for the Baelor Api (https://baelor.io)</param> public static async Task<IEnumerable<Fingerprint>> GenerateFingerprint(string baelorApiKey) { var baelorClient = new BaelorClient(baelorApiKey); var songs = await baelorClient.Songs(); var fingerprints = new List<Fingerprint>(); foreach (var song in songs) { var index = 0; foreach (var lyric in song.Lyrics.Where(l => !string.IsNullOrWhiteSpace(l.Content))) { fingerprints.Add(new Fingerprint { SongSlug = song.Slug, AlbumSlug = song.Album.Slug, Lyric = lyric.Content, TimeCodeStart = lyric.TimeCode, TimeCodeEnd = (index == song.Lyrics.Count() - 1) ? song.Length : song.Lyrics.ElementAt(index + 1).TimeCode }); index++; } } fingerprints.Shuffle(); return fingerprints.DistinctBy(f => f.Lyric.Trim().ToLowerInvariant()).Take(FingerprintCount); }
/// <summary> /// Generates a cryptographically random and unique collection of fingerprints. /// </summary> /// <param name="baelorApiKey">An Api Key for the Baelor Api (https://baelor.io)</param> public static async Task <IEnumerable <Fingerprint> > GenerateFingerprint(string baelorApiKey) { var baelorClient = new BaelorClient(baelorApiKey); var songs = await baelorClient.Songs(); var fingerprints = new List <Fingerprint>(); foreach (var song in songs) { var index = 0; foreach (var lyric in song.Lyrics.Where(l => !string.IsNullOrWhiteSpace(l.Content))) { fingerprints.Add(new Fingerprint { SongSlug = song.Slug, AlbumSlug = song.Album.Slug, Lyric = lyric.Content, TimeCodeStart = lyric.TimeCode, TimeCodeEnd = (index == song.Lyrics.Count() - 1) ? song.Length : song.Lyrics.ElementAt(index + 1).TimeCode }); index++; } } fingerprints.Shuffle(); return(fingerprints.DistinctBy(f => f.Lyric.Trim().ToLowerInvariant()).Take(FingerprintCount)); }
public async Task ThrowsAuthenticationException() { var baelorClient = new BaelorClient(); var ex = await Assert.ThrowsAsync <AuthenticationRequiredException>( async() => await baelorClient.Albums()); Assert.Equal("This endpoint requires an Api Key to authenticate.", ex.Message); }
public async Task ReturnsAlbumFromSlug(string slug) { var apiKey = Environment.GetEnvironmentVariable("BAELOR_TEST_KEY"); var baelorClient = new BaelorClient(apiKey); var album = await baelorClient.Album(slug); Assert.NotNull(album); }
public async Task ReturnsOneOrMoreAlbum() { var apiKey = Environment.GetEnvironmentVariable("BAELOR_TEST_KEY"); var baelorClient = new BaelorClient(apiKey); var albums = await baelorClient.Albums(); Assert.NotEmpty(albums); }
public async Task ReturnsSongFromSlug(string slug) { var apiKey = Environment.GetEnvironmentVariable("BAELOR_TEST_KEY"); var baelorClient = new BaelorClient(apiKey); var song = await baelorClient.Song(slug); Assert.NotNull(song); }
public static async Task GetLyricsToSong(Dictionary <string, string> arguments, Dictionary <string, string> options) { var songSlug = arguments["song"]; var hideTimecodes = options["h"]; var apiKey = options["k"]; var client = new BaelorClient(apiKey); var song = await client.Song(songSlug); WriteLine($"Lyrics for {song.Title}:"); foreach (var lyric in song.Lyrics) { if (hideTimecodes == "f") { Write($"{lyric.TimeCode} - "); } WriteLine($"{lyric.Content}"); } }
public static async Task GetAlbum(Dictionary <string, string> arguments, Dictionary <string, string> options) { var albumSlug = arguments["album"]; var apiKey = options["k"]; var client = new BaelorClient(apiKey); var album = await client.Album(albumSlug); WriteLine(album.Name); WriteLine($"- Produced By: {string.Join(", ", album.Producers)}"); WriteLine($"- Genres: {string.Join(", ", album.Genres)}"); WriteLine($"- Released: {album.ReleasedAt.ToString("dd MMM yyyy")}"); WriteLine($"- Label: {album.Label}"); WriteLine($"- Length: {album.Length.ToString("c")}"); WriteLine($"- Songs:"); foreach (var song in album.Songs) { WriteLine($" - {song.Title}"); } }