/// <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);
		}
Beispiel #2
0
        /// <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));
        }
Beispiel #3
0
        public async Task ThrowsAuthenticationException()
        {
            var baelorClient = new BaelorClient();
            var ex           = await Assert.ThrowsAsync <AuthenticationRequiredException>(
                async() => await baelorClient.Songs());

            Assert.Equal("This endpoint requires an Api Key to authenticate.", ex.Message);
        }
Beispiel #4
0
        public async Task ReturnsOneOrMoreSong()
        {
            var apiKey       = Environment.GetEnvironmentVariable("BAELOR_TEST_KEY");
            var baelorClient = new BaelorClient(apiKey);
            var songs        = await baelorClient.Songs();

            Assert.NotEmpty(songs);
        }