|
|
|
@ -26,7 +26,7 @@ func New(accessToken string) *Genius {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func search(artist, song, accessToken string, client *http.Client) (string, error) { |
|
|
|
|
func search(artist, song, accessToken string, client http.Client) (string, error) { |
|
|
|
|
url := "http://api.genius.com/search?access_token=" + accessToken + "&q=" + url.PathEscape(artist) + "-" + url.PathEscape(song) |
|
|
|
|
req, _ := http.NewRequest("GET", url, nil) |
|
|
|
|
req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0") |
|
|
|
@ -65,7 +65,7 @@ func parse(data io.Reader) (string, error) {
|
|
|
|
|
return "", errors.New("no song found") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func scrape(url string, client *http.Client) (string, error) { |
|
|
|
|
func scrape(url string, client http.Client) (string, error) { |
|
|
|
|
req, _ := http.NewRequest("GET", url, nil) |
|
|
|
|
req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0") |
|
|
|
|
// Make HTTP request
|
|
|
|
@ -88,7 +88,7 @@ func scrape(url string, client *http.Client) (string, error) {
|
|
|
|
|
|
|
|
|
|
// Fetch Searches Genius API based on Artist and Song. Then parses the result,
|
|
|
|
|
// to get a song and obtaines the url and scrapes it to return the lyrics.
|
|
|
|
|
func (g *Genius) Fetch(artist, song string, client *http.Client) string { |
|
|
|
|
func (g *Genius) Fetch(artist, song string, client http.Client) string { |
|
|
|
|
u, err := search(artist, song, g.accessToken, client) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Println("error in genius provider during search while attempting genius provider ", err) |
|
|
|
|