🚚 Move brainz to own package
This commit is contained in:
parent
2208b1de55
commit
4c5c46a5f2
6 changed files with 42 additions and 34 deletions
|
|
@ -1,94 +0,0 @@
|
|||
package media
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
u "net/url"
|
||||
|
||||
h "codeberg.org/danjones000/strip-beats/utils/http"
|
||||
)
|
||||
|
||||
type MbRecording struct {
|
||||
Id string
|
||||
Isrcs []string
|
||||
FirstReleaseDate string `json:"first-release-date"`
|
||||
Length int
|
||||
Title string
|
||||
Video bool
|
||||
Releases []MbRelease
|
||||
Genres []MbGenre
|
||||
}
|
||||
|
||||
type MbGenre struct {
|
||||
Id string
|
||||
Name string
|
||||
}
|
||||
|
||||
type MbRelease struct {
|
||||
Id string
|
||||
Country string
|
||||
Date string
|
||||
Media []MbMedia
|
||||
Status string
|
||||
StatusId string `json:"status-id"`
|
||||
ArtistCredit []MbArtistCredit `json:"artist-credit"`
|
||||
Title string
|
||||
Genres []MbGenre
|
||||
// ReleaseEvents []MbReleaseEvent `json:"release-events"`
|
||||
}
|
||||
|
||||
type MbArtistCredit struct {
|
||||
Name string
|
||||
Artist MbArtist
|
||||
}
|
||||
|
||||
type MbArtist struct {
|
||||
Id string
|
||||
Name string
|
||||
TypeId string `json:"type-id"`
|
||||
Type string
|
||||
SortName string `json:"sort-name"`
|
||||
Genres []MbGenre
|
||||
}
|
||||
|
||||
type MbMedia struct {
|
||||
FormatId string `json:"format-id"`
|
||||
Position int
|
||||
TrackOffset int `json:"track-offset"`
|
||||
Format string
|
||||
TrackCount int `json:"track-count"`
|
||||
Tracks []MbTrack
|
||||
}
|
||||
|
||||
type MbTrack struct {
|
||||
Id string
|
||||
Number string
|
||||
Title string
|
||||
Position int
|
||||
Length int
|
||||
}
|
||||
|
||||
func GetMbRecording(id string) (MbRecording, error) {
|
||||
rec := MbRecording{Id: id}
|
||||
err := FillMbRecording(&rec)
|
||||
return rec, err
|
||||
}
|
||||
|
||||
func FillMbRecording(rec *MbRecording) error {
|
||||
url := fmt.Sprintf("https://musicbrainz.org/ws/2/recording/%s", rec.Id)
|
||||
resp, err := h.GetWithQuery(url, u.Values{
|
||||
"fmt": []string{"json"},
|
||||
"inc": []string{"releases+media+artist-credits+isrcs+genres"}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = json.Unmarshal(body, rec)
|
||||
|
||||
return err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue