Browse Source

Fixing pointers

master
Delta503 7 months ago
parent
commit
9a8bed86f5
  1. 2
      .gitignore
  2. 6
      genius/fetch.go
  3. 6
      lyrics.go
  4. 2
      lyricswikia/fetch.go
  5. 2
      musixmatch/fetch.go
  6. 2
      songlyrics/fetch.go

2
.gitignore vendored

@ -7,6 +7,8 @@
# Test binary, build with `go test -c`
*.test
test/*
*test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

6
genius/fetch.go

@ -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)

6
lyrics.go

@ -11,7 +11,7 @@ import (
)
type provider interface {
Fetch(artist, song string, client *http.Client) string
Fetch(artist, song string, client http.Client) string
}
// Supported Providers:
@ -32,7 +32,7 @@ var (
// Lyric API.
type Lyric struct {
providers []provider
client *http.Client
client http.Client
}
// Option type describes Option Configuration Decorator return type.
@ -119,7 +119,7 @@ func WithoutProviders() Option {
//
// Eg. to attempt with both Lyrics Wikia and Song Lyrics:
// lyrics.New(WithoutProviders(), WithLyricsWikia(), WithSongLyrics())
func New(client *http.Client, o ...Option) Lyric {
func New(client http.Client, o ...Option) Lyric {
if len(o) == 0 {
return Lyric{
providers: defaultProviders,

2
lyricswikia/fetch.go

@ -18,7 +18,7 @@ func New() *LyricsWikia {
}
// Fetch scrapes Lyrics Wikia based on Artist and Song.
func (l *LyricsWikia) Fetch(artist, song string, client *http.Client) string {
func (l *LyricsWikia) Fetch(artist, song string, client http.Client) string {
url := "http://lyrics.wikia.com/wiki/" + artist + ":" + 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")

2
musixmatch/fetch.go

@ -18,7 +18,7 @@ func New() *MusixMatch {
}
// Fetch scrapes MusixMatch based on Artist and Song.
func (*MusixMatch) Fetch(artist, song string, client *http.Client) string {
func (*MusixMatch) Fetch(artist, song string, client http.Client) string {
url := "https://www.musixmatch.com/lyrics/" + formatURL(artist) + "/" + formatURL(song)
req, _ := http.NewRequest("GET", url, nil)

2
songlyrics/fetch.go

@ -19,7 +19,7 @@ func New() *SongLyrics {
}
// Fetch scrapes SongLyrics based on Artist and Song.
func (*SongLyrics) Fetch(artist, song string, client *http.Client) string {
func (*SongLyrics) Fetch(artist, song string, client http.Client) string {
url := "http://www.songlyrics.com/" + slug.Make(artist) + "/" + slug.Make(song) + "-lyrics/"
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")

Loading…
Cancel
Save