Beispiel #1
0
        public ReadOnlyCollection <LyricItem> Search(String keyword, LyricSearchType type, Int32?page)
        {
            List <LyricItem> lyricItems = new List <LyricItem>();

            Dictionary <String, String> query = new Dictionary <String, String>();

            switch (type)
            {
            case LyricSearchType.BySongName:
            {
                query.Add("kt", keyword);
                break;
            }

            case LyricSearchType.ByArtist:
            {
                query.Add("ka", keyword);
                break;
            }

            case LyricSearchType.ByLyric:
            {
                query.Add("kl", keyword);
                break;
            }

            default:
                break;
            }

            query.Add("ct", "2");

            if (page != null)
            {
                query.Add("p", page.ToString());
            }

            List <dynamic> results = new List <dynamic>();
            String         html    = WebOperations.GetContentAsString(JLyricProvider.QueryURI.ToString(), query, Encoding.UTF8);

            if (type == LyricSearchType.ByArtist)
            {
                foreach (Match match in JLyricProvider.ArtistSearchParseRegex.Matches(html))
                {
                    html = WebOperations.GetContentAsString(match.Groups["ArtistURL"].Value, Encoding.UTF8);

                    results.AddRange(JLyricProvider.ArtistSongSearchParseRegex.Matches(html)
                                     .OfType <Match>()
                                     .Select(m => new
                    {
                        Title  = m.Groups["SongTitle"].Value,
                        Artist = match.Groups["ArtistName"].Value,
                        URL    = JLyricProvider.RootURI.GetLeftPart(UriPartial.Authority) + match.Groups["SongRelativeURL"].Value
                    }));
                }
            }
            else
            {
                results.AddRange(JLyricProvider.SongSearchParseRegex.Matches(html)
                                 .OfType <Match>()
                                 .Select(m => new
                {
                    Title  = m.Groups["SongTitle"].Value,
                    Artist = m.Groups["SongArtist"].Value,
                    URL    = m.Groups["SongURL"].Value
                }));
            }

            foreach (dynamic r in results)
            {
                String songName   = r.Title;
                String songArtist = r.Artist;
                Uri    uri        = new Uri(r.URL);

                lyricItems.Add(new LyricItem(songName, songArtist, this, uri));
            }

            return(lyricItems.AsReadOnly());
        }
Beispiel #2
0
 public ReadOnlyCollection <LyricItem> Search(String keyword, LyricSearchType type)
 {
     return(this.Search(keyword, type, null));
 }