♻️ Add custom http functions so that User-Agent is always sent

This commit is contained in:
Dan Jones 2023-09-24 15:26:26 -05:00
commit 2208b1de55
3 changed files with 62 additions and 15 deletions

View file

@ -4,9 +4,9 @@ import (
"encoding/json"
"fmt"
"io"
"net/http"
u "net/url"
"codeberg.org/danjones000/strip-beats/config"
h "codeberg.org/danjones000/strip-beats/utils/http"
)
type MbRecording struct {
@ -77,17 +77,9 @@ func GetMbRecording(id string) (MbRecording, error) {
func FillMbRecording(rec *MbRecording) error {
url := fmt.Sprintf("https://musicbrainz.org/ws/2/recording/%s", rec.Id)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return err
}
q := req.URL.Query()
q.Add("fmt", "json")
q.Add("inc", "releases+media+artist-credits+isrcs+genres")
req.URL.RawQuery = q.Encode()
req.Header.Set("User-Agent", config.UserAgent)
resp, err := http.DefaultClient.Do(req)
resp, err := h.GetWithQuery(url, u.Values{
"fmt": []string{"json"},
"inc": []string{"releases+media+artist-credits+isrcs+genres"}})
if err != nil {
return err
}