mirror of
https://git.sr.ht/~phw/scotty
synced 2025-06-06 12:58:35 +02:00
Use LB API to lookup missing metadata for loves
This is faster than using the MBID API individually
This commit is contained in:
parent
dddd2e4eec
commit
7542657925
4 changed files with 194 additions and 51 deletions
|
@ -28,6 +28,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
"go.uploadedlobster.com/mbtypes"
|
||||
"go.uploadedlobster.com/scotty/pkg/ratelimit"
|
||||
)
|
||||
|
||||
|
@ -158,3 +159,24 @@ func (c Client) Lookup(ctx context.Context, recordingName string, artistName str
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c Client) MetadataRecordings(ctx context.Context, mbids []mbtypes.MBID) (result RecordingMetadataResult, err error) {
|
||||
const path = "/metadata/recording/"
|
||||
errorResult := ErrorResult{}
|
||||
body := RecordingMetadataRequest{
|
||||
RecordingMBIDs: mbids,
|
||||
Includes: "artist release",
|
||||
}
|
||||
response, err := c.HTTPClient.R().
|
||||
SetContext(ctx).
|
||||
SetBody(body).
|
||||
SetResult(&result).
|
||||
SetError(&errorResult).
|
||||
Post(path)
|
||||
|
||||
if !response.IsSuccess() {
|
||||
err = errors.New(errorResult.Error)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -82,9 +82,9 @@ type MBIDMapping struct {
|
|||
}
|
||||
|
||||
type Artist struct {
|
||||
ArtistCreditName string `json:"artist_credit_name,omitempty"`
|
||||
ArtistMBID string `json:"artist_mbid,omitempty"`
|
||||
JoinPhrase string `json:"join_phrase,omitempty"`
|
||||
ArtistCreditName string `json:"artist_credit_name,omitempty"`
|
||||
ArtistMBID mbtypes.MBID `json:"artist_mbid,omitempty"`
|
||||
JoinPhrase string `json:"join_phrase,omitempty"`
|
||||
}
|
||||
|
||||
type GetFeedbackResult struct {
|
||||
|
@ -112,6 +112,44 @@ type LookupResult struct {
|
|||
ArtistMBIDs []mbtypes.MBID `json:"artist_mbids"`
|
||||
}
|
||||
|
||||
type RecordingMetadataRequest struct {
|
||||
RecordingMBIDs []mbtypes.MBID `json:"recording_mbids"`
|
||||
Includes string `json:"inc,omitempty"`
|
||||
}
|
||||
|
||||
// Result for a recording metadata lookup
|
||||
type RecordingMetadataResult map[mbtypes.MBID]RecordingMetadata
|
||||
|
||||
type RecordingMetadata struct {
|
||||
Artist struct {
|
||||
Name string `json:"name"`
|
||||
ArtistCreditID int `json:"artist_credit_id"`
|
||||
Artists []struct {
|
||||
Name string `json:"name"`
|
||||
Area string `json:"area"`
|
||||
ArtistMBID mbtypes.MBID `json:"artist_mbid"`
|
||||
JoinPhrase string `json:"join_phrase"`
|
||||
BeginYear int `json:"begin_year"`
|
||||
Type string `json:"type"`
|
||||
// todo rels
|
||||
} `json:"artists"`
|
||||
} `json:"artist"`
|
||||
Recording struct {
|
||||
Name string `json:"name"`
|
||||
Length int `json:"length"`
|
||||
// TODO rels
|
||||
} `json:"recording"`
|
||||
Release struct {
|
||||
Name string `json:"name"`
|
||||
AlbumArtistName string `json:"album_artist_name"`
|
||||
Year int `json:"year"`
|
||||
MBID mbtypes.MBID `json:"mbid"`
|
||||
ReleaseGroupMBID mbtypes.MBID `json:"release_group_mbid"`
|
||||
CAAID int `json:"caa_id"`
|
||||
CAAReleaseMBID mbtypes.MBID `json:"caa_release_mbid"`
|
||||
} `json:"release"`
|
||||
}
|
||||
|
||||
type StatusResult struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue