Skip to content

Commit

Permalink
yes
Browse files Browse the repository at this point in the history
  • Loading branch information
milindmadhukar committed Apr 22, 2024
1 parent 59e67e5 commit d297329
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Go-Musixmatch!

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

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

*All of the API endpoints are covered except the premium ones.*

_All of the API endpoints are covered except the premium ones._

## 💻 Installation

To install the library simply open a terminal and type:

```
go get github.com/milindmadhukar/go-musixmatch
```
Expand All @@ -21,15 +21,15 @@ go get github.com/milindmadhukar/go-musixmatch
This project was written purely in `Golang` for `Golang`.</br>
The module helps with the usage of the [Musixmatch](https://developer.musixmatch.com/documentation) API.

## ⛏️ Acquiring Musixmatch API Key.
## ⛏️ Acquiring Musixmatch API Key.

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


## 🏁 Basic Setup:

For all the endpoints and parameters that can be used, check the [Musixmatch API docs](https://developer.musixmatch.com/documentation)

```go
Expand Down Expand Up @@ -60,15 +60,17 @@ func main() {
```

### Output

```go
{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}
```

## Missing Features / Known Bugs
_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._

_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._

#### Unimplemented Endpoints

- <a href="https://developer.musixmatch.com/documentation/api-reference/track-lyrics-post" target="_blank">track.lyrics.post</a>
- <a href="https://developer.musixmatch.com/documentation/api-reference/track-lyrics-mood-get" target="_blank">track.lyrics.mood.get</a>
- <a href="https://developer.musixmatch.com/documentation/api-reference/track-richsync-get" target="_blank">track.richsync.get</a>
Expand All @@ -81,8 +83,6 @@ _These features are not implemented as they are premium users only and give me a
- <a href="https://developer.musixmatch.com/documentation/api-reference/track-subtitle-get" target="_blank">track.subtitle.get</a>
- <a href="https://developer.musixmatch.com/documentation/api-reference/matcher-subtitle-get" target="_blank">matcher.subtitle.get</a>



## 🧿 Extras

_There is supposed to be something here idk_
Expand Down
3 changes: 1 addition & 2 deletions musixmatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func (client *Client) get(ctx context.Context, endpoint string, response interfa
return err
}


fmt.Println(url)
// fmt.Println(url)

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
Expand Down
26 changes: 12 additions & 14 deletions musixmatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package gomusixmatch_test
import (
"context"
"net/http"
"os"
"testing"

musixmatch "github.com/milindmadhukar/go-musixmatch"
"github.com/milindmadhukar/go-musixmatch/params"
)


var client = musixmatch.New(os.Getenv("MUSIXMATCH_API_KEY"), http.DefaultClient)
var client = musixmatch.New(musixmatch.GetApiKeyFromEnvFile(".env"), http.DefaultClient)

// INFO: Martin Garrix Musixmatch ID : 24407895
// INFO: AREA21 Musixmatch ID : 50722792
Expand Down Expand Up @@ -95,15 +93,15 @@ func TestSearchArtist(t *testing.T) {
t.Error(err.Error())
}

// Get names
// Get names

var artist_names []string
var artist_names []string

for _, artist := range artists {
artist_names = append(artist_names, artist.Name)
}
for _, artist := range artists {
artist_names = append(artist_names, artist.Name)
}

presentInSlice(artist_names, "Martin Garrix", t)
presentInSlice(artist_names, "Martin Garrix", t)

}

Expand Down Expand Up @@ -168,13 +166,13 @@ func TestSearchTrack(t *testing.T) {
t.Error(err.Error())
}

var track_names []string
var track_names []string

for _, track := range tracks {
track_names = append(track_names, track.Name)
}
for _, track := range tracks {
track_names = append(track_names, track.Name)
}

presentInSlice(track_names, "High On Life", t)
presentInSlice(track_names, "High On Life", t)

}

Expand Down
23 changes: 23 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package gomusixmatch

import (
"net/url"
"os"
"strings"

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

return musixMatchUrl, nil
}

func GetApiKeyFromEnvFile(filename string) string {

file, err := os.ReadFile(filename)
if err != nil {
panic(err)
}

content := string(file)
lines := strings.Split(content, "\n")

for _, line := range lines {

if strings.Contains(line, "MUSIXMATCH_API_KEY") {
apiKey := strings.Split(line, "=")
return apiKey[1]
}
}

panic("API Key not found in the file")
}

0 comments on commit d297329

Please sign in to comment.