func refineAuthorsOrArtists(str dna.String) dna.StringArray { tmp := str.ToStringArray().SplitWithRegexp(` / `).SplitWithRegexp(` - `).SplitWithRegexp(` – `) tmp = tmp.SplitWithRegexp(`, `).SplitWithRegexp(` ft `).SplitWithRegexp(` feat `).SplitWithRegexp(` ft. `) tmp = tmp.SplitWithRegexp(` feat. `).SplitWithRegexp(` Feat. `).SplitWithRegexp(` Ft. `) tmp = tmp.SplitWithRegexp(` & `).SplitWithRegexp(` vs. `).SplitWithRegexp(`- `).SplitWithRegexp(` & `) tmp = dna.StringArray(tmp.Map(func(val dna.String, idx dna.Int) dna.String { rv := val.Replace(`Đang Cập Nhật...`, ``).Replace(`Đang Cập Nhật (QT)`, ``) rv = rv.Replace(`Đang Cập Nhật (VN)`, ``).Replace(`Nhạc Phim QT`, `Nhạc Phim Quốc Tế`) rv = rv.Replace(`Đang cập nhật`, ``).Replace(`Nhiều Ca Sỹ`, `Various Artists`) return rv }).([]dna.String)).Filter(func(val dna.String, idx dna.Int) dna.Bool { if val != "" { return true } else { return false } }) return tmp }
func GetSong(artist, title dna.String) (*Song, error) { link := "http://lyrics.wikia.com/" + artist.Replace(" ", "_") + ":" + title.Replace(" ", "_") result, err := http.Get(link) // Log(link) // Log(result.Data) song := NewSong() song.Title = title song.Artists = artist.ToStringArray() if err == nil { data := &result.Data if data.Match(`class='lyricbox'.+Instrumental.+TrebleClef`) == true { song.Lyric = "Instrumental" } lyricArr := data.FindAllStringSubmatch(`(?mis)<div class='lyricbox'>(.+?)<!--`, 1) if len(lyricArr) > 0 { song.Lyric = lyricArr[0][1].Trim().DecodeHTML().ReplaceWithRegexp(`(?mis)^<div.+?</span></div>`, "").Trim().Replace("<br />", "\n") } if song.Lyric == "" { song.DownloadDone = -1 } else { song.DownloadDone = 1 } musicBrainzArr := data.FindAllString(`http://musicbrainz.+html`, 1) if musicBrainzArr.Length() > 0 { song.MusicbrainzLink = musicBrainzArr[0] } allmusicArr := data.FindAllString(`http://www\.allmusic\.com.+`, 1) if allmusicArr.Length() > 0 { song.AllmusicLink = allmusicArr[0].ReplaceWithRegexp(`".+$`, "") } youtubeArr := data.FindAllString(`http://youtube\.com.+`, 1) if youtubeArr.Length() > 0 { song.YoutubeLink = youtubeArr[0].ReplaceWithRegexp(`".+$`, "") } if data.Match("View the Gracenote") { song.IsGracenote = "1" } languageArr := data.FindAllStringSubmatch(`category normal" data-name="Language/(.+)" data-namespace`, 1) if len(languageArr) > 0 { song.Language = languageArr[0][1] } albumArr := data.FindAllStringSubmatch(`appears on the album.+">(.+)</a></i>`, 1) if len(albumArr) > 0 { song.AlbumTitle = albumArr[0][1] } if song.AlbumTitle.Match(`[0-9]+`) { song.Year = song.AlbumTitle.FindAllStringSubmatch(`([0-9]+)`, 1)[0][1] } if data.Match(`It has been suggested that Gracenote`) { song.IsGracenote = "1" getGracenoteSongLyric(artist, title, song) } return song, nil } else { return nil, err } }