예제 #1
0
        public LyricContent Retrieve(LyricItem item)
        {
            if (item.Provider.Name != this.Name)
            {
                throw new NotSupportedException("The lyric item data was not from the current provider.");
            }

            String html = WebOperations.GetContentAsString(item.URI.ToString(), Encoding.UTF8);

            Match match = JLyricProvider.LyricParseRegex.Match(html);

            String title    = item.SongTitle;
            String artist   = item.SongArtist;
            String writer   = match.Groups["Writer"].Value;
            String composer = match.Groups["Composer"].Value;

            String[] lyric = match.Groups["Lyric"].Value.Split(new String[] { "<br>" }, StringSplitOptions.None);

            return(new LyricContent(title, artist, writer, composer, lyric, item));
        }
예제 #2
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());
        }