func NewRecordFromId(id string) (*Record, error) { var doc *goquery.Document var e error recordUrl := fmt.Sprintf("http://boomkat.com/downloads/%s", id) if doc, e = goquerywrapper.NewDocument(recordUrl); e != nil { return nil, e } var coverUrl string if val, ok := doc.Find("div#main-image img").Attr("src"); ok { coverUrl = val } record := &Record{ Id: id, Artist: doc.Find("h1.product-header-artist-value").Text(), Title: doc.Find("h1.product-header-title").Text(), Label: doc.Find("div#product-header-label").Text(), Genre: GenresFromString(doc.Find("div#product-header-genre a").Text()), //Thumbnail Review: doc.Find("div#product-description-text").Text(), PageUrl: recordUrl, // ??? CoverUrl: coverUrl, } return record, nil }
func Search(word string) ([]*Record, error) { var doc *goquery.Document var e error // TODO: urlEncode "word" searchUrl := fmt.Sprintf("http://boomkat.com/search?q=%s", url.QueryEscape(word)) if doc, e = goquerywrapper.NewDocument(searchUrl); e != nil { return nil, e } elmRecords := doc.Find(".line") records := make([]*Record, elmRecords.Length()) elmRecords.Each(func(i int, s *goquery.Selection) { var artist, title, label, review string var recordUrl, coverUrl string if val, ok := s.Find("div.image a img").Attr("src"); ok { coverUrl = val } meta := s.Find(".meta") artist = meta.Find("h4").Text() if val, ok := meta.Find("h4 a").Attr("href"); ok { recordUrl = val } var recordId string if reId.MatchString(recordUrl) { recordId = reId.FindStringSubmatch(recordUrl)[1] } title = meta.Find("p:nth-of-type(1)").Text() label = meta.Find("p:nth-of-type(2)").Text() // TODO: format genres := GenresFromString(meta.Find("p:nth-of-type(4)").Text()) review = s.Find("div.review").Text() records[i] = &Record{ Id: recordId, Artist: artist, Title: title, Label: label, Genre: genres, // TODO: Thumbnail Review: review, PageUrl: recordUrl, CoverUrl: coverUrl, } }) return records, nil }
func (r *Record) moreRecords(cssQuery string) ([]*Record, error) { var doc *goquery.Document var e error if doc, e = goquerywrapper.NewDocument(r.PageUrl); e != nil { return nil, e } elmRecords := doc.Find(fmt.Sprintf("%s div.data div.meta", cssQuery)) records := make([]*Record, elmRecords.Length()) elmRecords.Each(func(i int, s *goquery.Selection) { artist := s.Find("p.artist").Text() title := s.Find("p.title").Text() label := s.Find("p.label").Text() var recordUrl, recordId string if val, ok := s.Find("p.artist a").Attr("href"); ok { recordUrl = val } if reId.MatchString(recordUrl) { recordId = reId.FindStringSubmatch(recordUrl)[1] } records[i] = &Record{ Id: recordId, Artist: artist, Title: title, Label: label, PageUrl: recordUrl, } }) elmRecords = doc.Find(fmt.Sprintf("%s div.image.medium a img", cssQuery)) elmRecords.Each(func(i int, s *goquery.Selection) { var coverUrl string if val, ok := s.Attr("src"); ok { coverUrl = val } records[i].CoverUrl = coverUrl }) return records, nil }