🚚 Move brainz to own package
This commit is contained in:
parent
2208b1de55
commit
4c5c46a5f2
6 changed files with 42 additions and 34 deletions
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"codeberg.org/danjones000/strip-beats/media"
|
||||
// "github.com/akrennmair/slice"
|
||||
"codeberg.org/danjones000/strip-beats/media/brainz"
|
||||
)
|
||||
|
||||
func print() {
|
||||
|
|
@ -19,10 +19,10 @@ func print() {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var recs []media.MbRecording
|
||||
var recs []brainz.Recording
|
||||
for _, res := range ids.Results {
|
||||
for _, rec := range res.Recordings {
|
||||
err = media.FillMbRecording(&rec)
|
||||
err = brainz.FillRecording(&rec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"codeberg.org/danjones000/strip-beats/input/boolean"
|
||||
"codeberg.org/danjones000/strip-beats/media"
|
||||
"codeberg.org/danjones000/strip-beats/media/brainz"
|
||||
)
|
||||
|
||||
type AppStep int
|
||||
|
|
@ -41,7 +42,7 @@ func testFp() {
|
|||
|
||||
func testMb() {
|
||||
id := "497f2f22-809b-4c9e-a692-72f7d8dcaaa2"
|
||||
mb, err := media.GetMbRecording(id)
|
||||
mb, err := brainz.GetRecording(id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
@ -57,7 +58,6 @@ func testPrint() {
|
|||
}
|
||||
|
||||
func Run(step AppStep) {
|
||||
// testMb()
|
||||
testPrint()
|
||||
for step < Quit {
|
||||
switch step {
|
||||
|
|
|
|||
1
go.mod
1
go.mod
|
|
@ -8,6 +8,7 @@ require (
|
|||
github.com/adrg/xdg v0.4.0
|
||||
github.com/akrennmair/slice v0.0.0-20220105203817-49445747ab81
|
||||
github.com/creack/pty v1.1.18
|
||||
github.com/google/uuid v1.1.1
|
||||
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
|
||||
github.com/rivo/tview v0.0.0-20230826224341-9754ab44dc1c
|
||||
github.com/rkoesters/xdg v0.0.1
|
||||
|
|
|
|||
1
go.sum
1
go.sum
|
|
@ -23,6 +23,7 @@ github.com/gdamore/tcell/v2 v2.6.0/go.mod h1:be9omFATkdr0D9qewWW3d+MEvl5dha+Etb5
|
|||
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
|
||||
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
|
|
|
|||
|
|
@ -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"},
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue