From 4c5c46a5f2a0720d0946543a1747eb5d6ea6b798 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 24 Sep 2023 16:40:24 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20Move=20brainz=20to=20own=20packa?= =?UTF-8?q?ge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/print.go | 6 ++-- app/run.go | 4 +-- go.mod | 1 + go.sum | 1 + media/{ => brainz}/brainz.go | 61 +++++++++++++++++++----------------- media/fingerprint.go | 3 +- 6 files changed, 42 insertions(+), 34 deletions(-) rename media/{ => brainz}/brainz.go (55%) diff --git a/app/print.go b/app/print.go index a815206..7ce26dc 100644 --- a/app/print.go +++ b/app/print.go @@ -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) } diff --git a/app/run.go b/app/run.go index 710e23c..a42b1ab 100644 --- a/app/run.go +++ b/app/run.go @@ -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 { diff --git a/go.mod b/go.mod index 79e4e26..093ef9b 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index e14acfe..6e6d58e 100644 --- a/go.sum +++ b/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= diff --git a/media/brainz.go b/media/brainz/brainz.go similarity index 55% rename from media/brainz.go rename to media/brainz/brainz.go index 4a4637f..da9d999 100644 --- a/media/brainz.go +++ b/media/brainz/brainz.go @@ -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"}, diff --git a/media/fingerprint.go b/media/fingerprint.go index 2fed139..2b4d1ad 100644 --- a/media/fingerprint.go +++ b/media/fingerprint.go @@ -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 {