Skip to content

Commit d297329

Browse files
yes
1 parent 59e67e5 commit d297329

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Go-Musixmatch!
32

43
This is a Go wrapper for working with the [Musixmatch](https://www.musixmatch.com/) API.
@@ -7,11 +6,12 @@ Documentation can be found at: [Go-Musixmatch Documentation](https://pkg.go.dev/
76

87
It aims to support every task listed in the Web API Endpoint Reference, located [here](https://developer.musixmatch.com/documentation).
98

10-
*All of the API endpoints are covered except the premium ones.*
11-
9+
_All of the API endpoints are covered except the premium ones._
1210

1311
## 💻 Installation
12+
1413
To install the library simply open a terminal and type:
14+
1515
```
1616
go get github.com/milindmadhukar/go-musixmatch
1717
```
@@ -21,15 +21,15 @@ go get github.com/milindmadhukar/go-musixmatch
2121
This project was written purely in `Golang` for `Golang`.</br>
2222
The module helps with the usage of the [Musixmatch](https://developer.musixmatch.com/documentation) API.
2323

24-
## ⛏️ Acquiring Musixmatch API Key.
24+
## ⛏️ Acquiring Musixmatch API Key.
2525

2626
1. Go to the [Musixmatch Developer Page](https://developer.musixmatch.com/plans) and select a plan.
2727
1. Fill in the necessary details to create an account and verify it from your email.
2828
1. Go to your [Account Dashboard](https://developer.musixmatch.com/admin/applications) and you should see an API Key.
2929
1. Note the API Key down and don't reveal it to anyone.
3030

31-
3231
## 🏁 Basic Setup:
32+
3333
For all the endpoints and parameters that can be used, check the [Musixmatch API docs](https://developer.musixmatch.com/documentation)
3434

3535
```go
@@ -60,15 +60,17 @@ func main() {
6060
```
6161

6262
### Output
63+
6364
```go
6465
{24407895 Martin Garrix [91 93] NL [{MARTIJN GARRITSEN}] 67 {[]} 0 2017-02-03 07:02:12 +0000 UTC 1996 1996-05-15 0000-00-00}
6566
```
6667

6768
## Missing Features / Known Bugs
68-
_These features are not implemented as they are premium users only and give me a 401. If you have access to the endpoints and would like to contribute, please open a PR._
6969

70+
_These features are not implemented as they are premium users only and give me a 401. If you have access to the endpoints and would like to contribute, please open a PR._
7071

7172
#### Unimplemented Endpoints
73+
7274
- <a href="https://developer.musixmatch.com/documentation/api-reference/track-lyrics-post" target="_blank">track.lyrics.post</a>
7375
- <a href="https://developer.musixmatch.com/documentation/api-reference/track-lyrics-mood-get" target="_blank">track.lyrics.mood.get</a>
7476
- <a href="https://developer.musixmatch.com/documentation/api-reference/track-richsync-get" target="_blank">track.richsync.get</a>
@@ -81,8 +83,6 @@ _These features are not implemented as they are premium users only and give me a
8183
- <a href="https://developer.musixmatch.com/documentation/api-reference/track-subtitle-get" target="_blank">track.subtitle.get</a>
8284
- <a href="https://developer.musixmatch.com/documentation/api-reference/matcher-subtitle-get" target="_blank">matcher.subtitle.get</a>
8385

84-
85-
8686
## 🧿 Extras
8787

8888
_There is supposed to be something here idk_

musixmatch.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ func (client *Client) get(ctx context.Context, endpoint string, response interfa
4040
return err
4141
}
4242

43-
44-
fmt.Println(url)
43+
// fmt.Println(url)
4544

4645
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
4746
if err != nil {

musixmatch_test.go

+12-14
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ package gomusixmatch_test
33
import (
44
"context"
55
"net/http"
6-
"os"
76
"testing"
87

98
musixmatch "github.com/milindmadhukar/go-musixmatch"
109
"github.com/milindmadhukar/go-musixmatch/params"
1110
)
1211

13-
14-
var client = musixmatch.New(os.Getenv("MUSIXMATCH_API_KEY"), http.DefaultClient)
12+
var client = musixmatch.New(musixmatch.GetApiKeyFromEnvFile(".env"), http.DefaultClient)
1513

1614
// INFO: Martin Garrix Musixmatch ID : 24407895
1715
// INFO: AREA21 Musixmatch ID : 50722792
@@ -95,15 +93,15 @@ func TestSearchArtist(t *testing.T) {
9593
t.Error(err.Error())
9694
}
9795

98-
// Get names
96+
// Get names
9997

100-
var artist_names []string
98+
var artist_names []string
10199

102-
for _, artist := range artists {
103-
artist_names = append(artist_names, artist.Name)
104-
}
100+
for _, artist := range artists {
101+
artist_names = append(artist_names, artist.Name)
102+
}
105103

106-
presentInSlice(artist_names, "Martin Garrix", t)
104+
presentInSlice(artist_names, "Martin Garrix", t)
107105

108106
}
109107

@@ -168,13 +166,13 @@ func TestSearchTrack(t *testing.T) {
168166
t.Error(err.Error())
169167
}
170168

171-
var track_names []string
169+
var track_names []string
172170

173-
for _, track := range tracks {
174-
track_names = append(track_names, track.Name)
175-
}
171+
for _, track := range tracks {
172+
track_names = append(track_names, track.Name)
173+
}
176174

177-
presentInSlice(track_names, "High On Life", t)
175+
presentInSlice(track_names, "High On Life", t)
178176

179177
}
180178

utils.go

+23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package gomusixmatch
22

33
import (
44
"net/url"
5+
"os"
6+
"strings"
57

68
mxmParams "github.com/milindmadhukar/go-musixmatch/params"
79
)
@@ -25,3 +27,24 @@ func processParams(musixMatchUrl string, params ...mxmParams.Param) (string, err
2527

2628
return musixMatchUrl, nil
2729
}
30+
31+
func GetApiKeyFromEnvFile(filename string) string {
32+
33+
file, err := os.ReadFile(filename)
34+
if err != nil {
35+
panic(err)
36+
}
37+
38+
content := string(file)
39+
lines := strings.Split(content, "\n")
40+
41+
for _, line := range lines {
42+
43+
if strings.Contains(line, "MUSIXMATCH_API_KEY") {
44+
apiKey := strings.Split(line, "=")
45+
return apiKey[1]
46+
}
47+
}
48+
49+
panic("API Key not found in the file")
50+
}

0 commit comments

Comments
 (0)