mirror of
https://github.com/gabehf/Koito.git
synced 2026-04-22 12:01:52 -07:00
feat: v0.0.8
This commit is contained in:
parent
00e7782be2
commit
80b6f4deaa
66 changed files with 1559 additions and 916 deletions
|
|
@ -3,6 +3,7 @@ package mbz
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/gabehf/koito/internal/logger"
|
||||
|
|
@ -28,7 +29,7 @@ func (c *MusicBrainzClient) getArtist(ctx context.Context, id uuid.UUID) (*Music
|
|||
mbzArtist := new(MusicBrainzArtist)
|
||||
err := c.getEntity(ctx, artistAliasFmtStr, id, mbzArtist)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("getArtist: %w", err)
|
||||
}
|
||||
return mbzArtist, nil
|
||||
}
|
||||
|
|
@ -38,10 +39,10 @@ func (c *MusicBrainzClient) GetArtistPrimaryAliases(ctx context.Context, id uuid
|
|||
l := logger.FromContext(ctx)
|
||||
artist, err := c.getArtist(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("GetArtistPrimaryAliases: %w", err)
|
||||
}
|
||||
if artist == nil {
|
||||
return nil, errors.New("artist could not be found by musicbrainz")
|
||||
return nil, errors.New("GetArtistPrimaryAliases: artist could not be found by musicbrainz")
|
||||
}
|
||||
used := make(map[string]bool)
|
||||
ret := make([]string, 1)
|
||||
|
|
|
|||
|
|
@ -52,19 +52,19 @@ func (c *MusicBrainzClient) getEntity(ctx context.Context, fmtStr string, id uui
|
|||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
l.Err(err).Msg("Failed to build MusicBrainz request")
|
||||
return err
|
||||
return fmt.Errorf("getEntity: %w", err)
|
||||
}
|
||||
l.Debug().Msg("Adding MusicBrainz request to queue")
|
||||
body, err := c.queue(ctx, req)
|
||||
if err != nil {
|
||||
l.Err(err).Msg("MusicBrainz request failed")
|
||||
return err
|
||||
return fmt.Errorf("getEntity: %w", err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, result)
|
||||
if err != nil {
|
||||
l.Err(err).Str("body", string(body)).Msg("Failed to unmarshal MusicBrainz response body")
|
||||
return err
|
||||
return fmt.Errorf("getEntity: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package mbz
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
|
@ -36,7 +37,7 @@ func (c *MusicBrainzClient) GetReleaseGroup(ctx context.Context, id uuid.UUID) (
|
|||
mbzRG := new(MusicBrainzReleaseGroup)
|
||||
err := c.getEntity(ctx, releaseGroupFmtStr, id, mbzRG)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("GetReleaseGroup: %w", err)
|
||||
}
|
||||
return mbzRG, nil
|
||||
}
|
||||
|
|
@ -45,7 +46,7 @@ func (c *MusicBrainzClient) GetRelease(ctx context.Context, id uuid.UUID) (*Musi
|
|||
mbzRelease := new(MusicBrainzRelease)
|
||||
err := c.getEntity(ctx, releaseFmtStr, id, mbzRelease)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("GetRelease: %w", err)
|
||||
}
|
||||
return mbzRelease, nil
|
||||
}
|
||||
|
|
@ -53,7 +54,7 @@ func (c *MusicBrainzClient) GetRelease(ctx context.Context, id uuid.UUID) (*Musi
|
|||
func (c *MusicBrainzClient) GetReleaseTitles(ctx context.Context, RGID uuid.UUID) ([]string, error) {
|
||||
releaseGroup, err := c.GetReleaseGroup(ctx, RGID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("GetReleaseTitles: %w", err)
|
||||
}
|
||||
|
||||
var titles []string
|
||||
|
|
@ -80,7 +81,7 @@ func ReleaseGroupToTitles(rg *MusicBrainzReleaseGroup) []string {
|
|||
func (c *MusicBrainzClient) GetLatinTitles(ctx context.Context, id uuid.UUID) ([]string, error) {
|
||||
rg, err := c.GetReleaseGroup(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("GetLatinTitles: %w", err)
|
||||
}
|
||||
titles := make([]string, 0)
|
||||
for _, r := range rg.Releases {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package mbz
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
|
@ -17,7 +18,7 @@ func (c *MusicBrainzClient) GetTrack(ctx context.Context, id uuid.UUID) (*MusicB
|
|||
track := new(MusicBrainzTrack)
|
||||
err := c.getEntity(ctx, recordingFmtStr, id, track)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("GetTrack: %w", err)
|
||||
}
|
||||
return track, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue