Skip to content

Commit eb8de16

Browse files
upgrade Lyric API
1 parent f98a1ae commit eb8de16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+60799
-31
lines changed

go.mod

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
module github.com/kylegrantlucas/lyricpiece
22

3-
go 1.14
3+
go 1.19
44

55
require (
66
github.com/andybrewer/mack v0.0.0-20200226161639-15be3d47cc54
7+
github.com/rhnvrm/lyric-api-go v0.1.4
78
gopkg.in/mattes/go-expand-tilde.v1 v1.0.0-20150330173918-cb884138e64c
89
)
10+
11+
require (
12+
github.com/PuerkitoBio/goquery v1.4.1 // indirect
13+
github.com/andybalholm/cascadia v1.0.0 // indirect
14+
github.com/gopherjs/gopherjs v1.17.2 // indirect
15+
github.com/gosimple/slug v1.2.0 // indirect
16+
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be // indirect
17+
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect
18+
)

go.sum

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
1+
github.com/PuerkitoBio/goquery v1.4.1 h1:smcIRGdYm/w7JSbcdeLHEMzxmsBQvl8lhf0dSw2nzMI=
2+
github.com/PuerkitoBio/goquery v1.4.1/go.mod h1:T9ezsOHcCrDCgA8aF1Cqr3sSYbO/xgdy8/R/XiIMAhA=
3+
github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRySc45o=
4+
github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
15
github.com/andybrewer/mack v0.0.0-20200226161639-15be3d47cc54 h1:uZMWs9VZiUv6J6gHdlDUA4Y11ckPLe+qYagoHfQb6BY=
26
github.com/andybrewer/mack v0.0.0-20200226161639-15be3d47cc54/go.mod h1:unYm1XWSUgGRVv0MaRe3DFEGh2OEcUQ/sFSGxXjXBfI=
7+
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
8+
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
9+
github.com/gosimple/slug v1.2.0 h1:DqQXHQLprYBsiO4ZtdadqBeKh7CFnl5qoVNkKkVI7No=
10+
github.com/gosimple/slug v1.2.0/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0=
11+
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
12+
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
13+
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be h1:ta7tUOvsPHVHGom5hKW5VXNc2xZIkfCKP8iaqOyYtUQ=
14+
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be/go.mod h1:MIDFMn7db1kT65GmV94GzpX9Qdi7N/pQlwb+AN8wh+Q=
15+
github.com/rhnvrm/lyric-api-go v0.1.4 h1:E3n6+H4PyVJCesc3NNIbLxKlFpyMVDiq2niKSZK7K1s=
16+
github.com/rhnvrm/lyric-api-go v0.1.4/go.mod h1:mxXSk7lWgck4BEMLsOgse2AiE+qoXIc9mcfxF2YQCHs=
17+
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
18+
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
19+
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a h1:JSvGDIbmil4Ui/dDdFBExb7/cmkNjyX5F97oglmvCDo=
20+
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
21+
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
22+
golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
23+
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d h1:LO7XpTYMwTqxjLcGWPijK3vRXg1aWdlNOVOHRq45d7c=
24+
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
325
gopkg.in/mattes/go-expand-tilde.v1 v1.0.0-20150330173918-cb884138e64c h1:/Onz8dZtKBCmB8P0JU7+WSCfMekXry7BflVO0SQQrCU=
426
gopkg.in/mattes/go-expand-tilde.v1 v1.0.0-20150330173918-cb884138e64c/go.mod h1:j6QavCO5cYWud1+2/PFTXL1y6tjjkhSs+qcWgibOIc0=

main.go

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import (
44
"fmt"
55
"io/ioutil"
66
"math/rand"
7-
"net/http"
87
"os"
98
"strings"
109
"sync"
1110
"time"
1211

1312
"github.com/andybrewer/mack"
13+
lyrics "github.com/rhnvrm/lyric-api-go"
1414
tilde "gopkg.in/mattes/go-expand-tilde.v1"
1515
)
1616

@@ -19,7 +19,7 @@ func main() {
1919

2020
lyrics, err := getLyrics(song)
2121
if err != nil {
22-
panic(err)
22+
fmt.Fprintln(os.Stderr, err)
2323
}
2424

2525
lyricPiece := getRandomLyricPiece(lyrics)
@@ -114,36 +114,11 @@ func fileExists(filename string) bool {
114114
}
115115

116116
func queryLyrics(song Song) (string, error) {
117-
req, err := http.NewRequest("GET", "https://makeitpersonal.co/lyrics", nil)
117+
l := lyrics.New()
118+
lyric, err := l.Search(song.Artist, song.Title)
118119
if err != nil {
119120
return "", err
120121
}
121122

122-
q := req.URL.Query()
123-
q.Add("artist", song.Artist)
124-
q.Add("title", song.Title)
125-
req.URL.RawQuery = q.Encode()
126-
127-
timeout := time.Duration(5 * time.Second)
128-
client := http.Client{
129-
Timeout: timeout,
130-
}
131-
132-
resp, err := client.Do(req)
133-
if err != nil {
134-
return "", err
135-
}
136-
137-
defer resp.Body.Close()
138-
139-
body, err := ioutil.ReadAll(resp.Body)
140-
if err != nil {
141-
return "", err
142-
}
143-
144-
if strings.TrimSpace(string(body)) == "Sorry, We don't have lyrics for this song yet. Add them to https://lyrics.wikia.com" {
145-
return "", nil
146-
}
147-
148-
return string(body), nil
123+
return lyric, nil
149124
}

vendor/github.com/PuerkitoBio/goquery/.gitattributes

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/PuerkitoBio/goquery/.gitignore

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/PuerkitoBio/goquery/.travis.yml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/PuerkitoBio/goquery/LICENSE

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/PuerkitoBio/goquery/README.md

Lines changed: 177 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)