🚚 Move brainz to own package

This commit is contained in:
Dan Jones 2023-09-24 16:40:24 -05:00
commit 4c5c46a5f2
6 changed files with 42 additions and 34 deletions

View file

@ -1,4 +1,4 @@
package media
package brainz
import (
"encoding/json"
@ -7,75 +7,80 @@ import (
u "net/url"
h "codeberg.org/danjones000/strip-beats/utils/http"
"github.com/google/uuid"
)
type MbRecording struct {
Id string
type Recording struct {
Id uuid.UUID
Isrcs []string
FirstReleaseDate string `json:"first-release-date"`
Length int
Title string
Video bool
Releases []MbRelease
Genres []MbGenre
Releases []Release
Genres []Genre
}
type MbGenre struct {
Id string
type Genre struct {
Id uuid.UUID
Name string
}
type MbRelease struct {
Id string
type Release struct {
Id uuid.UUID
Country string
Date string
Media []MbMedia
Media []Media
Status string
StatusId string `json:"status-id"`
ArtistCredit []MbArtistCredit `json:"artist-credit"`
StatusId uuid.UUID `json:"status-id"`
ArtistCredit []ArtistCredit `json:"artist-credit"`
Title string
Genres []MbGenre
// ReleaseEvents []MbReleaseEvent `json:"release-events"`
Genres []Genre
// ReleaseEvents []ReleaseEvent `json:"release-events"`
}
type MbArtistCredit struct {
type ArtistCredit struct {
Name string
Artist MbArtist
Artist Artist
}
type MbArtist struct {
Id string
type Artist struct {
Id uuid.UUID
Name string
TypeId string `json:"type-id"`
Type string
SortName string `json:"sort-name"`
Genres []MbGenre
Genres []Genre
}
type MbMedia struct {
FormatId string `json:"format-id"`
type Media struct {
FormatId uuid.UUID `json:"format-id"`
Position int
TrackOffset int `json:"track-offset"`
Format string
TrackCount int `json:"track-count"`
Tracks []MbTrack
Tracks []Track
}
type MbTrack struct {
Id string
type Track struct {
Id uuid.UUID
Number string
Title string
Position int
Length int
}
func GetMbRecording(id string) (MbRecording, error) {
rec := MbRecording{Id: id}
err := FillMbRecording(&rec)
func GetRecording(id string) (Recording, error) {
u, err := uuid.Parse(id)
rec := Recording{Id: u}
if err != nil {
return rec, err
}
err = FillRecording(&rec)
return rec, err
}
func FillMbRecording(rec *MbRecording) error {
func FillRecording(rec *Recording) error {
url := fmt.Sprintf("https://musicbrainz.org/ws/2/recording/%s", rec.Id)
resp, err := h.GetWithQuery(url, u.Values{
"fmt": []string{"json"},

View file

@ -10,6 +10,7 @@ import (
"strings"
"codeberg.org/danjones000/strip-beats/config"
"codeberg.org/danjones000/strip-beats/media/brainz"
h "codeberg.org/danjones000/strip-beats/utils/http"
)
@ -46,7 +47,7 @@ type IdResults struct {
type IdResult struct {
Id string
Score float64
Recordings []MbRecording
Recordings []brainz.Recording
}
type IdError struct {