mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-29 21:27:05 +02:00
Write acronym MBID all uppercase
This commit is contained in:
parent
8fff19ceac
commit
ad1644672c
17 changed files with 149 additions and 149 deletions
|
@ -114,7 +114,7 @@ func TestGetFeedback(t *testing.T) {
|
|||
assert.Equal(302, result.TotalCount)
|
||||
assert.Equal(3, result.Offset)
|
||||
require.Len(t, result.Feedback, 2)
|
||||
assert.Equal("c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12", result.Feedback[0].RecordingMbid)
|
||||
assert.Equal("c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12", result.Feedback[0].RecordingMBID)
|
||||
}
|
||||
|
||||
func TestSendFeedback(t *testing.T) {
|
||||
|
@ -131,7 +131,7 @@ func TestSendFeedback(t *testing.T) {
|
|||
httpmock.RegisterResponder("POST", url, responder)
|
||||
|
||||
feedback := listenbrainz.Feedback{
|
||||
RecordingMbid: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
||||
RecordingMBID: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
||||
Score: 1,
|
||||
}
|
||||
result, err := client.SendFeedback(feedback)
|
||||
|
@ -154,7 +154,7 @@ func TestLookup(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
assert.Equal("Say Just Words", result.RecordingName)
|
||||
assert.Equal("Paradise Lost", result.ArtistCreditName)
|
||||
assert.Equal("569436a1-234a-44bc-a370-8f4d252bef21", result.RecordingMbid)
|
||||
assert.Equal("569436a1-234a-44bc-a370-8f4d252bef21", result.RecordingMBID)
|
||||
}
|
||||
|
||||
func setupHttpMock(t *testing.T, client *http.Client, url string, testDataPath string) {
|
||||
|
|
|
@ -33,7 +33,7 @@ type ListenBrainzApiBackend struct {
|
|||
client Client
|
||||
username string
|
||||
checkDuplicates bool
|
||||
existingMbids map[string]bool
|
||||
existingMBIDs map[string]bool
|
||||
}
|
||||
|
||||
func (b *ListenBrainzApiBackend) Name() string { return "listenbrainz" }
|
||||
|
@ -148,7 +148,7 @@ func (b *ListenBrainzApiBackend) ImportListens(export models.ListensResult, impo
|
|||
} else if isDupe {
|
||||
count -= 1
|
||||
msg := i18n.Tr("Ignored duplicate listen %v: \"%v\" by %v (%v)",
|
||||
l.ListenedAt, l.TrackName, l.ArtistName(), l.RecordingMbid)
|
||||
l.ListenedAt, l.TrackName, l.ArtistName(), l.RecordingMBID)
|
||||
importResult.Log(models.Info, msg)
|
||||
continue
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ out:
|
|||
}
|
||||
|
||||
func (b *ListenBrainzApiBackend) ImportLoves(export models.LovesResult, importResult models.ImportResult, progress chan models.Progress) (models.ImportResult, error) {
|
||||
if len(b.existingMbids) == 0 {
|
||||
if len(b.existingMBIDs) == 0 {
|
||||
existingLovesChan := make(chan models.LovesResult)
|
||||
go b.ExportLoves(time.Unix(0, 0), existingLovesChan, progress)
|
||||
existingLoves := <-existingLovesChan
|
||||
|
@ -239,30 +239,30 @@ func (b *ListenBrainzApiBackend) ImportLoves(export models.LovesResult, importRe
|
|||
}
|
||||
|
||||
// TODO: Store MBIDs directly
|
||||
b.existingMbids = make(map[string]bool, len(existingLoves.Items))
|
||||
b.existingMBIDs = make(map[string]bool, len(existingLoves.Items))
|
||||
for _, love := range existingLoves.Items {
|
||||
b.existingMbids[string(love.RecordingMbid)] = true
|
||||
b.existingMBIDs[string(love.RecordingMBID)] = true
|
||||
}
|
||||
}
|
||||
|
||||
for _, love := range export.Items {
|
||||
recordingMbid := string(love.RecordingMbid)
|
||||
recordingMBID := string(love.RecordingMBID)
|
||||
|
||||
if recordingMbid == "" {
|
||||
if recordingMBID == "" {
|
||||
lookup, err := b.client.Lookup(love.TrackName, love.ArtistName())
|
||||
if err == nil {
|
||||
recordingMbid = lookup.RecordingMbid
|
||||
recordingMBID = lookup.RecordingMBID
|
||||
}
|
||||
}
|
||||
|
||||
if recordingMbid != "" {
|
||||
if recordingMBID != "" {
|
||||
ok := false
|
||||
errMsg := ""
|
||||
if b.existingMbids[recordingMbid] {
|
||||
if b.existingMBIDs[recordingMBID] {
|
||||
ok = true
|
||||
} else {
|
||||
resp, err := b.client.SendFeedback(Feedback{
|
||||
RecordingMbid: recordingMbid,
|
||||
RecordingMBID: recordingMBID,
|
||||
Score: 1,
|
||||
})
|
||||
ok = err == nil && resp.Status == "ok"
|
||||
|
@ -324,20 +324,20 @@ func (lbListen Listen) AsListen() models.Listen {
|
|||
}
|
||||
|
||||
func (f Feedback) AsLove() models.Love {
|
||||
recordingMbid := mbtypes.MBID(f.RecordingMbid)
|
||||
recordingMBID := mbtypes.MBID(f.RecordingMBID)
|
||||
track := f.TrackMetadata
|
||||
if track == nil {
|
||||
track = &Track{}
|
||||
}
|
||||
love := models.Love{
|
||||
UserName: f.UserName,
|
||||
RecordingMbid: recordingMbid,
|
||||
RecordingMBID: recordingMBID,
|
||||
Created: time.Unix(f.Created, 0),
|
||||
Track: track.AsTrack(),
|
||||
}
|
||||
|
||||
if love.Track.RecordingMbid == "" {
|
||||
love.Track.RecordingMbid = love.RecordingMbid
|
||||
if love.Track.RecordingMBID == "" {
|
||||
love.Track.RecordingMBID = love.RecordingMBID
|
||||
}
|
||||
|
||||
return love
|
||||
|
@ -351,16 +351,16 @@ func (t Track) AsTrack() models.Track {
|
|||
Duration: t.Duration(),
|
||||
TrackNumber: t.TrackNumber(),
|
||||
DiscNumber: t.DiscNumber(),
|
||||
RecordingMbid: mbtypes.MBID(t.RecordingMbid()),
|
||||
ReleaseMbid: mbtypes.MBID(t.ReleaseMbid()),
|
||||
ReleaseGroupMbid: mbtypes.MBID(t.ReleaseGroupMbid()),
|
||||
RecordingMBID: mbtypes.MBID(t.RecordingMBID()),
|
||||
ReleaseMBID: mbtypes.MBID(t.ReleaseMBID()),
|
||||
ReleaseGroupMBID: mbtypes.MBID(t.ReleaseGroupMBID()),
|
||||
ISRC: t.ISRC(),
|
||||
AdditionalInfo: t.AdditionalInfo,
|
||||
}
|
||||
|
||||
if t.MbidMapping != nil && len(track.ArtistMbids) == 0 {
|
||||
for _, artistMbid := range t.MbidMapping.ArtistMbids {
|
||||
track.ArtistMbids = append(track.ArtistMbids, mbtypes.MBID(artistMbid))
|
||||
if t.MBIDMapping != nil && len(track.ArtistMBIDs) == 0 {
|
||||
for _, artistMBID := range t.MBIDMapping.ArtistMBIDs {
|
||||
track.ArtistMBIDs = append(track.ArtistMBIDs, mbtypes.MBID(artistMBID))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,30 +65,30 @@ func TestListenBrainzListenAsListen(t *testing.T) {
|
|||
assert.Equal(t, []string{lbListen.TrackMetadata.ArtistName}, listen.ArtistNames)
|
||||
assert.Equal(t, 5, listen.TrackNumber)
|
||||
assert.Equal(t, 1, listen.DiscNumber)
|
||||
assert.Equal(t, mbtypes.MBID("c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"), listen.RecordingMbid)
|
||||
assert.Equal(t, mbtypes.MBID("d7f22677-9803-4d21-ba42-081b633a6f68"), listen.ReleaseMbid)
|
||||
assert.Equal(t, mbtypes.MBID("80aca1ee-aa51-41be-9f75-024710d92ff4"), listen.ReleaseGroupMbid)
|
||||
assert.Equal(t, mbtypes.MBID("c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"), listen.RecordingMBID)
|
||||
assert.Equal(t, mbtypes.MBID("d7f22677-9803-4d21-ba42-081b633a6f68"), listen.ReleaseMBID)
|
||||
assert.Equal(t, mbtypes.MBID("80aca1ee-aa51-41be-9f75-024710d92ff4"), listen.ReleaseGroupMBID)
|
||||
assert.Equal(t, "DES561620801", listen.ISRC)
|
||||
assert.Equal(t, lbListen.TrackMetadata.AdditionalInfo["foo"], listen.AdditionalInfo["foo"])
|
||||
}
|
||||
|
||||
func TestListenBrainzFeedbackAsLove(t *testing.T) {
|
||||
recordingMbid := "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"
|
||||
releaseMbid := "d7f22677-9803-4d21-ba42-081b633a6f68"
|
||||
artistMbid := "d7f22677-9803-4d21-ba42-081b633a6f68"
|
||||
recordingMBID := "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"
|
||||
releaseMBID := "d7f22677-9803-4d21-ba42-081b633a6f68"
|
||||
artistMBID := "d7f22677-9803-4d21-ba42-081b633a6f68"
|
||||
feedback := listenbrainz.Feedback{
|
||||
Created: 1699859066,
|
||||
RecordingMbid: recordingMbid,
|
||||
RecordingMBID: recordingMBID,
|
||||
Score: 1,
|
||||
UserName: "ousidecontext",
|
||||
TrackMetadata: &listenbrainz.Track{
|
||||
TrackName: "Oweynagat",
|
||||
ArtistName: "Dool",
|
||||
ReleaseName: "Here Now, There Then",
|
||||
MbidMapping: &listenbrainz.MbidMapping{
|
||||
RecordingMbid: recordingMbid,
|
||||
ReleaseMbid: releaseMbid,
|
||||
ArtistMbids: []string{artistMbid},
|
||||
MBIDMapping: &listenbrainz.MBIDMapping{
|
||||
RecordingMBID: recordingMBID,
|
||||
ReleaseMBID: releaseMBID,
|
||||
ArtistMBIDs: []string{artistMBID},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -99,24 +99,24 @@ func TestListenBrainzFeedbackAsLove(t *testing.T) {
|
|||
assert.Equal(feedback.TrackMetadata.TrackName, love.TrackName)
|
||||
assert.Equal(feedback.TrackMetadata.ReleaseName, love.ReleaseName)
|
||||
assert.Equal([]string{feedback.TrackMetadata.ArtistName}, love.ArtistNames)
|
||||
assert.Equal(mbtypes.MBID(recordingMbid), love.RecordingMbid)
|
||||
assert.Equal(mbtypes.MBID(recordingMbid), love.Track.RecordingMbid)
|
||||
assert.Equal(mbtypes.MBID(releaseMbid), love.Track.ReleaseMbid)
|
||||
require.Len(t, love.Track.ArtistMbids, 1)
|
||||
assert.Equal(mbtypes.MBID(artistMbid), love.Track.ArtistMbids[0])
|
||||
assert.Equal(mbtypes.MBID(recordingMBID), love.RecordingMBID)
|
||||
assert.Equal(mbtypes.MBID(recordingMBID), love.Track.RecordingMBID)
|
||||
assert.Equal(mbtypes.MBID(releaseMBID), love.Track.ReleaseMBID)
|
||||
require.Len(t, love.Track.ArtistMBIDs, 1)
|
||||
assert.Equal(mbtypes.MBID(artistMBID), love.Track.ArtistMBIDs[0])
|
||||
}
|
||||
|
||||
func TestListenBrainzPartialFeedbackAsLove(t *testing.T) {
|
||||
recordingMbid := "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"
|
||||
recordingMBID := "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"
|
||||
feedback := listenbrainz.Feedback{
|
||||
Created: 1699859066,
|
||||
RecordingMbid: recordingMbid,
|
||||
RecordingMBID: recordingMBID,
|
||||
Score: 1,
|
||||
}
|
||||
love := feedback.AsLove()
|
||||
assert := assert.New(t)
|
||||
assert.Equal(time.Unix(1699859066, 0).Unix(), love.Created.Unix())
|
||||
assert.Equal(mbtypes.MBID(recordingMbid), love.RecordingMbid)
|
||||
assert.Equal(mbtypes.MBID(recordingMbid), love.Track.RecordingMbid)
|
||||
assert.Equal(mbtypes.MBID(recordingMBID), love.RecordingMBID)
|
||||
assert.Equal(mbtypes.MBID(recordingMBID), love.Track.RecordingMBID)
|
||||
assert.Empty(love.Track.TrackName)
|
||||
}
|
||||
|
|
|
@ -66,20 +66,20 @@ type Track struct {
|
|||
ArtistName string `json:"artist_name,omitempty"`
|
||||
ReleaseName string `json:"release_name,omitempty"`
|
||||
AdditionalInfo map[string]any `json:"additional_info,omitempty"`
|
||||
MbidMapping *MbidMapping `json:"mbid_mapping,omitempty"`
|
||||
MBIDMapping *MBIDMapping `json:"mbid_mapping,omitempty"`
|
||||
}
|
||||
|
||||
type MbidMapping struct {
|
||||
type MBIDMapping struct {
|
||||
RecordingName string `json:"recording_name,omitempty"`
|
||||
RecordingMbid string `json:"recording_mbid,omitempty"`
|
||||
ReleaseMbid string `json:"release_mbid,omitempty"`
|
||||
ArtistMbids []string `json:"artist_mbids,omitempty"`
|
||||
RecordingMBID string `json:"recording_mbid,omitempty"`
|
||||
ReleaseMBID string `json:"release_mbid,omitempty"`
|
||||
ArtistMBIDs []string `json:"artist_mbids,omitempty"`
|
||||
Artists []Artist `json:"artists,omitempty"`
|
||||
}
|
||||
|
||||
type Artist struct {
|
||||
ArtistCreditName string `json:"artist_credit_name,omitempty"`
|
||||
ArtistMbid string `json:"artist_mbid,omitempty"`
|
||||
ArtistMBID string `json:"artist_mbid,omitempty"`
|
||||
JoinPhrase string `json:"join_phrase,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ type GetFeedbackResult struct {
|
|||
|
||||
type Feedback struct {
|
||||
Created int64 `json:"created,omitempty"`
|
||||
RecordingMbid string `json:"recording_mbid,omitempty"`
|
||||
RecordingMBID string `json:"recording_mbid,omitempty"`
|
||||
RecordingMsid string `json:"recording_msid,omitempty"`
|
||||
Score int `json:"score,omitempty"`
|
||||
TrackMetadata *Track `json:"track_metadata,omitempty"`
|
||||
|
@ -103,9 +103,9 @@ type LookupResult struct {
|
|||
ArtistCreditName string `json:"artist_credit_name"`
|
||||
ReleaseName string `json:"release_name"`
|
||||
RecordingName string `json:"recording_name"`
|
||||
RecordingMbid string `json:"recording_mbid"`
|
||||
ReleaseMbid string `json:"release_mbid"`
|
||||
ArtistMbids []string `json:"artist_mbids"`
|
||||
RecordingMBID string `json:"recording_mbid"`
|
||||
ReleaseMBID string `json:"release_mbid"`
|
||||
ArtistMBIDs []string `json:"artist_mbids"`
|
||||
}
|
||||
|
||||
type StatusResult struct {
|
||||
|
@ -162,25 +162,25 @@ func (t Track) ISRC() string {
|
|||
return tryGetValueOrEmpty[string](t.AdditionalInfo, "isrc")
|
||||
}
|
||||
|
||||
func (t Track) RecordingMbid() string {
|
||||
func (t Track) RecordingMBID() string {
|
||||
mbid := tryGetValueOrEmpty[string](t.AdditionalInfo, "recording_mbid")
|
||||
if mbid == "" && t.MbidMapping != nil {
|
||||
return t.MbidMapping.RecordingMbid
|
||||
if mbid == "" && t.MBIDMapping != nil {
|
||||
return t.MBIDMapping.RecordingMBID
|
||||
} else {
|
||||
return mbid
|
||||
}
|
||||
}
|
||||
|
||||
func (t Track) ReleaseMbid() string {
|
||||
func (t Track) ReleaseMBID() string {
|
||||
mbid := tryGetValueOrEmpty[string](t.AdditionalInfo, "release_mbid")
|
||||
if mbid == "" && t.MbidMapping != nil {
|
||||
return t.MbidMapping.ReleaseMbid
|
||||
if mbid == "" && t.MBIDMapping != nil {
|
||||
return t.MBIDMapping.ReleaseMBID
|
||||
} else {
|
||||
return mbid
|
||||
}
|
||||
}
|
||||
|
||||
func (t Track) ReleaseGroupMbid() string {
|
||||
func (t Track) ReleaseGroupMBID() string {
|
||||
return tryGetValueOrEmpty[string](t.AdditionalInfo, "release_group_mbid")
|
||||
}
|
||||
|
||||
|
|
|
@ -140,40 +140,40 @@ func TestTrackIsrc(t *testing.T) {
|
|||
assert.Equal(t, expected, track.ISRC())
|
||||
}
|
||||
|
||||
func TestTrackRecordingMbid(t *testing.T) {
|
||||
func TestTrackRecordingMBID(t *testing.T) {
|
||||
expected := "e02cc1c3-93fd-4e24-8b77-325060de920b"
|
||||
track := listenbrainz.Track{
|
||||
AdditionalInfo: map[string]any{
|
||||
"recording_mbid": expected,
|
||||
},
|
||||
}
|
||||
assert.Equal(t, expected, track.RecordingMbid())
|
||||
assert.Equal(t, expected, track.RecordingMBID())
|
||||
}
|
||||
|
||||
func TestTrackReleaseMbid(t *testing.T) {
|
||||
func TestTrackReleaseMBID(t *testing.T) {
|
||||
expected := "e02cc1c3-93fd-4e24-8b77-325060de920b"
|
||||
track := listenbrainz.Track{
|
||||
AdditionalInfo: map[string]any{
|
||||
"release_mbid": expected,
|
||||
},
|
||||
}
|
||||
assert.Equal(t, expected, track.ReleaseMbid())
|
||||
assert.Equal(t, expected, track.ReleaseMBID())
|
||||
}
|
||||
|
||||
func TestReleaseGroupMbid(t *testing.T) {
|
||||
func TestReleaseGroupMBID(t *testing.T) {
|
||||
expected := "e02cc1c3-93fd-4e24-8b77-325060de920b"
|
||||
track := listenbrainz.Track{
|
||||
AdditionalInfo: map[string]any{
|
||||
"release_group_mbid": expected,
|
||||
},
|
||||
}
|
||||
assert.Equal(t, expected, track.ReleaseGroupMbid())
|
||||
assert.Equal(t, expected, track.ReleaseGroupMBID())
|
||||
}
|
||||
|
||||
func TestMarshalPartialFeedback(t *testing.T) {
|
||||
feedback := listenbrainz.Feedback{
|
||||
Created: 1699859066,
|
||||
RecordingMbid: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
||||
RecordingMBID: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
||||
}
|
||||
b, err := json.Marshal(feedback)
|
||||
require.NoError(t, err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue