🚚 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

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"codeberg.org/danjones000/strip-beats/media" "codeberg.org/danjones000/strip-beats/media"
// "github.com/akrennmair/slice" "codeberg.org/danjones000/strip-beats/media/brainz"
) )
func print() { func print() {
@ -19,10 +19,10 @@ func print() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
var recs []media.MbRecording var recs []brainz.Recording
for _, res := range ids.Results { for _, res := range ids.Results {
for _, rec := range res.Recordings { for _, rec := range res.Recordings {
err = media.FillMbRecording(&rec) err = brainz.FillRecording(&rec)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View file

@ -6,6 +6,7 @@ import (
"codeberg.org/danjones000/strip-beats/input/boolean" "codeberg.org/danjones000/strip-beats/input/boolean"
"codeberg.org/danjones000/strip-beats/media" "codeberg.org/danjones000/strip-beats/media"
"codeberg.org/danjones000/strip-beats/media/brainz"
) )
type AppStep int type AppStep int
@ -41,7 +42,7 @@ func testFp() {
func testMb() { func testMb() {
id := "497f2f22-809b-4c9e-a692-72f7d8dcaaa2" id := "497f2f22-809b-4c9e-a692-72f7d8dcaaa2"
mb, err := media.GetMbRecording(id) mb, err := brainz.GetRecording(id)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -57,7 +58,6 @@ func testPrint() {
} }
func Run(step AppStep) { func Run(step AppStep) {
// testMb()
testPrint() testPrint()
for step < Quit { for step < Quit {
switch step { switch step {

1
go.mod
View file

@ -8,6 +8,7 @@ require (
github.com/adrg/xdg v0.4.0 github.com/adrg/xdg v0.4.0
github.com/akrennmair/slice v0.0.0-20220105203817-49445747ab81 github.com/akrennmair/slice v0.0.0-20220105203817-49445747ab81
github.com/creack/pty v1.1.18 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/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
github.com/rivo/tview v0.0.0-20230826224341-9754ab44dc1c github.com/rivo/tview v0.0.0-20230826224341-9754ab44dc1c
github.com/rkoesters/xdg v0.0.1 github.com/rkoesters/xdg v0.0.1

1
go.sum
View file

@ -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/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= 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/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/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/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=

View file

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

View file

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