mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-07 22:29:28 +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
internal
backends
dump
funkwhale
jspf
lastfm
listenbrainz
scrobblerlog
models
similarity
|
@ -41,7 +41,7 @@ func (b *DumpBackend) ImportListens(export models.ListensResult, importResult mo
|
|||
importResult.UpdateTimestamp(listen.ListenedAt)
|
||||
importResult.ImportCount += 1
|
||||
msg := fmt.Sprintf("🎶 %v: \"%v\" by %v (%v)",
|
||||
listen.ListenedAt, listen.TrackName, listen.ArtistName(), listen.RecordingMbid)
|
||||
listen.ListenedAt, listen.TrackName, listen.ArtistName(), listen.RecordingMBID)
|
||||
importResult.Log(models.Info, msg)
|
||||
progress <- models.Progress{}.FromImportResult(importResult)
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func (b *DumpBackend) ImportLoves(export models.LovesResult, importResult models
|
|||
importResult.UpdateTimestamp(love.Created)
|
||||
importResult.ImportCount += 1
|
||||
msg := fmt.Sprintf("❤️ %v: \"%v\" by %v (%v)",
|
||||
love.Created, love.TrackName, love.ArtistName(), love.RecordingMbid)
|
||||
love.Created, love.TrackName, love.ArtistName(), love.RecordingMBID)
|
||||
importResult.Log(models.Info, msg)
|
||||
progress <- models.Progress{}.FromImportResult(importResult)
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ func (f FavoriteTrack) AsLove() models.Love {
|
|||
track := f.Track.AsTrack()
|
||||
love := models.Love{
|
||||
UserName: f.User.UserName,
|
||||
RecordingMbid: track.RecordingMbid,
|
||||
RecordingMBID: track.RecordingMBID,
|
||||
Track: track,
|
||||
}
|
||||
|
||||
|
@ -189,16 +189,16 @@ func (f FavoriteTrack) AsLove() models.Love {
|
|||
}
|
||||
|
||||
func (t Track) AsTrack() models.Track {
|
||||
recordingMbid := mbtypes.MBID(t.RecordingMbid)
|
||||
recordingMBID := mbtypes.MBID(t.RecordingMBID)
|
||||
track := models.Track{
|
||||
TrackName: t.Title,
|
||||
ReleaseName: t.Album.Title,
|
||||
ArtistNames: []string{t.Artist.Name},
|
||||
TrackNumber: t.Position,
|
||||
DiscNumber: t.DiscNumber,
|
||||
RecordingMbid: recordingMbid,
|
||||
ReleaseMbid: mbtypes.MBID(t.Album.ReleaseMbid),
|
||||
ArtistMbids: []mbtypes.MBID{mbtypes.MBID(t.Artist.ArtistMbid)},
|
||||
RecordingMBID: recordingMBID,
|
||||
ReleaseMBID: mbtypes.MBID(t.Album.ReleaseMBID),
|
||||
ArtistMBIDs: []mbtypes.MBID{mbtypes.MBID(t.Artist.ArtistMBID)},
|
||||
Tags: t.Tags,
|
||||
AdditionalInfo: map[string]any{
|
||||
"media_player": FunkwhaleClientName,
|
||||
|
|
|
@ -44,17 +44,17 @@ func TestFunkwhaleListeningAsListen(t *testing.T) {
|
|||
},
|
||||
Track: funkwhale.Track{
|
||||
Title: "Oweynagat",
|
||||
RecordingMbid: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
||||
RecordingMBID: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
||||
Position: 5,
|
||||
DiscNumber: 1,
|
||||
Tags: []string{"foo", "bar"},
|
||||
Artist: funkwhale.Artist{
|
||||
Name: "Dool",
|
||||
ArtistMbid: "24412926-c7bd-48e8-afad-8a285b42e131",
|
||||
ArtistMBID: "24412926-c7bd-48e8-afad-8a285b42e131",
|
||||
},
|
||||
Album: funkwhale.Album{
|
||||
Title: "Here Now, There Then",
|
||||
ReleaseMbid: "d7f22677-9803-4d21-ba42-081b633a6f68",
|
||||
ReleaseMBID: "d7f22677-9803-4d21-ba42-081b633a6f68",
|
||||
},
|
||||
Uploads: []funkwhale.Upload{
|
||||
{
|
||||
|
@ -75,9 +75,9 @@ func TestFunkwhaleListeningAsListen(t *testing.T) {
|
|||
assert.Equal(fwListen.Track.DiscNumber, listen.Track.DiscNumber)
|
||||
assert.Equal(fwListen.Track.Tags, listen.Track.Tags)
|
||||
// assert.Equal(backends.FunkwhaleClientName, listen.AdditionalInfo["disc_number"])
|
||||
assert.Equal(mbtypes.MBID(fwListen.Track.RecordingMbid), listen.RecordingMbid)
|
||||
assert.Equal(mbtypes.MBID(fwListen.Track.Album.ReleaseMbid), listen.ReleaseMbid)
|
||||
assert.Equal(mbtypes.MBID(fwListen.Track.Artist.ArtistMbid), listen.ArtistMbids[0])
|
||||
assert.Equal(mbtypes.MBID(fwListen.Track.RecordingMBID), listen.RecordingMBID)
|
||||
assert.Equal(mbtypes.MBID(fwListen.Track.Album.ReleaseMBID), listen.ReleaseMBID)
|
||||
assert.Equal(mbtypes.MBID(fwListen.Track.Artist.ArtistMBID), listen.ArtistMBIDs[0])
|
||||
assert.Equal(funkwhale.FunkwhaleClientName, listen.AdditionalInfo["media_player"])
|
||||
}
|
||||
|
||||
|
@ -89,17 +89,17 @@ func TestFunkwhaleFavoriteTrackAsLove(t *testing.T) {
|
|||
},
|
||||
Track: funkwhale.Track{
|
||||
Title: "Oweynagat",
|
||||
RecordingMbid: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
||||
RecordingMBID: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
||||
Position: 5,
|
||||
DiscNumber: 1,
|
||||
Tags: []string{"foo", "bar"},
|
||||
Artist: funkwhale.Artist{
|
||||
Name: "Dool",
|
||||
ArtistMbid: "24412926-c7bd-48e8-afad-8a285b42e131",
|
||||
ArtistMBID: "24412926-c7bd-48e8-afad-8a285b42e131",
|
||||
},
|
||||
Album: funkwhale.Album{
|
||||
Title: "Here Now, There Then",
|
||||
ReleaseMbid: "d7f22677-9803-4d21-ba42-081b633a6f68",
|
||||
ReleaseMBID: "d7f22677-9803-4d21-ba42-081b633a6f68",
|
||||
},
|
||||
Uploads: []funkwhale.Upload{
|
||||
{
|
||||
|
@ -119,10 +119,10 @@ func TestFunkwhaleFavoriteTrackAsLove(t *testing.T) {
|
|||
assert.Equal(favorite.Track.Position, love.Track.TrackNumber)
|
||||
assert.Equal(favorite.Track.DiscNumber, love.Track.DiscNumber)
|
||||
assert.Equal(favorite.Track.Tags, love.Track.Tags)
|
||||
assert.Equal(mbtypes.MBID(favorite.Track.RecordingMbid), love.RecordingMbid)
|
||||
assert.Equal(mbtypes.MBID(favorite.Track.RecordingMbid), love.Track.RecordingMbid)
|
||||
assert.Equal(mbtypes.MBID(favorite.Track.Album.ReleaseMbid), love.ReleaseMbid)
|
||||
require.Len(t, love.Track.ArtistMbids, 1)
|
||||
assert.Equal(mbtypes.MBID(favorite.Track.Artist.ArtistMbid), love.ArtistMbids[0])
|
||||
assert.Equal(mbtypes.MBID(favorite.Track.RecordingMBID), love.RecordingMBID)
|
||||
assert.Equal(mbtypes.MBID(favorite.Track.RecordingMBID), love.Track.RecordingMBID)
|
||||
assert.Equal(mbtypes.MBID(favorite.Track.Album.ReleaseMBID), love.ReleaseMBID)
|
||||
require.Len(t, love.Track.ArtistMBIDs, 1)
|
||||
assert.Equal(mbtypes.MBID(favorite.Track.Artist.ArtistMBID), love.ArtistMBIDs[0])
|
||||
assert.Equal(funkwhale.FunkwhaleClientName, love.AdditionalInfo["media_player"])
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ type Track struct {
|
|||
Title string `json:"title"`
|
||||
Position int `json:"position"`
|
||||
DiscNumber int `json:"disc_number"`
|
||||
RecordingMbid string `json:"mbid"`
|
||||
RecordingMBID string `json:"mbid"`
|
||||
Tags []string `json:"tags"`
|
||||
Uploads []Upload `json:"uploads"`
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ type Track struct {
|
|||
type Artist struct {
|
||||
Id int `json:"int"`
|
||||
Name string `json:"name"`
|
||||
ArtistMbid string `json:"mbid"`
|
||||
ArtistMBID string `json:"mbid"`
|
||||
}
|
||||
|
||||
type Album struct {
|
||||
|
@ -73,7 +73,7 @@ type Album struct {
|
|||
AlbumArtist Artist `json:"artist"`
|
||||
ReleaseDate string `json:"release_date"`
|
||||
TrackCount int `json:"track_count"`
|
||||
ReleaseMbid string `json:"mbid"`
|
||||
ReleaseMBID string `json:"mbid"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
|
|
|
@ -118,8 +118,8 @@ func listenAsTrack(l models.Listen) jspf.Track {
|
|||
extension.AddedBy = l.UserName
|
||||
track.Extension[jspf.MusicBrainzTrackExtensionId] = extension
|
||||
|
||||
if l.RecordingMbid != "" {
|
||||
track.Identifier = append(track.Identifier, "https://musicbrainz.org/recording/"+string(l.RecordingMbid))
|
||||
if l.RecordingMBID != "" {
|
||||
track.Identifier = append(track.Identifier, "https://musicbrainz.org/recording/"+string(l.RecordingMBID))
|
||||
}
|
||||
|
||||
return track
|
||||
|
@ -133,12 +133,12 @@ func loveAsTrack(l models.Love) jspf.Track {
|
|||
extension.AddedBy = l.UserName
|
||||
track.Extension[jspf.MusicBrainzTrackExtensionId] = extension
|
||||
|
||||
recordingMbid := l.Track.RecordingMbid
|
||||
if l.RecordingMbid != "" {
|
||||
recordingMbid = l.RecordingMbid
|
||||
recordingMBID := l.Track.RecordingMBID
|
||||
if l.RecordingMBID != "" {
|
||||
recordingMBID = l.RecordingMBID
|
||||
}
|
||||
if recordingMbid != "" {
|
||||
track.Identifier = append(track.Identifier, "https://musicbrainz.org/recording/"+string(recordingMbid))
|
||||
if recordingMBID != "" {
|
||||
track.Identifier = append(track.Identifier, "https://musicbrainz.org/recording/"+string(recordingMBID))
|
||||
}
|
||||
|
||||
return track
|
||||
|
@ -159,15 +159,15 @@ func trackAsTrack(t models.Track) jspf.Track {
|
|||
func makeMusicBrainzExtension(t models.Track) jspf.MusicBrainzTrackExtension {
|
||||
extension := jspf.MusicBrainzTrackExtension{
|
||||
AdditionalMetadata: t.AdditionalInfo,
|
||||
ArtistIdentifiers: make([]string, len(t.ArtistMbids)),
|
||||
ArtistIdentifiers: make([]string, len(t.ArtistMBIDs)),
|
||||
}
|
||||
|
||||
for i, mbid := range t.ArtistMbids {
|
||||
for i, mbid := range t.ArtistMBIDs {
|
||||
extension.ArtistIdentifiers[i] = "https://musicbrainz.org/artist/" + string(mbid)
|
||||
}
|
||||
|
||||
if t.ReleaseMbid != "" {
|
||||
extension.ReleaseIdentifier = "https://musicbrainz.org/release/" + string(t.ReleaseMbid)
|
||||
if t.ReleaseMBID != "" {
|
||||
extension.ReleaseIdentifier = "https://musicbrainz.org/release/" + string(t.ReleaseMBID)
|
||||
}
|
||||
|
||||
// The tracknumber tag would be redundant
|
||||
|
|
|
@ -141,16 +141,16 @@ out:
|
|||
TrackName: scrobble.Name,
|
||||
ArtistNames: []string{},
|
||||
ReleaseName: scrobble.Album.Name,
|
||||
RecordingMbid: mbtypes.MBID(scrobble.Mbid),
|
||||
ArtistMbids: []mbtypes.MBID{},
|
||||
ReleaseMbid: mbtypes.MBID(scrobble.Album.Mbid),
|
||||
RecordingMBID: mbtypes.MBID(scrobble.Mbid),
|
||||
ArtistMBIDs: []mbtypes.MBID{},
|
||||
ReleaseMBID: mbtypes.MBID(scrobble.Album.Mbid),
|
||||
},
|
||||
}
|
||||
if scrobble.Artist.Name != "" {
|
||||
listen.Track.ArtistNames = []string{scrobble.Artist.Name}
|
||||
}
|
||||
if scrobble.Artist.Mbid != "" {
|
||||
listen.Track.ArtistMbids = []mbtypes.MBID{mbtypes.MBID(scrobble.Artist.Mbid)}
|
||||
listen.Track.ArtistMBIDs = []mbtypes.MBID{mbtypes.MBID(scrobble.Artist.Mbid)}
|
||||
}
|
||||
listens = append(listens, listen)
|
||||
} else {
|
||||
|
@ -204,8 +204,8 @@ func (b *LastfmApiBackend) ImportListens(export models.ListensResult, importResu
|
|||
if l.TrackNumber > 0 {
|
||||
trackNumbers = append(trackNumbers, strconv.Itoa(l.TrackNumber))
|
||||
}
|
||||
if l.RecordingMbid != "" {
|
||||
mbids = append(mbids, string(l.RecordingMbid))
|
||||
if l.RecordingMBID != "" {
|
||||
mbids = append(mbids, string(l.RecordingMBID))
|
||||
}
|
||||
// if l.ReleaseArtist != "" {
|
||||
// albumArtists = append(albums, l.ReleaseArtist)
|
||||
|
@ -295,12 +295,12 @@ out:
|
|||
love := models.Love{
|
||||
Created: time.Unix(timestamp, 0),
|
||||
UserName: result.User,
|
||||
RecordingMbid: mbtypes.MBID(track.Mbid),
|
||||
RecordingMBID: mbtypes.MBID(track.Mbid),
|
||||
Track: models.Track{
|
||||
TrackName: track.Name,
|
||||
ArtistNames: []string{track.Artist.Name},
|
||||
RecordingMbid: mbtypes.MBID(track.Mbid),
|
||||
ArtistMbids: []mbtypes.MBID{mbtypes.MBID(track.Artist.Mbid)},
|
||||
RecordingMBID: mbtypes.MBID(track.Mbid),
|
||||
ArtistMBIDs: []mbtypes.MBID{mbtypes.MBID(track.Artist.Mbid)},
|
||||
AdditionalInfo: models.AdditionalInfo{
|
||||
"lastfm_url": track.Url,
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -58,7 +58,7 @@ func Parse(data io.Reader, includeSkipped bool) (ScrobblerLog, error) {
|
|||
|
||||
for {
|
||||
// A row is:
|
||||
// artistName releaseName trackName trackNumber duration rating timestamp recordingMbid
|
||||
// artistName releaseName trackName trackNumber duration rating timestamp recordingMBID
|
||||
row, err := tsvReader.Read()
|
||||
if err == io.EOF {
|
||||
break
|
||||
|
@ -101,7 +101,7 @@ func Write(data io.Writer, listens models.ListensList) (lastTimestamp time.Time,
|
|||
}
|
||||
|
||||
// A row is:
|
||||
// artistName releaseName trackName trackNumber duration rating timestamp recordingMbid
|
||||
// artistName releaseName trackName trackNumber duration rating timestamp recordingMBID
|
||||
rating, ok := listen.AdditionalInfo["rockbox_rating"].(string)
|
||||
if !ok || rating == "" {
|
||||
rating = "L"
|
||||
|
@ -114,7 +114,7 @@ func Write(data io.Writer, listens models.ListensList) (lastTimestamp time.Time,
|
|||
strconv.Itoa(int(listen.Duration.Seconds())),
|
||||
rating,
|
||||
strconv.Itoa(int(listen.ListenedAt.Unix())),
|
||||
string(listen.RecordingMbid),
|
||||
string(listen.RecordingMBID),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ func rowToListen(row []string, client string) (models.Listen, error) {
|
|||
}
|
||||
|
||||
if len(row) > 7 {
|
||||
listen.Track.RecordingMbid = mbtypes.MBID(row[7])
|
||||
listen.Track.RecordingMBID = mbtypes.MBID(row[7])
|
||||
}
|
||||
|
||||
return listen, nil
|
||||
|
|
|
@ -61,10 +61,10 @@ func TestParser(t *testing.T) {
|
|||
assert.Equal(time.Duration(306*time.Second), listen1.Duration)
|
||||
assert.Equal("L", listen1.AdditionalInfo["rockbox_rating"])
|
||||
assert.Equal(time.Unix(1260342084, 0), listen1.ListenedAt)
|
||||
assert.Equal(mbtypes.MBID(""), listen1.RecordingMbid)
|
||||
assert.Equal(mbtypes.MBID(""), listen1.RecordingMBID)
|
||||
listen4 := result.Listens[3]
|
||||
assert.Equal("S", listen4.AdditionalInfo["rockbox_rating"])
|
||||
assert.Equal(mbtypes.MBID("385ba9e9-626d-4750-a607-58e541dca78e"), listen4.RecordingMbid)
|
||||
assert.Equal(mbtypes.MBID("385ba9e9-626d-4750-a607-58e541dca78e"), listen4.RecordingMBID)
|
||||
}
|
||||
|
||||
func TestParserExcludeSkipped(t *testing.T) {
|
||||
|
@ -75,7 +75,7 @@ func TestParserExcludeSkipped(t *testing.T) {
|
|||
assert.Len(result.Listens, 4)
|
||||
listen4 := result.Listens[3]
|
||||
assert.Equal("L", listen4.AdditionalInfo["rockbox_rating"])
|
||||
assert.Equal(mbtypes.MBID("1262beaf-19f8-4534-b9ed-7eef9ca8e83f"), listen4.RecordingMbid)
|
||||
assert.Equal(mbtypes.MBID("1262beaf-19f8-4534-b9ed-7eef9ca8e83f"), listen4.RecordingMBID)
|
||||
}
|
||||
|
||||
func TestWrite(t *testing.T) {
|
||||
|
@ -94,7 +94,7 @@ func TestWrite(t *testing.T) {
|
|||
TrackName: "Reign",
|
||||
TrackNumber: 1,
|
||||
Duration: 271 * time.Second,
|
||||
RecordingMbid: mbtypes.MBID("b59cf4e7-caee-4019-a844-79d2c58d4dff"),
|
||||
RecordingMBID: mbtypes.MBID("b59cf4e7-caee-4019-a844-79d2c58d4dff"),
|
||||
AdditionalInfo: models.AdditionalInfo{"rockbox_rating": "L"},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -45,11 +45,11 @@ type Track struct {
|
|||
DiscNumber int
|
||||
Duration time.Duration
|
||||
ISRC string
|
||||
RecordingMbid mbtypes.MBID
|
||||
ReleaseMbid mbtypes.MBID
|
||||
ReleaseGroupMbid mbtypes.MBID
|
||||
ArtistMbids []mbtypes.MBID
|
||||
WorkMbids []mbtypes.MBID
|
||||
RecordingMBID mbtypes.MBID
|
||||
ReleaseMBID mbtypes.MBID
|
||||
ReleaseGroupMBID mbtypes.MBID
|
||||
ArtistMBIDs []mbtypes.MBID
|
||||
WorkMBIDs []mbtypes.MBID
|
||||
Tags []string
|
||||
AdditionalInfo AdditionalInfo
|
||||
}
|
||||
|
@ -63,20 +63,20 @@ func (t *Track) FillAdditionalInfo() {
|
|||
if t.AdditionalInfo == nil {
|
||||
t.AdditionalInfo = make(AdditionalInfo, 5)
|
||||
}
|
||||
if t.RecordingMbid != "" {
|
||||
t.AdditionalInfo["recording_mbid"] = t.RecordingMbid
|
||||
if t.RecordingMBID != "" {
|
||||
t.AdditionalInfo["recording_mbid"] = t.RecordingMBID
|
||||
}
|
||||
if t.ReleaseGroupMbid != "" {
|
||||
t.AdditionalInfo["release_group_mbid"] = t.ReleaseGroupMbid
|
||||
if t.ReleaseGroupMBID != "" {
|
||||
t.AdditionalInfo["release_group_mbid"] = t.ReleaseGroupMBID
|
||||
}
|
||||
if t.ReleaseMbid != "" {
|
||||
t.AdditionalInfo["release_mbid"] = t.ReleaseMbid
|
||||
if t.ReleaseMBID != "" {
|
||||
t.AdditionalInfo["release_mbid"] = t.ReleaseMBID
|
||||
}
|
||||
if len(t.ArtistMbids) > 0 {
|
||||
t.AdditionalInfo["artist_mbids"] = t.ArtistMbids
|
||||
if len(t.ArtistMBIDs) > 0 {
|
||||
t.AdditionalInfo["artist_mbids"] = t.ArtistMBIDs
|
||||
}
|
||||
if len(t.WorkMbids) > 0 {
|
||||
t.AdditionalInfo["work_mbids"] = t.WorkMbids
|
||||
if len(t.WorkMBIDs) > 0 {
|
||||
t.AdditionalInfo["work_mbids"] = t.WorkMBIDs
|
||||
}
|
||||
if t.ISRC != "" {
|
||||
t.AdditionalInfo["isrc"] = t.ISRC
|
||||
|
@ -111,7 +111,7 @@ type Love struct {
|
|||
Track
|
||||
Created time.Time
|
||||
UserName string
|
||||
RecordingMbid mbtypes.MBID
|
||||
RecordingMBID mbtypes.MBID
|
||||
RecordingMsid mbtypes.MBID
|
||||
}
|
||||
|
||||
|
|
|
@ -45,11 +45,11 @@ func TestTrackArtistName(t *testing.T) {
|
|||
|
||||
func TestTrackFillAdditionalInfo(t *testing.T) {
|
||||
track := models.Track{
|
||||
RecordingMbid: mbtypes.MBID("c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"),
|
||||
ReleaseGroupMbid: mbtypes.MBID("80aca1ee-aa51-41be-9f75-024710d92ff4"),
|
||||
ReleaseMbid: mbtypes.MBID("aa1ea1ac-7ec4-4542-a494-105afbfe547d"),
|
||||
ArtistMbids: []mbtypes.MBID{"24412926-c7bd-48e8-afad-8a285b42e131"},
|
||||
WorkMbids: []mbtypes.MBID{"c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"},
|
||||
RecordingMBID: mbtypes.MBID("c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"),
|
||||
ReleaseGroupMBID: mbtypes.MBID("80aca1ee-aa51-41be-9f75-024710d92ff4"),
|
||||
ReleaseMBID: mbtypes.MBID("aa1ea1ac-7ec4-4542-a494-105afbfe547d"),
|
||||
ArtistMBIDs: []mbtypes.MBID{"24412926-c7bd-48e8-afad-8a285b42e131"},
|
||||
WorkMBIDs: []mbtypes.MBID{"c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"},
|
||||
TrackNumber: 5,
|
||||
DiscNumber: 1,
|
||||
Duration: time.Duration(413787 * time.Millisecond),
|
||||
|
@ -59,11 +59,11 @@ func TestTrackFillAdditionalInfo(t *testing.T) {
|
|||
track.FillAdditionalInfo()
|
||||
i := track.AdditionalInfo
|
||||
assert := assert.New(t)
|
||||
assert.Equal(track.RecordingMbid, i["recording_mbid"])
|
||||
assert.Equal(track.ReleaseGroupMbid, i["release_group_mbid"])
|
||||
assert.Equal(track.ReleaseMbid, i["release_mbid"])
|
||||
assert.Equal(track.ArtistMbids, i["artist_mbids"])
|
||||
assert.Equal(track.WorkMbids, i["work_mbids"])
|
||||
assert.Equal(track.RecordingMBID, i["recording_mbid"])
|
||||
assert.Equal(track.ReleaseGroupMBID, i["release_group_mbid"])
|
||||
assert.Equal(track.ReleaseMBID, i["release_mbid"])
|
||||
assert.Equal(track.ArtistMBIDs, i["artist_mbids"])
|
||||
assert.Equal(track.WorkMBIDs, i["work_mbids"])
|
||||
assert.Equal(track.TrackNumber, i["tracknumber"])
|
||||
assert.Equal(track.DiscNumber, i["discnumber"])
|
||||
assert.Equal(track.Duration.Milliseconds(), i["duration_ms"])
|
||||
|
|
|
@ -63,7 +63,7 @@ func NormalizeTitle(s string) string {
|
|||
// Compare two tracks for similarity.
|
||||
func CompareTracks(t1 models.Track, t2 models.Track) float64 {
|
||||
// Identical recording MBID always compares 100%
|
||||
if t1.RecordingMbid == t2.RecordingMbid && t1.RecordingMbid != "" {
|
||||
if t1.RecordingMBID == t2.RecordingMBID && t1.RecordingMBID != "" {
|
||||
return 1.0
|
||||
}
|
||||
|
||||
|
|
|
@ -75,13 +75,13 @@ func TestCompareTracksSameMBID(t *testing.T) {
|
|||
t1 := models.Track{
|
||||
ArtistNames: []string{"Paradise Lost"},
|
||||
TrackName: "Forever After",
|
||||
RecordingMbid: mbtypes.MBID("2886d15c-09b0-43c6-af56-932f70dde164"),
|
||||
RecordingMBID: mbtypes.MBID("2886d15c-09b0-43c6-af56-932f70dde164"),
|
||||
}
|
||||
t2 := models.Track{
|
||||
ArtistNames: []string{"Paradise Lost"},
|
||||
TrackName: "Forever Failure (radio edit)",
|
||||
ReleaseName: "Draconian Times",
|
||||
RecordingMbid: mbtypes.MBID("2886d15c-09b0-43c6-af56-932f70dde164"),
|
||||
RecordingMBID: mbtypes.MBID("2886d15c-09b0-43c6-af56-932f70dde164"),
|
||||
}
|
||||
assert.Equal(t, 1.0, similarity.CompareTracks(t1, t2))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue