コード例 #1
0
        public async Task GetLyrics(PluginLyricsInput input, CancellationToken ct, Action <PluginLyricsResult> updateAction)
        {
            String url    = string.Format("http://www.darklyrics.com/search?q={0}+{1}", HttpUtility.UrlEncode(input.Artist), HttpUtility.UrlEncode(input.Title));
            var    client = new HttpClient();
            String web    = string.Empty;

            try
            {
                var response = await client.GetAsync(url, ct);

                var data = await response.Content.ReadAsByteArrayAsync();

                web = Encoding.UTF8.GetString(data);
            }
            catch (HttpRequestException)
            {
                return;
            }
            Regex           SearchRegex = new Regex(@"<h2><a href=""(?'url'[^""]+)"" target=""_blank"" >(?'artisttitle'[^<]+)</a></h2>", RegexOptions.Compiled);
            MatchCollection matches     = SearchRegex.Matches(web);

            foreach (Match match in matches)
            {
                var result = new PluginLyricsResult();
                result.Artist        = match.Groups["artisttitle"].Value.Substring(0, match.Groups["artisttitle"].Value.IndexOf(" - "));
                result.Title         = match.Groups["artisttitle"].Value.Substring(match.Groups["artisttitle"].Value.IndexOf(" - ") + 3);
                result.FoundByPlugin = string.Format("{0} v{1}", Name, Version);
                result.Lyrics        = await DownloadLyrics(string.Format("http://www.darklyrics.com/{0}", match.Groups["url"].Value), result.Title, ct);

                updateAction(result);
            }
        }
コード例 #2
0
        public async Task GetLyrics(PluginLyricsInput input, CancellationToken ct, Action <PluginLyricsResult> updateAction)
        {
            String url    = string.Format("http://lyrics.wikia.com/api.php?action=lyrics&artist={0}&song={1}&fmt=xml", HttpUtility.UrlEncode(input.Artist), HttpUtility.UrlEncode(input.Title));
            var    client = new HttpClient();
            String xml    = string.Empty;

            try
            {
                var response = await client.GetAsync(url, ct);

                var data = await response.Content.ReadAsByteArrayAsync();

                xml = Encoding.UTF8.GetString(data);
            }
            catch (HttpRequestException)
            {
                return;
            }
            XDocument xdoc = XDocument.Parse(xml);

            if (xdoc.Element("LyricsResult").Element("lyrics").Value.ToString() != "Not found")
            {
                if (xdoc.Element("LyricsResult").Element("lyrics").Value.ToString() == "Instrumental")
                {
                    var result = new PluginLyricsResult();
                    result.Artist        = xdoc.Element("LyricsResult").Element("artist").Value.ToString();
                    result.Title         = xdoc.Element("LyricsResult").Element("song").Value.ToString();
                    result.FoundByPlugin = string.Format("{0} v{1}", Name, Version);
                    result.Lyrics        = "<p>[Instrumental]</p>\n<p><i><sub>powered by LyricWiki</sub></i></p>";
                    updateAction(result);
                }
                else
                {
                    url = xdoc.Element("LyricsResult").Element("url").Value.ToString();
                    String lyrics = await DownloadLyrics(url, ct);

                    if (!string.IsNullOrEmpty(lyrics))
                    {
                        var result = new PluginLyricsResult();
                        result.Artist        = xdoc.Element("LyricsResult").Element("artist").Value.ToString();
                        result.Title         = xdoc.Element("LyricsResult").Element("song").Value.ToString();
                        result.FoundByPlugin = string.Format("{0} v{1}", Name, Version);
                        result.Lyrics        = lyrics;
                        updateAction(result);
                    }
                    lyrics = await DownloadLyrics("http://lyrics.wikia.com/Gracenote:" + url.Substring(24), ct);

                    if (!string.IsNullOrEmpty(lyrics))
                    {
                        var result = new PluginLyricsResult();
                        result.Artist        = xdoc.Element("LyricsResult").Element("artist").Value.ToString();
                        result.Title         = string.Format("Gracenote: {0}", xdoc.Element("LyricsResult").Element("song").Value.ToString());
                        result.FoundByPlugin = string.Format("{0} v{1}", Name, Version);
                        result.Lyrics        = lyrics;
                        updateAction(result);
                    }
                }
            }
        }
コード例 #3
0
        public async Task GetLyrics(PluginLyricsInput input, CancellationToken ct, Action <PluginLyricsResult> updateAction)
        {
            String url    = string.Format("https://www.musixmatch.com/search/{0}+{1}/tracks", HttpUtility.UrlEncode(input.Artist), HttpUtility.UrlEncode(input.Title));
            var    client = new HttpClient();
            String web    = string.Empty;

            try
            {
                var response = await client.GetAsync(url, ct);

                var data = await response.Content.ReadAsByteArrayAsync();

                web = Encoding.UTF8.GetString(data);
            }
            catch (HttpRequestException)
            {
                return;
            }
            Regex           SearchRegex = new Regex(@"<a class=""title"" href=""(?'url'[^""]+)""><span>(?'title'[^<]+)</span></a></h2><h3 class=""media-card-subtitle""><span class=""artist-field""><span><a class=""artist"" href=""[^""]+"">(?'artist'[^<]+)</a></span></span></h3></div></div><meta content=", RegexOptions.Compiled);
            MatchCollection matches     = SearchRegex.Matches(web);

            foreach (Match match in matches)
            {
                var result = new PluginLyricsResult();
                result.Artist        = match.Groups["artist"].Value;
                result.Title         = match.Groups["title"].Value;
                result.FoundByPlugin = string.Format("{0} v{1}", Name, Version);
                result.Lyrics        = await DownloadLyrics(string.Format("https://www.musixmatch.com{0}", match.Groups["url"].Value), ct);

                if (result.Lyrics.StartsWith(string.Format("<p>{0}</p>\n<p>{1}</p>\n", input.Artist, input.Title)))
                {
                    result.Lyrics = result.Lyrics.Remove(3, string.Format("{0}</p>\n<p>{1}</p>\n", input.Artist, input.Title).Length);
                }
                else if (result.Lyrics.StartsWith(string.Format("<p>{0}</p>\n<p>{1}</p>\n", input.Title, input.Artist)))
                {
                    result.Lyrics = result.Lyrics.Remove(3, string.Format("<p>{0}</p>\n<p>{1}</p>\n", input.Title, input.Artist).Length);
                }
                updateAction(result);
            }
        }
コード例 #4
0
        public async Task GetLyrics(PluginLyricsInput input, CancellationToken ct, Action <PluginLyricsResult> updateAction)
        {
            String url    = string.Format("https://search.azlyrics.com/search.php?q={0}+{1}", HttpUtility.UrlEncode(input.Artist), HttpUtility.UrlEncode(input.Title));
            var    client = new HttpClient();
            String web    = string.Empty;

            try
            {
                var response = await client.GetAsync(url, ct);

                var data = await response.Content.ReadAsByteArrayAsync();

                web = Encoding.UTF8.GetString(data);
            }
            catch (HttpRequestException)
            {
                return;
            }
            Regex           LyricsRegex = new Regex(@"\d+\. <a href=""(?'url'[^""]+)"" target=""_blank""><b>(?'title'[^<]+)</b></a>  by <b>(?'artist'[^<]+)</b><br>", RegexOptions.Compiled);
            MatchCollection matches     = LyricsRegex.Matches(web);

            foreach (Match match in matches)
            {
                if ((match.Groups["title"].Value.ToLower().Contains(input.Title.ToLower()) || input.Title.ToLower().Contains(match.Groups["title"].Value.ToLower())) &&
                    (match.Groups["artist"].Value.ToLower().Contains(input.Artist.ToLower()) || input.Artist.ToLower().Contains(match.Groups["artist"].Value.ToLower())))
                {
                    var result = new PluginLyricsResult();
                    result.Artist        = match.Groups["artist"].Value;
                    result.Title         = match.Groups["title"].Value;
                    result.FoundByPlugin = string.Format("{0} v{1}", Name, Version);
                    result.Lyrics        = await DownloadLyrics(match.Groups["url"].Value, ct);

                    updateAction(result);
                }
            }
        }