Example #1
0
        private List <Data.Artist> ExtractAlbumArtists(string html)
        {
            var artistsRegex = new Regex(@"\<h3\>Artiesten\<\/h3\>\s*\<ul class\=\""list\-unstyled\""\>\s*(?<artists>.*?)\s*\<\/ul\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var matchArtists = artistsRegex.Match(html);

            if (!matchArtists.Success)
            {
                throw new Exception("No ul found");
            }

            var liRegex       = new Regex(@"\<li.*?\>.*?\<a href\=\""(?<url>.*?)\""\>(?<name>.*?)\<\/a\>\<\/li\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var artistMatches = liRegex.Matches(matchArtists.Groups["artists"].Value);
            var arr_matches   = new Match[artistMatches.Count];

            artistMatches.CopyTo(arr_matches, 0);

            return(arr_matches.Select(m =>
            {
                var url_split = m.Groups["url"].Value.Split('/');
                return new Data.Artist
                {
                    Id = Convert.ToInt32(url_split[url_split.Length - 2]),
                    Url = m.Groups["url"].Value,
                    Name = m.Groups["name"].Value
                };
            }).ToList());
        }
Example #2
0
        private List <Data.Song> ExtractAlbumSongs(string html)
        {
            var songsRegex = new Regex(@"\<h1\>(?<artist_album>.*?)\<\/h1\>\s*\<ul class\=\""list\-unstyled\""\>\s*(?<tracks>.*?)\s*\<\/ul\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var matchSongs = songsRegex.Match(html);

            if (!matchSongs.Success)
            {
                throw new Exception("No ul found");
            }

            var liRegex     = new Regex(@"\<li.*?\>.*?\<a href\=\""(?<url>.*?)\""\>(?<title>.*?)\<\/a\>\<\/li\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var songMatches = liRegex.Matches(matchSongs.Groups["tracks"].Value);
            var arr_matches = new Match[songMatches.Count];

            songMatches.CopyTo(arr_matches, 0);

            return(arr_matches.Select(m =>
            {
                var url_split = m.Groups["url"].Value.Split('/');
                return new Data.Song
                {
                    Id = Convert.ToInt32(url_split[url_split.Length - 3]),
                    Url = m.Groups["url"].Value,
                    Title = m.Groups["title"].Value
                };
            }).ToList());
        }
        private Task <Album[]> ExtractArtistAlbums(string html)
        {
            var rgx        = new Regex(@"\<div id\=\""[0-9]+\"" class\=\""album\""\>album\: \<b\>\""(?<album_name>.*?)\""\<\/b\> \((?<year>[0-9]{4})\)\<\/div\>\s(?<tracks>.*?)\s\s", RegexOptions.Singleline | RegexOptions.Multiline);
            var matches    = rgx.Matches(html);
            var arrMatches = new Match[matches.Count];

            matches.CopyTo(arrMatches, 0);

            var tasks = arrMatches.Select((m) => {
                int year;
                var hasYear = int.TryParse(m.Groups["year"].Value, out year);

                return(Task.Run(async() =>
                {
                    return new Album
                    {
                        Url = null,
                        Name = m.Groups["album_name"].Value,
                        ReleaseDate = hasYear ? (DateTime?)new DateTime(year, 1, 1) : null,
                        Tracks = await ExtractArtistAlbumTracks(m.Groups["tracks"].Value)
                    };
                }));
            });

            return(Task.WhenAll(tasks));
        }
        private async Task <IEnumerable <Album> > ExtractArtistAlbums(string url)
        {
            var link = url;

            if (!link.EndsWith("/"))
            {
                link += "/";
            }
            link += "albums";

            var html = await SendRequest(httpClient, link);

            var rgx_albums_ul = new Regex(@"\<ul class=\""albums grid\""\>(?<list>.*?)\<\/ul\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var m_albums_ul   = rgx_albums_ul.Match(html);

            if (!m_albums_ul.Success)
            {
                throw new Exception("No ul tag found");
            }

            var rgx_album_li = new Regex(@"\<li\>.*?\<h2 class=\""media\-card\-title\""\>\<a href=\""(?<url>.*?)\""\>(?<title>.*?)\<\/a\>\<\/h2\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var m_albums     = rgx_album_li.Matches(m_albums_ul.Groups["list"].Value);
            var arr_albums   = new Match[m_albums.Count];

            m_albums.CopyTo(arr_albums, 0);

            return(arr_albums.Select(a => new Album
            {
                Name = a.Groups["title"].Value,
                Url = "https://www.musixmatch.com" + System.Web.HttpUtility.HtmlDecode(a.Groups["url"].Value)
            }));
        }
Example #5
0
        private Task <IEnumerable <Song> > ExtractArtistSongs(string songsHtml)
        {
            //var rgxSong = new Regex(@"\<tr id\=\""lyric\-(?<id>[0-9]+)\""\>\<td class\=\""\""\>\<a style\=\""\"" class\=\""\"" href\=\""(?<url>\/\/songmeanings\.com\/songs\/view\/\k<id>\/)\"" title\=\""(?<title>.*?)\""\>\k<title>\<\/a\>\<\/td\>\<td class\=\""\""\>\<span id\=\""lyriclinks-\k<id>\"" style\=\""display\: none;\""\>\<\/span\>\<\/td\>\<td class\=\""comments \"">\<a style\=\""\"" class\=\""\"" href\=\""\k<url>\"" title\=\""[0-9]+ comments on \k<title> lyrics\"" rel\=\""nofollow\""\>[0-9]+\<\/a\>\<\/td\>\<\/tr\>", RegexOptions.Singleline | RegexOptions.Multiline);
            //var mSongs = rgxSong.Matches(songsHtml);
            //var arrMatches = new Match[mSongs.Count];
            //mSongs.CopyTo(arrMatches, 0);
            //return Task.FromResult(arrMatches.Select(m => new Song
            //{
            //    Title = m.Groups["title"].Value,
            //    Url = m.Groups["url"].Value
            //}));

            var rgxTr  = new Regex(@"\<tr id\=\""lyric\-(?<id>[0-9]+)\""\>(?<content>.*?)\<\/tr\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var mTrs   = rgxTr.Matches(songsHtml);
            var arrTrs = new Match[mTrs.Count];

            mTrs.CopyTo(arrTrs, 0);

            var rgxTd = new Regex(@"\<td.*?\>\<a .*? href\=\""(?<url>\/\/songmeanings\.com\/songs\/view\/[0-9]+\/)\"" title\=\""(?<title>.*?) lyrics\""\>\k<title>\<\/a\>\<\/td\>\<td.*?\>\<span .*?\>\<\/span\>\<\/td\>\<td class\=\""comments [a-z]*\"">\<a .*? href\=\""\k<url>\"" title\=\""[0-9]+ comments on \k<title> lyrics\"" rel\=\""nofollow\""\>[0-9]+\<\/a\>\<\/td\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var mTds  = arrTrs.Select(m => rgxTd.Match(m.Value));

            var result = mTds.Select(m => new Song {
                Url   = m.Groups["url"].Value,
                Title = m.Groups["title"].Value
            });

            return(Task.FromResult(result));
        }
Example #6
0
        public RawInstruction(string instruction)
        {
            var fullMatch = regexInstruction.Match(instruction.Trim());

            if (!fullMatch.Success)
            {
                throw new InvalidInstructionException();
            }
            Command = fullMatch.Groups[1].Value;

            if (fullMatch.Groups[2].Length == 0)
            {
                Arguments = new string[0];
                return;
            }
            var argumentMatchesColl = regexArgument.Matches(fullMatch.Groups[2].Value);
            var argumentMatches     = new Match[argumentMatchesColl.Count]; // copy manually to be able to use LINQ, remove with .NET Standard 2.1

            argumentMatchesColl.CopyTo(argumentMatches, 0);

            if (!argumentMatches.Any() || argumentMatches.Any(m => !m.Success))
            {
                throw new Exception("Assertion failed during syntax error");
            }
            Arguments = argumentMatches
                        .Select(m => m.Groups[1].Success
                    ? m.Groups[1].Value
                    : StringUtils.Unescape(m.Groups[2].Value))
                        .ToArray();
        }
        private IEnumerable <Album> ExtractArtistAlbums(string url, string html)
        {
            var rgx_container = new Regex(@"\<div class=\""tdata\-ext\""\>\s*(?<albums>.*?)\s*\<\/div\>\s*\<section.*?\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var match_albums  = rgx_container.Match(html);

            if (!match_albums.Success)
            {
                throw new Exception("No albums section found");
            }

            var rgx_album     = new Regex(@"\<div class=\""clearfix\""\>\<h3 class=\""artist\-album\-label\""\>\<a href=\""(?<album_url>.*?)\""\>(?<album_title>.*?)\<\/a\>\s*\<span class=\""year\""\>\[(?<album_year>[0-9]{4})\]\<\/span\>\<\/h3\>\<div class=\""artist\-album\-thumb\""\>\<img src=\""(?<album_image>.*?)\""\>\<\/div\>\<table class=\""tdata\""\>.*?\<tbody\>(?<rows>.*?)\<\/tbody\>\<\/table\>\<\/div\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var album_matches = rgx_album.Matches(match_albums.Groups["albums"].Value);
            var arr_albums    = new Match[album_matches.Count];

            album_matches.CopyTo(arr_albums, 0);

            return(arr_albums.Select(a => new Album
            {
                Id = Convert.ToInt32(a.Groups["album_url"].Value.Split('/').Reverse().ElementAt(1)),
                Url = "https://www.lyrics.com" + a.Groups["album_url"].Value,
                //Url = "https://www.lyrics.com" + HttpUtility.UrlDecode(a.Groups["album_url"].Value),
                Name = a.Groups["album_title"].Value,
                ReleaseDate = new DateTime(Convert.ToInt32(a.Groups["album_year"].Value), 1, 1),
                CoverArtUrl = a.Groups["album_image"].Value,

                Tracks = ExtractArtistAlbumSongs(a.Groups["rows"].Value).ToList()
            }));
        }
        private List <Classes.Artist> ExtractSongArtists(string html)
        {
            var regexUl = new Regex(@"\<h3\>Artiesten\<\/h3\>\s*\<ul.*?\>\s*(.*?)\s*\<\/ul\>");
            var matchUl = regexUl.Match(html);

            if (!matchUl.Success)
            {
                throw new Exception("No UL found");
            }

            var regexLi        = new Regex(@"\<li.*?\>.*?\<a href\=\""(?<url>.*?)\""\>(?<name>.*?)\<\/a\>\<\/li\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var artist_matches = regexLi.Matches(matchUl.Value);
            var arr_matches    = new Match[artist_matches.Count];

            artist_matches.CopyTo(arr_matches, 0);


            return(arr_matches.Select(m => {
                var url_split = m.Groups["url"].Value.Split('/');
                return new Classes.Artist
                {
                    Id = Convert.ToInt32(url_split[url_split.Length - 2]),
                    Url = m.Groups["url"].Value,
                    Name = m.Groups["name"].Value
                };
            }).ToList());
        }
        public static void ICollectionOfT_CopyTo()
        {
            string[] expected = new[] { "t", "t" };
            ICollection<Match> collection = CreateCollection();

            Match[] array = new Match[collection.Count];
            collection.CopyTo(array, 0);

            Assert.Equal(expected, array.Select(c => c.ToString()));
        }
Example #10
0
        public void Init()
        {
            // Populate compiled matches.
            CompiledMatches = Match.Select((match) =>
                                           new Regex(match)).ToArray();

            // Populate compiled exclusions.
            CompiledExclusions = Exclude.Select((exclusion) =>
                                                new Regex(exclusion)).ToArray();
        }
        public static void ICollectionOfT_CopyTo()
        {
            string[]            expected   = new[] { "t", "t" };
            ICollection <Match> collection = CreateCollection();

            Match[] array = new Match[collection.Count];
            collection.CopyTo(array, 0);

            Assert.Equal(expected, array.Select(c => c.ToString()));
        }
        private List <Song> ExtractArtistSongs(string html)
        {
            var rgxSong   = new Regex(@"\<div class\=\""list_item\""\>\s*\<div class\=\""cover\""\>\s*\<a href\=\""(?<url>.*?)\""\>\s*\<img alt\=\""Cover\: (?<artist>.*?) \- (?<title>.*?)\"" src\=\""(?<image>.*?)\"" \/\>\s*\<\/a\>\s*\<\/div\>\s*\<div class\=\""info\""\>\s*\<span.*?\>\s*\<\/span\>\s*\<span.*?\>\s*\<a href\=\""(?<url>.*?)\"".*?\>\k<title>\<\/a\>\s*\<\/span\>.*?\<\/div\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var m_songs   = rgxSong.Matches(html);
            var arr_songs = new Match[m_songs.Count];

            m_songs.CopyTo(arr_songs, 0);

            return(arr_songs.Select(m => new Song
            {
                Url = "https://www.lololyrics.com" + m.Groups["url"].Value,
                Title = m.Groups["title"].Value,
            }).ToList());
        }
Example #13
0
        private Task <IEnumerable <Album> > ExtractArtistAlbums(string albumsHtml)
        {
            var rgxAlbum   = new Regex(@"\<div class\=\""album\-holder albums\-list\""\>\s*\<div class\=\""info\""\>\s*\<img src\=\""(?<image>.*?)\"" alt\=\""(?<name>.*?)\"" .*?\>\s*\<\/div\>\s*\<div class\=\""text\""\>\s*\<h3\>\<a href\=\""(?<url>.*?)\"" title\=\""\k<name>\""\>\k<name>\<\/a\>\<\/h3\>\s*\<ul class\=\""albumlist\""\>\s*\<li\>(?<released>[0-9\-]+)\<\/li\>\s*\<li\>[0-9]+ Songs\<\/li\>\s*\<li\>\<a href\=\""(\k<url>.*?)\"" title\=\""See album details\""\>See album details\<\/a\>\<\/li\>\s*\<\/ul\>\s*\<\/div\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var mAlbums    = rgxAlbum.Matches(albumsHtml);
            var arrMatches = new Match[mAlbums.Count];

            mAlbums.CopyTo(arrMatches, 0);
            return(Task.FromResult(arrMatches.Select(m => new Album
            {
                Name = m.Groups["name"].Value,
                CoverArtUrl = m.Groups["image"].Value,
                Url = m.Groups["url"].Value
            })));
        }
Example #14
0
        public static Graph ReadFromMatrixFile(string fileName)
        {
            var data = File.ReadAllLines(fileName);

            Regex regex   = new Regex(@"(\d)");
            var   matches = new Match[data.Length][];

            for (int i = 0; i < data.Length; i++)
            {
                matches[i] = regex.Matches(data[i]).ToArray();
            }

            return(ReadFromMatrix(matches.Select(m => m.Select(e => int.Parse(e.Value)).ToArray()).ToArray()));
        }
        private Task <List <Song> > ExtractArtistAlbumTracks(string html)
        {
            var rgx        = new Regex(@"\<div class\=\""listalbum\-item\""\>\<a href\=\""\.\.(?<url>.*?)\"" target\=\""_blank\""\>(?<title>.*?)\<\/a\>\<\/div\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var matches    = rgx.Matches(html);
            var arrMatches = new Match[matches.Count];

            matches.CopyTo(arrMatches, 0);

            return(Task.FromResult(arrMatches.Select(m => new Song
            {
                Url = "https://www.azlyrics.com" + m.Groups["url"].Value,
                Title = m.Groups["title"].Value
            }).ToList()));
        }
        private IEnumerable <Song> ExtractArtistAlbumSongs(string html)
        {
            var rgx_song = new Regex(@"\<tr\>\<td.*?\>\<strong\>\<a href=\""(?<url>.*?)\""\>(?<title>.*?)\<\/a\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var m_song   = rgx_song.Matches(html);
            var matches  = new Match[m_song.Count];

            m_song.CopyTo(matches, 0);

            return(matches.Select(m => new Song
            {
                Title = m.Groups["title"].Value,
                Url = "https://www.lyrics.com" + m.Groups["url"].Value
                      //Url = "https://www.lyrics.com" + HttpUtility.UrlDecode(m.Groups["url"].Value)
            }));
        }
Example #17
0
        private List <Album> ExtractArtistAlbums(string html)
        {
            var rgx     = new Regex(@"\<div class\=\""listbox\-album\""\>\s*\<a href\=\""(?<url>.*?)\"".*?\>\s*\<img src\=\""(?<image>.*?)\"".*?\>\s*\<\/a\>\s*\<h3\>\<a href\=\""\k<url>\"".*?\>(?<title>.*?)\<\/a\>\<\/h3\>\s*\<\/div\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var matches = rgx.Matches(html);
            var arrM    = new Match[matches.Count];

            matches.CopyTo(arrM, 0);

            return(arrM.Select(m => new Album
            {
                Url = m.Groups["url"].Value,
                Name = m.Groups["title"].Value,
                CoverArtUrl = m.Groups["image"].Value
            }).ToList());
        }
        private string ExtractSongLyrics(string html, bool trimTrash)
        {
            var spanRegex   = new Regex(@"(?<=\<span class=\""lyrics__content__ok\""\>).*?(?=\<\/span\>)", RegexOptions.Singleline | RegexOptions.Multiline);
            var spanMatches = spanRegex.Matches(html);

            if (spanMatches.Count == 0)
            {
                throw new Exception("span tag not found");
            }

            var matches = new Match[spanMatches.Count];

            spanMatches.CopyTo(matches, 0);

            return(string.Join("\r\n\r\n", matches.Select(m => m.Value)));
        }
Example #19
0
        public IEnumerable <string> EnumerateFiles()
        {
            // Find common base paths of match strings, so we don't enumerate the same root multiple times,
            // and we don't enumerate a child path unnecessarily
            var matchers = Match.Select(x => new PathMatcher(x)).ToList();

            for (var i = 0; i < matchers.Count; i++)
            {
                var match = matchers[i];
                for (var j = i + 1; j < matchers.Count; j++)
                {
                    // If [j] was merged into [i], remove [j] and fix index as list items shift
                    if (match.Merge(matchers[j]))
                    {
                        matchers.RemoveAt(j);
                        j--;
                    }
                }
            }

            // Log invalid paths
            foreach (var matcher in matchers.Where(x => x.IsInvalid))
            {
                Log.Error($"Path \"{matcher.BasePath}\" not found.");
            }

            // Create an async iterator for each matcher enumeration, then process the first
            // iterator to get its next value each time to interleve results
            var iterators = matchers.Select(x => new AsyncIterator <string>(x.EnumerateFiles())).ToArray();
            var tasks     = iterators.Select(x => x.NextAsync()).ToList();

            while (tasks.Any())
            {
                var index    = Task.WaitAny(tasks.ToArray());
                var iterator = tasks[index].Result;
                if (iterator.HasCurrent)
                {
                    yield return(iterator.Current);

                    tasks[index] = iterator.NextAsync();
                }
                else
                {
                    tasks.RemoveAt(index);
                }
            }
        }
        private static Face CreateFace(string definition)
        {
            var matches  = Regex.Matches(definition, FaceIndicePattern);
            var vertices = new Match[matches.Count];

            matches.CopyTo(vertices, 0);
            return(new Face
            {
                Indices = vertices.Select(match => new Indice
                {
                    VertexIndex = int.Parse(match.Groups[1].Value) - 1,
                    TextureIndex = match.Groups[2].Value != string.Empty ? (int?)int.Parse(match.Groups[2].Value) - 1 : null,
                    NormalIndex = match.Groups[3].Value != string.Empty ? (int?)int.Parse(match.Groups[3].Value) - 1 : null
                })
                          .ToList()
            });
        }
Example #21
0
        private static char[] GetMatchesForSuppliedRegEx(Regex regEx, string input, int numberOfRepetitionsToCheck = 2, char[] charactersToCheck = null)
        {
            var matchesCollection = regEx.Matches(input);

            if (matchesCollection.Count > 0)
            {
                var matchesArray = new Match[matchesCollection.Count];
                matchesCollection.CopyTo(matchesArray, 0);
                var matchedCharacters = matchesArray.Select(m => m.Value[0]).ToArray();
                if (charactersToCheck != null && charactersToCheck.Count() > 0)
                {
                    matchedCharacters = charactersToCheck.Where(x => matchedCharacters.Contains(x)).ToArray();
                }
                return(matchedCharacters);
            }
            return(null);
        }
        private IEnumerable <Artist> ExtractArtists(string h1)
        {
            var rgx           = new Regex(@"<a.*? href\=\""(?<url>.*?)\""\>(?<artist>.*?)\<\/a\>", RegexOptions.Singleline);
            var m_artists     = rgx.Matches(h1);
            var arr_m_artists = new Match[m_artists.Count];

            m_artists.CopyTo(arr_m_artists, 0);

            if (!arr_m_artists.Any())
            {
                throw new Exception("Could not extract artists");
            }

            return(arr_m_artists.Select(m => new Artist
            {
                Url = "https://www.lololyrics.com" + m.Groups["url"].Value,
                Name = m.Groups["artist"].Value
            }));
        }
Example #23
0
        private List <Song> ExtractAlbumSongs(string html)
        {
            var rgx     = new Regex(@"\<div class\=\""rightcol rightcol\-thin\""\>\s*\<table class\=\""tracklist\""\>\s*\<tbody\>\s*(?<songs>.*?)\<\/tbody\>\s*\<\/table\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var m_table = rgx.Match(html);

            if (!m_table.Success)
            {
                throw new Exception("No songs found");
            }

            var rgx_tr = new Regex(@"\<tr.*?\>.*?\<a.*?href=\""(?<url>.*?)\"".*?\>(?<title>.*?)\<\/a\>.*?\<\/td\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var m_tr   = rgx_tr.Matches(m_table.Groups["songs"].Value);
            var arr_tr = new Match[m_tr.Count];

            m_tr.CopyTo(arr_tr, 0);

            return(arr_tr.Select(m => new Song
            {
                Url = m.Groups["url"].Value,
                Title = m.Groups["title"].Value
            }).ToList());
        }
        private IEnumerable <Artist> ExtractSongArtists(string html)
        {
            var h3Regex = new Regex(@"\<h3 class=\""lyric-artist\""\>(?<h3>.*?)\<\/h3\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var h3Match = h3Regex.Match(html);

            if (!h3Match.Success)
            {
                return(null);
            }

            var aRegex   = new Regex(@"\<a href=\""(?<url>artist\/.*?)\""\>(?<name>.*?)\<\/a\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var aMatches = aRegex.Matches(h3Match.Groups["h3"].Value);

            var aMatchesArray = new Match[aMatches.Count];

            aMatches.CopyTo(aMatchesArray, 0);

            return(aMatchesArray.Select(m => new Artist
            {
                Name = m.Groups["name"].Value,
                Url = "https://www.lyrics.com/" + m.Groups["url"].Value
            }));
        }
        private IEnumerable <Song> ExtractAlbumTracks(string html)
        {
            var rgx_table = new Regex(@"\<tbody\>(?<rows>.*)\<\/tbody\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var m_table   = rgx_table.Match(html);

            if (!m_table.Success)
            {
                throw new Exception("Track table not found");
            }

            var rgx_track     = new Regex(@"\<tr\>\<td .*?\>(?<disc_number>[0-9]+)\<\/td\>\<td .*?\>(?<track_number>[0-9]+)\<\/td\>\<td .*?\>\<div\>\<strong\>\<a href=\""(?<url>.*?)\""\>(?<title>.*?)\<\/a\>\<\/strong\>\<\/div\>\<\/td\>\<td .*?\>(?<duration>[0-9\:]+)\<\/td\>\<td .*?\>.*?\<\/td\>\<\/tr\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var m_tracks      = rgx_track.Matches(m_table.Groups["rows"].Value);
            var track_matches = new Match[m_tracks.Count];

            m_tracks.CopyTo(track_matches, 0);

            return(track_matches.Select(m => new Song
            {
                Id = Convert.ToInt32(m.Groups["url"].Value.Split('/').Reverse().ElementAt(1)),
                Url = "https://www.lyrics.com" + m.Groups["url"].Value,
                Title = m.Groups["title"].Value
            }));
        }
Example #26
0
        private List <Data.Album> ExtractArtistAlbums(string html)
        {
            var albumsRegex   = new Regex(@"\<h3\>Albums\<\/h3\>\s*\<ul class\=\""list-unstyled\""\>(?<lis>.*?)\<\/ul\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var albumsSection = albumsRegex.Match(html).Groups["lis"].Value;

            var albumRegex      = new Regex(@"\<a href=\""(?<url>.*?)\"">(?<name>.*?)\s*\((?<released>[^)]+)\)<\/a\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var albumMatches    = albumRegex.Matches(albumsSection);
            var arrAlbumMatches = new Match[albumMatches.Count];

            albumMatches.CopyTo(arrAlbumMatches, 0);

            return(arrAlbumMatches.Select(m =>
            {
                var parts = m.Groups["url"].Value.Split('/');
                return new Data.Album
                {
                    Id = Convert.ToInt32(parts[parts.Length - 3]),
                    Url = m.Groups["url"].Value,
                    Name = m.Groups["name"].Value,
                    Released = DateTime.ParseExact(m.Groups["released"].Value, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture)
                };
            }).ToList());
        }
        private List <Classes.Song> ExtractArtistSongs(string html)
        {
            var h1Regex = new Regex(@"\<\/h1\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var main    = h1Regex.Split(html)[1];

            var ulRegex    = new Regex(@"\<ul class\=\""list-unstyled\""\>(?<lis>.*?)\<\/ul\>", RegexOptions.Singleline | RegexOptions.Multiline);
            var songsMatch = ulRegex.Match(main).Groups["lis"];

            var songRegex       = new Regex(@"\<a href=\""(?<url>.*?)\"">(?<title>.*?)\<\/a\>");
            var songMatches     = songRegex.Matches(songsMatch.Value);
            var arrSongsMatches = new Match[songMatches.Count];

            songMatches.CopyTo(arrSongsMatches, 0);

            return(arrSongsMatches.Select(m => {
                var parts = m.Groups["url"].Value.Split('/');
                return new Classes.Song
                {
                    Id = Convert.ToInt32(parts[parts.Length - 3]),
                    Title = m.Groups["title"].Value,
                    Url = m.Groups["url"].Value
                };
            }).ToList());
        }