예제 #1
0
        /// <summary>
        /// Searches OVH for lyrics and returns them as string.
        /// </summary>
        /// <param name="lavaTrack"><see cref="LavaTrack"/></param>
        /// <returns><see cref="string"/></returns>
        /// <exception cref="ArgumentNullException">Throws if LavaTrack is null.</exception>
        public static async ValueTask <string> SearchOVHAsync(LavaTrack lavaTrack)
        {
            if (lavaTrack == null)
            {
                throw new ArgumentNullException(nameof(lavaTrack));
            }

            var(author, title) = lavaTrack.GetAuthorAndTitle();
            var url   = $"https://api.lyrics.ovh/v1/{author.Encode()}/{title.Encode()}";
            var bytes = await GetBytesAsync(url)
                        .ConfigureAwait(false);

            if (bytes.Length == 0)
            {
                throw new Exception($"No lyrics found for {lavaTrack.Title}");
            }

            var rawJson = Encoding.UTF8.GetString(bytes);
            var parse   = JObject.Parse(rawJson);

            if (!parse.TryGetValue("lyrics", out var result))
            {
                return(parse.GetValue("error").ToObject <string>());
            }

            var regex = new Regex(@"[\r\n]{2,}");

            return(regex.Replace($"{result}", "\n"));
        }
예제 #2
0
        /// <summary>
        /// Searches Genius for lyrics and returns them as string.
        /// </summary>
        /// <param name="lavaTrack"><see cref="LavaTrack"/></param>
        /// <returns><see cref="string"/></returns>
        /// <exception cref="ArgumentNullException">Throws if LavaTrack is null.</exception>
        public static async ValueTask <string> SearchGeniusAsync(LavaTrack lavaTrack)
        {
            if (lavaTrack == null)
            {
                throw new ArgumentNullException(nameof(lavaTrack));
            }

            var(author, title) = lavaTrack.GetAuthorAndTitle();
            author             = author.Replace(' ', '-');
            title = title.Replace(' ', '-');

            var url   = $"https://genius.com/{author}-{title}-lyrics";
            var bytes = await GetBytesAsync(url)
                        .ConfigureAwait(false);

            return(VictoriaExtensions.ParseGeniusHtml(bytes));
        }
예제 #3
0
        /// <summary>
        /// Searches Genius for lyrics and returns them as string.
        /// </summary>
        /// <param name="lavaTrack"><see cref="LavaTrack"/></param>
        /// <returns><see cref="string"/></returns>
        /// <exception cref="ArgumentNullException">Throws if LavaTrack is null.</exception>
        public static async ValueTask <string> SearchGeniusAsync(LavaTrack lavaTrack)
        {
            if (lavaTrack == null)
            {
                throw new ArgumentNullException(nameof(lavaTrack));
            }

            var(author, title) = lavaTrack.GetAuthorAndTitle();
            //Phytal - added regex to improve lyric finding
            Regex x = new Regex(@"\[\D+\]");

            title  = x.Replace(title, "").Trim();
            author = author.Trim();
            //
            author = author.Replace(' ', '-');
            title  = title.Replace(' ', '-');

            var url   = $"https://genius.com/{author}-{title}-lyrics";
            var bytes = await GetBytesAsync(url)
                        .ConfigureAwait(false);

            return(VictoriaExtensions.ParseGeniusHtml(bytes));
        }