mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-08 06:39: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
|
@ -41,7 +41,7 @@ func (b *DumpBackend) ImportListens(export models.ListensResult, importResult mo
|
||||||
importResult.UpdateTimestamp(listen.ListenedAt)
|
importResult.UpdateTimestamp(listen.ListenedAt)
|
||||||
importResult.ImportCount += 1
|
importResult.ImportCount += 1
|
||||||
msg := fmt.Sprintf("🎶 %v: \"%v\" by %v (%v)",
|
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)
|
importResult.Log(models.Info, msg)
|
||||||
progress <- models.Progress{}.FromImportResult(importResult)
|
progress <- models.Progress{}.FromImportResult(importResult)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ func (b *DumpBackend) ImportLoves(export models.LovesResult, importResult models
|
||||||
importResult.UpdateTimestamp(love.Created)
|
importResult.UpdateTimestamp(love.Created)
|
||||||
importResult.ImportCount += 1
|
importResult.ImportCount += 1
|
||||||
msg := fmt.Sprintf("❤️ %v: \"%v\" by %v (%v)",
|
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)
|
importResult.Log(models.Info, msg)
|
||||||
progress <- models.Progress{}.FromImportResult(importResult)
|
progress <- models.Progress{}.FromImportResult(importResult)
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,7 +176,7 @@ func (f FavoriteTrack) AsLove() models.Love {
|
||||||
track := f.Track.AsTrack()
|
track := f.Track.AsTrack()
|
||||||
love := models.Love{
|
love := models.Love{
|
||||||
UserName: f.User.UserName,
|
UserName: f.User.UserName,
|
||||||
RecordingMbid: track.RecordingMbid,
|
RecordingMBID: track.RecordingMBID,
|
||||||
Track: track,
|
Track: track,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,16 +189,16 @@ func (f FavoriteTrack) AsLove() models.Love {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Track) AsTrack() models.Track {
|
func (t Track) AsTrack() models.Track {
|
||||||
recordingMbid := mbtypes.MBID(t.RecordingMbid)
|
recordingMBID := mbtypes.MBID(t.RecordingMBID)
|
||||||
track := models.Track{
|
track := models.Track{
|
||||||
TrackName: t.Title,
|
TrackName: t.Title,
|
||||||
ReleaseName: t.Album.Title,
|
ReleaseName: t.Album.Title,
|
||||||
ArtistNames: []string{t.Artist.Name},
|
ArtistNames: []string{t.Artist.Name},
|
||||||
TrackNumber: t.Position,
|
TrackNumber: t.Position,
|
||||||
DiscNumber: t.DiscNumber,
|
DiscNumber: t.DiscNumber,
|
||||||
RecordingMbid: recordingMbid,
|
RecordingMBID: recordingMBID,
|
||||||
ReleaseMbid: mbtypes.MBID(t.Album.ReleaseMbid),
|
ReleaseMBID: mbtypes.MBID(t.Album.ReleaseMBID),
|
||||||
ArtistMbids: []mbtypes.MBID{mbtypes.MBID(t.Artist.ArtistMbid)},
|
ArtistMBIDs: []mbtypes.MBID{mbtypes.MBID(t.Artist.ArtistMBID)},
|
||||||
Tags: t.Tags,
|
Tags: t.Tags,
|
||||||
AdditionalInfo: map[string]any{
|
AdditionalInfo: map[string]any{
|
||||||
"media_player": FunkwhaleClientName,
|
"media_player": FunkwhaleClientName,
|
||||||
|
|
|
@ -44,17 +44,17 @@ func TestFunkwhaleListeningAsListen(t *testing.T) {
|
||||||
},
|
},
|
||||||
Track: funkwhale.Track{
|
Track: funkwhale.Track{
|
||||||
Title: "Oweynagat",
|
Title: "Oweynagat",
|
||||||
RecordingMbid: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
RecordingMBID: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
||||||
Position: 5,
|
Position: 5,
|
||||||
DiscNumber: 1,
|
DiscNumber: 1,
|
||||||
Tags: []string{"foo", "bar"},
|
Tags: []string{"foo", "bar"},
|
||||||
Artist: funkwhale.Artist{
|
Artist: funkwhale.Artist{
|
||||||
Name: "Dool",
|
Name: "Dool",
|
||||||
ArtistMbid: "24412926-c7bd-48e8-afad-8a285b42e131",
|
ArtistMBID: "24412926-c7bd-48e8-afad-8a285b42e131",
|
||||||
},
|
},
|
||||||
Album: funkwhale.Album{
|
Album: funkwhale.Album{
|
||||||
Title: "Here Now, There Then",
|
Title: "Here Now, There Then",
|
||||||
ReleaseMbid: "d7f22677-9803-4d21-ba42-081b633a6f68",
|
ReleaseMBID: "d7f22677-9803-4d21-ba42-081b633a6f68",
|
||||||
},
|
},
|
||||||
Uploads: []funkwhale.Upload{
|
Uploads: []funkwhale.Upload{
|
||||||
{
|
{
|
||||||
|
@ -75,9 +75,9 @@ func TestFunkwhaleListeningAsListen(t *testing.T) {
|
||||||
assert.Equal(fwListen.Track.DiscNumber, listen.Track.DiscNumber)
|
assert.Equal(fwListen.Track.DiscNumber, listen.Track.DiscNumber)
|
||||||
assert.Equal(fwListen.Track.Tags, listen.Track.Tags)
|
assert.Equal(fwListen.Track.Tags, listen.Track.Tags)
|
||||||
// assert.Equal(backends.FunkwhaleClientName, listen.AdditionalInfo["disc_number"])
|
// assert.Equal(backends.FunkwhaleClientName, listen.AdditionalInfo["disc_number"])
|
||||||
assert.Equal(mbtypes.MBID(fwListen.Track.RecordingMbid), listen.RecordingMbid)
|
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.Album.ReleaseMBID), listen.ReleaseMBID)
|
||||||
assert.Equal(mbtypes.MBID(fwListen.Track.Artist.ArtistMbid), listen.ArtistMbids[0])
|
assert.Equal(mbtypes.MBID(fwListen.Track.Artist.ArtistMBID), listen.ArtistMBIDs[0])
|
||||||
assert.Equal(funkwhale.FunkwhaleClientName, listen.AdditionalInfo["media_player"])
|
assert.Equal(funkwhale.FunkwhaleClientName, listen.AdditionalInfo["media_player"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,17 +89,17 @@ func TestFunkwhaleFavoriteTrackAsLove(t *testing.T) {
|
||||||
},
|
},
|
||||||
Track: funkwhale.Track{
|
Track: funkwhale.Track{
|
||||||
Title: "Oweynagat",
|
Title: "Oweynagat",
|
||||||
RecordingMbid: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
RecordingMBID: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
||||||
Position: 5,
|
Position: 5,
|
||||||
DiscNumber: 1,
|
DiscNumber: 1,
|
||||||
Tags: []string{"foo", "bar"},
|
Tags: []string{"foo", "bar"},
|
||||||
Artist: funkwhale.Artist{
|
Artist: funkwhale.Artist{
|
||||||
Name: "Dool",
|
Name: "Dool",
|
||||||
ArtistMbid: "24412926-c7bd-48e8-afad-8a285b42e131",
|
ArtistMBID: "24412926-c7bd-48e8-afad-8a285b42e131",
|
||||||
},
|
},
|
||||||
Album: funkwhale.Album{
|
Album: funkwhale.Album{
|
||||||
Title: "Here Now, There Then",
|
Title: "Here Now, There Then",
|
||||||
ReleaseMbid: "d7f22677-9803-4d21-ba42-081b633a6f68",
|
ReleaseMBID: "d7f22677-9803-4d21-ba42-081b633a6f68",
|
||||||
},
|
},
|
||||||
Uploads: []funkwhale.Upload{
|
Uploads: []funkwhale.Upload{
|
||||||
{
|
{
|
||||||
|
@ -119,10 +119,10 @@ func TestFunkwhaleFavoriteTrackAsLove(t *testing.T) {
|
||||||
assert.Equal(favorite.Track.Position, love.Track.TrackNumber)
|
assert.Equal(favorite.Track.Position, love.Track.TrackNumber)
|
||||||
assert.Equal(favorite.Track.DiscNumber, love.Track.DiscNumber)
|
assert.Equal(favorite.Track.DiscNumber, love.Track.DiscNumber)
|
||||||
assert.Equal(favorite.Track.Tags, love.Track.Tags)
|
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.RecordingMBID)
|
||||||
assert.Equal(mbtypes.MBID(favorite.Track.RecordingMbid), love.Track.RecordingMbid)
|
assert.Equal(mbtypes.MBID(favorite.Track.RecordingMBID), love.Track.RecordingMBID)
|
||||||
assert.Equal(mbtypes.MBID(favorite.Track.Album.ReleaseMbid), love.ReleaseMbid)
|
assert.Equal(mbtypes.MBID(favorite.Track.Album.ReleaseMBID), love.ReleaseMBID)
|
||||||
require.Len(t, love.Track.ArtistMbids, 1)
|
require.Len(t, love.Track.ArtistMBIDs, 1)
|
||||||
assert.Equal(mbtypes.MBID(favorite.Track.Artist.ArtistMbid), love.ArtistMbids[0])
|
assert.Equal(mbtypes.MBID(favorite.Track.Artist.ArtistMBID), love.ArtistMBIDs[0])
|
||||||
assert.Equal(funkwhale.FunkwhaleClientName, love.AdditionalInfo["media_player"])
|
assert.Equal(funkwhale.FunkwhaleClientName, love.AdditionalInfo["media_player"])
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ type Track struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Position int `json:"position"`
|
Position int `json:"position"`
|
||||||
DiscNumber int `json:"disc_number"`
|
DiscNumber int `json:"disc_number"`
|
||||||
RecordingMbid string `json:"mbid"`
|
RecordingMBID string `json:"mbid"`
|
||||||
Tags []string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
Uploads []Upload `json:"uploads"`
|
Uploads []Upload `json:"uploads"`
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ type Track struct {
|
||||||
type Artist struct {
|
type Artist struct {
|
||||||
Id int `json:"int"`
|
Id int `json:"int"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
ArtistMbid string `json:"mbid"`
|
ArtistMBID string `json:"mbid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Album struct {
|
type Album struct {
|
||||||
|
@ -73,7 +73,7 @@ type Album struct {
|
||||||
AlbumArtist Artist `json:"artist"`
|
AlbumArtist Artist `json:"artist"`
|
||||||
ReleaseDate string `json:"release_date"`
|
ReleaseDate string `json:"release_date"`
|
||||||
TrackCount int `json:"track_count"`
|
TrackCount int `json:"track_count"`
|
||||||
ReleaseMbid string `json:"mbid"`
|
ReleaseMBID string `json:"mbid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
|
|
@ -118,8 +118,8 @@ func listenAsTrack(l models.Listen) jspf.Track {
|
||||||
extension.AddedBy = l.UserName
|
extension.AddedBy = l.UserName
|
||||||
track.Extension[jspf.MusicBrainzTrackExtensionId] = extension
|
track.Extension[jspf.MusicBrainzTrackExtensionId] = extension
|
||||||
|
|
||||||
if l.RecordingMbid != "" {
|
if l.RecordingMBID != "" {
|
||||||
track.Identifier = append(track.Identifier, "https://musicbrainz.org/recording/"+string(l.RecordingMbid))
|
track.Identifier = append(track.Identifier, "https://musicbrainz.org/recording/"+string(l.RecordingMBID))
|
||||||
}
|
}
|
||||||
|
|
||||||
return track
|
return track
|
||||||
|
@ -133,12 +133,12 @@ func loveAsTrack(l models.Love) jspf.Track {
|
||||||
extension.AddedBy = l.UserName
|
extension.AddedBy = l.UserName
|
||||||
track.Extension[jspf.MusicBrainzTrackExtensionId] = extension
|
track.Extension[jspf.MusicBrainzTrackExtensionId] = extension
|
||||||
|
|
||||||
recordingMbid := l.Track.RecordingMbid
|
recordingMBID := l.Track.RecordingMBID
|
||||||
if l.RecordingMbid != "" {
|
if l.RecordingMBID != "" {
|
||||||
recordingMbid = l.RecordingMbid
|
recordingMBID = l.RecordingMBID
|
||||||
}
|
}
|
||||||
if recordingMbid != "" {
|
if recordingMBID != "" {
|
||||||
track.Identifier = append(track.Identifier, "https://musicbrainz.org/recording/"+string(recordingMbid))
|
track.Identifier = append(track.Identifier, "https://musicbrainz.org/recording/"+string(recordingMBID))
|
||||||
}
|
}
|
||||||
|
|
||||||
return track
|
return track
|
||||||
|
@ -159,15 +159,15 @@ func trackAsTrack(t models.Track) jspf.Track {
|
||||||
func makeMusicBrainzExtension(t models.Track) jspf.MusicBrainzTrackExtension {
|
func makeMusicBrainzExtension(t models.Track) jspf.MusicBrainzTrackExtension {
|
||||||
extension := jspf.MusicBrainzTrackExtension{
|
extension := jspf.MusicBrainzTrackExtension{
|
||||||
AdditionalMetadata: t.AdditionalInfo,
|
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)
|
extension.ArtistIdentifiers[i] = "https://musicbrainz.org/artist/" + string(mbid)
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.ReleaseMbid != "" {
|
if t.ReleaseMBID != "" {
|
||||||
extension.ReleaseIdentifier = "https://musicbrainz.org/release/" + string(t.ReleaseMbid)
|
extension.ReleaseIdentifier = "https://musicbrainz.org/release/" + string(t.ReleaseMBID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The tracknumber tag would be redundant
|
// The tracknumber tag would be redundant
|
||||||
|
|
|
@ -141,16 +141,16 @@ out:
|
||||||
TrackName: scrobble.Name,
|
TrackName: scrobble.Name,
|
||||||
ArtistNames: []string{},
|
ArtistNames: []string{},
|
||||||
ReleaseName: scrobble.Album.Name,
|
ReleaseName: scrobble.Album.Name,
|
||||||
RecordingMbid: mbtypes.MBID(scrobble.Mbid),
|
RecordingMBID: mbtypes.MBID(scrobble.Mbid),
|
||||||
ArtistMbids: []mbtypes.MBID{},
|
ArtistMBIDs: []mbtypes.MBID{},
|
||||||
ReleaseMbid: mbtypes.MBID(scrobble.Album.Mbid),
|
ReleaseMBID: mbtypes.MBID(scrobble.Album.Mbid),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if scrobble.Artist.Name != "" {
|
if scrobble.Artist.Name != "" {
|
||||||
listen.Track.ArtistNames = []string{scrobble.Artist.Name}
|
listen.Track.ArtistNames = []string{scrobble.Artist.Name}
|
||||||
}
|
}
|
||||||
if scrobble.Artist.Mbid != "" {
|
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)
|
listens = append(listens, listen)
|
||||||
} else {
|
} else {
|
||||||
|
@ -204,8 +204,8 @@ func (b *LastfmApiBackend) ImportListens(export models.ListensResult, importResu
|
||||||
if l.TrackNumber > 0 {
|
if l.TrackNumber > 0 {
|
||||||
trackNumbers = append(trackNumbers, strconv.Itoa(l.TrackNumber))
|
trackNumbers = append(trackNumbers, strconv.Itoa(l.TrackNumber))
|
||||||
}
|
}
|
||||||
if l.RecordingMbid != "" {
|
if l.RecordingMBID != "" {
|
||||||
mbids = append(mbids, string(l.RecordingMbid))
|
mbids = append(mbids, string(l.RecordingMBID))
|
||||||
}
|
}
|
||||||
// if l.ReleaseArtist != "" {
|
// if l.ReleaseArtist != "" {
|
||||||
// albumArtists = append(albums, l.ReleaseArtist)
|
// albumArtists = append(albums, l.ReleaseArtist)
|
||||||
|
@ -295,12 +295,12 @@ out:
|
||||||
love := models.Love{
|
love := models.Love{
|
||||||
Created: time.Unix(timestamp, 0),
|
Created: time.Unix(timestamp, 0),
|
||||||
UserName: result.User,
|
UserName: result.User,
|
||||||
RecordingMbid: mbtypes.MBID(track.Mbid),
|
RecordingMBID: mbtypes.MBID(track.Mbid),
|
||||||
Track: models.Track{
|
Track: models.Track{
|
||||||
TrackName: track.Name,
|
TrackName: track.Name,
|
||||||
ArtistNames: []string{track.Artist.Name},
|
ArtistNames: []string{track.Artist.Name},
|
||||||
RecordingMbid: mbtypes.MBID(track.Mbid),
|
RecordingMBID: mbtypes.MBID(track.Mbid),
|
||||||
ArtistMbids: []mbtypes.MBID{mbtypes.MBID(track.Artist.Mbid)},
|
ArtistMBIDs: []mbtypes.MBID{mbtypes.MBID(track.Artist.Mbid)},
|
||||||
AdditionalInfo: models.AdditionalInfo{
|
AdditionalInfo: models.AdditionalInfo{
|
||||||
"lastfm_url": track.Url,
|
"lastfm_url": track.Url,
|
||||||
},
|
},
|
||||||
|
|
|
@ -114,7 +114,7 @@ func TestGetFeedback(t *testing.T) {
|
||||||
assert.Equal(302, result.TotalCount)
|
assert.Equal(302, result.TotalCount)
|
||||||
assert.Equal(3, result.Offset)
|
assert.Equal(3, result.Offset)
|
||||||
require.Len(t, result.Feedback, 2)
|
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) {
|
func TestSendFeedback(t *testing.T) {
|
||||||
|
@ -131,7 +131,7 @@ func TestSendFeedback(t *testing.T) {
|
||||||
httpmock.RegisterResponder("POST", url, responder)
|
httpmock.RegisterResponder("POST", url, responder)
|
||||||
|
|
||||||
feedback := listenbrainz.Feedback{
|
feedback := listenbrainz.Feedback{
|
||||||
RecordingMbid: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
RecordingMBID: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
||||||
Score: 1,
|
Score: 1,
|
||||||
}
|
}
|
||||||
result, err := client.SendFeedback(feedback)
|
result, err := client.SendFeedback(feedback)
|
||||||
|
@ -154,7 +154,7 @@ func TestLookup(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
assert.Equal("Say Just Words", result.RecordingName)
|
assert.Equal("Say Just Words", result.RecordingName)
|
||||||
assert.Equal("Paradise Lost", result.ArtistCreditName)
|
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) {
|
func setupHttpMock(t *testing.T, client *http.Client, url string, testDataPath string) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ type ListenBrainzApiBackend struct {
|
||||||
client Client
|
client Client
|
||||||
username string
|
username string
|
||||||
checkDuplicates bool
|
checkDuplicates bool
|
||||||
existingMbids map[string]bool
|
existingMBIDs map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *ListenBrainzApiBackend) Name() string { return "listenbrainz" }
|
func (b *ListenBrainzApiBackend) Name() string { return "listenbrainz" }
|
||||||
|
@ -148,7 +148,7 @@ func (b *ListenBrainzApiBackend) ImportListens(export models.ListensResult, impo
|
||||||
} else if isDupe {
|
} else if isDupe {
|
||||||
count -= 1
|
count -= 1
|
||||||
msg := i18n.Tr("Ignored duplicate listen %v: \"%v\" by %v (%v)",
|
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)
|
importResult.Log(models.Info, msg)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *ListenBrainzApiBackend) ImportLoves(export models.LovesResult, importResult models.ImportResult, progress chan models.Progress) (models.ImportResult, error) {
|
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)
|
existingLovesChan := make(chan models.LovesResult)
|
||||||
go b.ExportLoves(time.Unix(0, 0), existingLovesChan, progress)
|
go b.ExportLoves(time.Unix(0, 0), existingLovesChan, progress)
|
||||||
existingLoves := <-existingLovesChan
|
existingLoves := <-existingLovesChan
|
||||||
|
@ -239,30 +239,30 @@ func (b *ListenBrainzApiBackend) ImportLoves(export models.LovesResult, importRe
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Store MBIDs directly
|
// 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 {
|
for _, love := range existingLoves.Items {
|
||||||
b.existingMbids[string(love.RecordingMbid)] = true
|
b.existingMBIDs[string(love.RecordingMBID)] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, love := range export.Items {
|
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())
|
lookup, err := b.client.Lookup(love.TrackName, love.ArtistName())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
recordingMbid = lookup.RecordingMbid
|
recordingMBID = lookup.RecordingMBID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if recordingMbid != "" {
|
if recordingMBID != "" {
|
||||||
ok := false
|
ok := false
|
||||||
errMsg := ""
|
errMsg := ""
|
||||||
if b.existingMbids[recordingMbid] {
|
if b.existingMBIDs[recordingMBID] {
|
||||||
ok = true
|
ok = true
|
||||||
} else {
|
} else {
|
||||||
resp, err := b.client.SendFeedback(Feedback{
|
resp, err := b.client.SendFeedback(Feedback{
|
||||||
RecordingMbid: recordingMbid,
|
RecordingMBID: recordingMBID,
|
||||||
Score: 1,
|
Score: 1,
|
||||||
})
|
})
|
||||||
ok = err == nil && resp.Status == "ok"
|
ok = err == nil && resp.Status == "ok"
|
||||||
|
@ -324,20 +324,20 @@ func (lbListen Listen) AsListen() models.Listen {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Feedback) AsLove() models.Love {
|
func (f Feedback) AsLove() models.Love {
|
||||||
recordingMbid := mbtypes.MBID(f.RecordingMbid)
|
recordingMBID := mbtypes.MBID(f.RecordingMBID)
|
||||||
track := f.TrackMetadata
|
track := f.TrackMetadata
|
||||||
if track == nil {
|
if track == nil {
|
||||||
track = &Track{}
|
track = &Track{}
|
||||||
}
|
}
|
||||||
love := models.Love{
|
love := models.Love{
|
||||||
UserName: f.UserName,
|
UserName: f.UserName,
|
||||||
RecordingMbid: recordingMbid,
|
RecordingMBID: recordingMBID,
|
||||||
Created: time.Unix(f.Created, 0),
|
Created: time.Unix(f.Created, 0),
|
||||||
Track: track.AsTrack(),
|
Track: track.AsTrack(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if love.Track.RecordingMbid == "" {
|
if love.Track.RecordingMBID == "" {
|
||||||
love.Track.RecordingMbid = love.RecordingMbid
|
love.Track.RecordingMBID = love.RecordingMBID
|
||||||
}
|
}
|
||||||
|
|
||||||
return love
|
return love
|
||||||
|
@ -351,16 +351,16 @@ func (t Track) AsTrack() models.Track {
|
||||||
Duration: t.Duration(),
|
Duration: t.Duration(),
|
||||||
TrackNumber: t.TrackNumber(),
|
TrackNumber: t.TrackNumber(),
|
||||||
DiscNumber: t.DiscNumber(),
|
DiscNumber: t.DiscNumber(),
|
||||||
RecordingMbid: mbtypes.MBID(t.RecordingMbid()),
|
RecordingMBID: mbtypes.MBID(t.RecordingMBID()),
|
||||||
ReleaseMbid: mbtypes.MBID(t.ReleaseMbid()),
|
ReleaseMBID: mbtypes.MBID(t.ReleaseMBID()),
|
||||||
ReleaseGroupMbid: mbtypes.MBID(t.ReleaseGroupMbid()),
|
ReleaseGroupMBID: mbtypes.MBID(t.ReleaseGroupMBID()),
|
||||||
ISRC: t.ISRC(),
|
ISRC: t.ISRC(),
|
||||||
AdditionalInfo: t.AdditionalInfo,
|
AdditionalInfo: t.AdditionalInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.MbidMapping != nil && len(track.ArtistMbids) == 0 {
|
if t.MBIDMapping != nil && len(track.ArtistMBIDs) == 0 {
|
||||||
for _, artistMbid := range t.MbidMapping.ArtistMbids {
|
for _, artistMBID := range t.MBIDMapping.ArtistMBIDs {
|
||||||
track.ArtistMbids = append(track.ArtistMbids, mbtypes.MBID(artistMbid))
|
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, []string{lbListen.TrackMetadata.ArtistName}, listen.ArtistNames)
|
||||||
assert.Equal(t, 5, listen.TrackNumber)
|
assert.Equal(t, 5, listen.TrackNumber)
|
||||||
assert.Equal(t, 1, listen.DiscNumber)
|
assert.Equal(t, 1, listen.DiscNumber)
|
||||||
assert.Equal(t, mbtypes.MBID("c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"), listen.RecordingMbid)
|
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("d7f22677-9803-4d21-ba42-081b633a6f68"), listen.ReleaseMBID)
|
||||||
assert.Equal(t, mbtypes.MBID("80aca1ee-aa51-41be-9f75-024710d92ff4"), listen.ReleaseGroupMbid)
|
assert.Equal(t, mbtypes.MBID("80aca1ee-aa51-41be-9f75-024710d92ff4"), listen.ReleaseGroupMBID)
|
||||||
assert.Equal(t, "DES561620801", listen.ISRC)
|
assert.Equal(t, "DES561620801", listen.ISRC)
|
||||||
assert.Equal(t, lbListen.TrackMetadata.AdditionalInfo["foo"], listen.AdditionalInfo["foo"])
|
assert.Equal(t, lbListen.TrackMetadata.AdditionalInfo["foo"], listen.AdditionalInfo["foo"])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListenBrainzFeedbackAsLove(t *testing.T) {
|
func TestListenBrainzFeedbackAsLove(t *testing.T) {
|
||||||
recordingMbid := "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"
|
recordingMBID := "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"
|
||||||
releaseMbid := "d7f22677-9803-4d21-ba42-081b633a6f68"
|
releaseMBID := "d7f22677-9803-4d21-ba42-081b633a6f68"
|
||||||
artistMbid := "d7f22677-9803-4d21-ba42-081b633a6f68"
|
artistMBID := "d7f22677-9803-4d21-ba42-081b633a6f68"
|
||||||
feedback := listenbrainz.Feedback{
|
feedback := listenbrainz.Feedback{
|
||||||
Created: 1699859066,
|
Created: 1699859066,
|
||||||
RecordingMbid: recordingMbid,
|
RecordingMBID: recordingMBID,
|
||||||
Score: 1,
|
Score: 1,
|
||||||
UserName: "ousidecontext",
|
UserName: "ousidecontext",
|
||||||
TrackMetadata: &listenbrainz.Track{
|
TrackMetadata: &listenbrainz.Track{
|
||||||
TrackName: "Oweynagat",
|
TrackName: "Oweynagat",
|
||||||
ArtistName: "Dool",
|
ArtistName: "Dool",
|
||||||
ReleaseName: "Here Now, There Then",
|
ReleaseName: "Here Now, There Then",
|
||||||
MbidMapping: &listenbrainz.MbidMapping{
|
MBIDMapping: &listenbrainz.MBIDMapping{
|
||||||
RecordingMbid: recordingMbid,
|
RecordingMBID: recordingMBID,
|
||||||
ReleaseMbid: releaseMbid,
|
ReleaseMBID: releaseMBID,
|
||||||
ArtistMbids: []string{artistMbid},
|
ArtistMBIDs: []string{artistMBID},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -99,24 +99,24 @@ func TestListenBrainzFeedbackAsLove(t *testing.T) {
|
||||||
assert.Equal(feedback.TrackMetadata.TrackName, love.TrackName)
|
assert.Equal(feedback.TrackMetadata.TrackName, love.TrackName)
|
||||||
assert.Equal(feedback.TrackMetadata.ReleaseName, love.ReleaseName)
|
assert.Equal(feedback.TrackMetadata.ReleaseName, love.ReleaseName)
|
||||||
assert.Equal([]string{feedback.TrackMetadata.ArtistName}, love.ArtistNames)
|
assert.Equal([]string{feedback.TrackMetadata.ArtistName}, love.ArtistNames)
|
||||||
assert.Equal(mbtypes.MBID(recordingMbid), love.RecordingMbid)
|
assert.Equal(mbtypes.MBID(recordingMBID), love.RecordingMBID)
|
||||||
assert.Equal(mbtypes.MBID(recordingMbid), love.Track.RecordingMbid)
|
assert.Equal(mbtypes.MBID(recordingMBID), love.Track.RecordingMBID)
|
||||||
assert.Equal(mbtypes.MBID(releaseMbid), love.Track.ReleaseMbid)
|
assert.Equal(mbtypes.MBID(releaseMBID), love.Track.ReleaseMBID)
|
||||||
require.Len(t, love.Track.ArtistMbids, 1)
|
require.Len(t, love.Track.ArtistMBIDs, 1)
|
||||||
assert.Equal(mbtypes.MBID(artistMbid), love.Track.ArtistMbids[0])
|
assert.Equal(mbtypes.MBID(artistMBID), love.Track.ArtistMBIDs[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListenBrainzPartialFeedbackAsLove(t *testing.T) {
|
func TestListenBrainzPartialFeedbackAsLove(t *testing.T) {
|
||||||
recordingMbid := "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"
|
recordingMBID := "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"
|
||||||
feedback := listenbrainz.Feedback{
|
feedback := listenbrainz.Feedback{
|
||||||
Created: 1699859066,
|
Created: 1699859066,
|
||||||
RecordingMbid: recordingMbid,
|
RecordingMBID: recordingMBID,
|
||||||
Score: 1,
|
Score: 1,
|
||||||
}
|
}
|
||||||
love := feedback.AsLove()
|
love := feedback.AsLove()
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
assert.Equal(time.Unix(1699859066, 0).Unix(), love.Created.Unix())
|
assert.Equal(time.Unix(1699859066, 0).Unix(), love.Created.Unix())
|
||||||
assert.Equal(mbtypes.MBID(recordingMbid), love.RecordingMbid)
|
assert.Equal(mbtypes.MBID(recordingMBID), love.RecordingMBID)
|
||||||
assert.Equal(mbtypes.MBID(recordingMbid), love.Track.RecordingMbid)
|
assert.Equal(mbtypes.MBID(recordingMBID), love.Track.RecordingMBID)
|
||||||
assert.Empty(love.Track.TrackName)
|
assert.Empty(love.Track.TrackName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,20 +66,20 @@ type Track struct {
|
||||||
ArtistName string `json:"artist_name,omitempty"`
|
ArtistName string `json:"artist_name,omitempty"`
|
||||||
ReleaseName string `json:"release_name,omitempty"`
|
ReleaseName string `json:"release_name,omitempty"`
|
||||||
AdditionalInfo map[string]any `json:"additional_info,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"`
|
RecordingName string `json:"recording_name,omitempty"`
|
||||||
RecordingMbid string `json:"recording_mbid,omitempty"`
|
RecordingMBID string `json:"recording_mbid,omitempty"`
|
||||||
ReleaseMbid string `json:"release_mbid,omitempty"`
|
ReleaseMBID string `json:"release_mbid,omitempty"`
|
||||||
ArtistMbids []string `json:"artist_mbids,omitempty"`
|
ArtistMBIDs []string `json:"artist_mbids,omitempty"`
|
||||||
Artists []Artist `json:"artists,omitempty"`
|
Artists []Artist `json:"artists,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Artist struct {
|
type Artist struct {
|
||||||
ArtistCreditName string `json:"artist_credit_name,omitempty"`
|
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"`
|
JoinPhrase string `json:"join_phrase,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ type GetFeedbackResult struct {
|
||||||
|
|
||||||
type Feedback struct {
|
type Feedback struct {
|
||||||
Created int64 `json:"created,omitempty"`
|
Created int64 `json:"created,omitempty"`
|
||||||
RecordingMbid string `json:"recording_mbid,omitempty"`
|
RecordingMBID string `json:"recording_mbid,omitempty"`
|
||||||
RecordingMsid string `json:"recording_msid,omitempty"`
|
RecordingMsid string `json:"recording_msid,omitempty"`
|
||||||
Score int `json:"score,omitempty"`
|
Score int `json:"score,omitempty"`
|
||||||
TrackMetadata *Track `json:"track_metadata,omitempty"`
|
TrackMetadata *Track `json:"track_metadata,omitempty"`
|
||||||
|
@ -103,9 +103,9 @@ type LookupResult struct {
|
||||||
ArtistCreditName string `json:"artist_credit_name"`
|
ArtistCreditName string `json:"artist_credit_name"`
|
||||||
ReleaseName string `json:"release_name"`
|
ReleaseName string `json:"release_name"`
|
||||||
RecordingName string `json:"recording_name"`
|
RecordingName string `json:"recording_name"`
|
||||||
RecordingMbid string `json:"recording_mbid"`
|
RecordingMBID string `json:"recording_mbid"`
|
||||||
ReleaseMbid string `json:"release_mbid"`
|
ReleaseMBID string `json:"release_mbid"`
|
||||||
ArtistMbids []string `json:"artist_mbids"`
|
ArtistMBIDs []string `json:"artist_mbids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatusResult struct {
|
type StatusResult struct {
|
||||||
|
@ -162,25 +162,25 @@ func (t Track) ISRC() string {
|
||||||
return tryGetValueOrEmpty[string](t.AdditionalInfo, "isrc")
|
return tryGetValueOrEmpty[string](t.AdditionalInfo, "isrc")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Track) RecordingMbid() string {
|
func (t Track) RecordingMBID() string {
|
||||||
mbid := tryGetValueOrEmpty[string](t.AdditionalInfo, "recording_mbid")
|
mbid := tryGetValueOrEmpty[string](t.AdditionalInfo, "recording_mbid")
|
||||||
if mbid == "" && t.MbidMapping != nil {
|
if mbid == "" && t.MBIDMapping != nil {
|
||||||
return t.MbidMapping.RecordingMbid
|
return t.MBIDMapping.RecordingMBID
|
||||||
} else {
|
} else {
|
||||||
return mbid
|
return mbid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Track) ReleaseMbid() string {
|
func (t Track) ReleaseMBID() string {
|
||||||
mbid := tryGetValueOrEmpty[string](t.AdditionalInfo, "release_mbid")
|
mbid := tryGetValueOrEmpty[string](t.AdditionalInfo, "release_mbid")
|
||||||
if mbid == "" && t.MbidMapping != nil {
|
if mbid == "" && t.MBIDMapping != nil {
|
||||||
return t.MbidMapping.ReleaseMbid
|
return t.MBIDMapping.ReleaseMBID
|
||||||
} else {
|
} else {
|
||||||
return mbid
|
return mbid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Track) ReleaseGroupMbid() string {
|
func (t Track) ReleaseGroupMBID() string {
|
||||||
return tryGetValueOrEmpty[string](t.AdditionalInfo, "release_group_mbid")
|
return tryGetValueOrEmpty[string](t.AdditionalInfo, "release_group_mbid")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,40 +140,40 @@ func TestTrackIsrc(t *testing.T) {
|
||||||
assert.Equal(t, expected, track.ISRC())
|
assert.Equal(t, expected, track.ISRC())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTrackRecordingMbid(t *testing.T) {
|
func TestTrackRecordingMBID(t *testing.T) {
|
||||||
expected := "e02cc1c3-93fd-4e24-8b77-325060de920b"
|
expected := "e02cc1c3-93fd-4e24-8b77-325060de920b"
|
||||||
track := listenbrainz.Track{
|
track := listenbrainz.Track{
|
||||||
AdditionalInfo: map[string]any{
|
AdditionalInfo: map[string]any{
|
||||||
"recording_mbid": expected,
|
"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"
|
expected := "e02cc1c3-93fd-4e24-8b77-325060de920b"
|
||||||
track := listenbrainz.Track{
|
track := listenbrainz.Track{
|
||||||
AdditionalInfo: map[string]any{
|
AdditionalInfo: map[string]any{
|
||||||
"release_mbid": expected,
|
"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"
|
expected := "e02cc1c3-93fd-4e24-8b77-325060de920b"
|
||||||
track := listenbrainz.Track{
|
track := listenbrainz.Track{
|
||||||
AdditionalInfo: map[string]any{
|
AdditionalInfo: map[string]any{
|
||||||
"release_group_mbid": expected,
|
"release_group_mbid": expected,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.Equal(t, expected, track.ReleaseGroupMbid())
|
assert.Equal(t, expected, track.ReleaseGroupMBID())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMarshalPartialFeedback(t *testing.T) {
|
func TestMarshalPartialFeedback(t *testing.T) {
|
||||||
feedback := listenbrainz.Feedback{
|
feedback := listenbrainz.Feedback{
|
||||||
Created: 1699859066,
|
Created: 1699859066,
|
||||||
RecordingMbid: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
RecordingMBID: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
||||||
}
|
}
|
||||||
b, err := json.Marshal(feedback)
|
b, err := json.Marshal(feedback)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -58,7 +58,7 @@ func Parse(data io.Reader, includeSkipped bool) (ScrobblerLog, error) {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// A row is:
|
// A row is:
|
||||||
// artistName releaseName trackName trackNumber duration rating timestamp recordingMbid
|
// artistName releaseName trackName trackNumber duration rating timestamp recordingMBID
|
||||||
row, err := tsvReader.Read()
|
row, err := tsvReader.Read()
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
break
|
break
|
||||||
|
@ -101,7 +101,7 @@ func Write(data io.Writer, listens models.ListensList) (lastTimestamp time.Time,
|
||||||
}
|
}
|
||||||
|
|
||||||
// A row is:
|
// 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)
|
rating, ok := listen.AdditionalInfo["rockbox_rating"].(string)
|
||||||
if !ok || rating == "" {
|
if !ok || rating == "" {
|
||||||
rating = "L"
|
rating = "L"
|
||||||
|
@ -114,7 +114,7 @@ func Write(data io.Writer, listens models.ListensList) (lastTimestamp time.Time,
|
||||||
strconv.Itoa(int(listen.Duration.Seconds())),
|
strconv.Itoa(int(listen.Duration.Seconds())),
|
||||||
rating,
|
rating,
|
||||||
strconv.Itoa(int(listen.ListenedAt.Unix())),
|
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 {
|
if len(row) > 7 {
|
||||||
listen.Track.RecordingMbid = mbtypes.MBID(row[7])
|
listen.Track.RecordingMBID = mbtypes.MBID(row[7])
|
||||||
}
|
}
|
||||||
|
|
||||||
return listen, nil
|
return listen, nil
|
||||||
|
|
|
@ -61,10 +61,10 @@ func TestParser(t *testing.T) {
|
||||||
assert.Equal(time.Duration(306*time.Second), listen1.Duration)
|
assert.Equal(time.Duration(306*time.Second), listen1.Duration)
|
||||||
assert.Equal("L", listen1.AdditionalInfo["rockbox_rating"])
|
assert.Equal("L", listen1.AdditionalInfo["rockbox_rating"])
|
||||||
assert.Equal(time.Unix(1260342084, 0), listen1.ListenedAt)
|
assert.Equal(time.Unix(1260342084, 0), listen1.ListenedAt)
|
||||||
assert.Equal(mbtypes.MBID(""), listen1.RecordingMbid)
|
assert.Equal(mbtypes.MBID(""), listen1.RecordingMBID)
|
||||||
listen4 := result.Listens[3]
|
listen4 := result.Listens[3]
|
||||||
assert.Equal("S", listen4.AdditionalInfo["rockbox_rating"])
|
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) {
|
func TestParserExcludeSkipped(t *testing.T) {
|
||||||
|
@ -75,7 +75,7 @@ func TestParserExcludeSkipped(t *testing.T) {
|
||||||
assert.Len(result.Listens, 4)
|
assert.Len(result.Listens, 4)
|
||||||
listen4 := result.Listens[3]
|
listen4 := result.Listens[3]
|
||||||
assert.Equal("L", listen4.AdditionalInfo["rockbox_rating"])
|
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) {
|
func TestWrite(t *testing.T) {
|
||||||
|
@ -94,7 +94,7 @@ func TestWrite(t *testing.T) {
|
||||||
TrackName: "Reign",
|
TrackName: "Reign",
|
||||||
TrackNumber: 1,
|
TrackNumber: 1,
|
||||||
Duration: 271 * time.Second,
|
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"},
|
AdditionalInfo: models.AdditionalInfo{"rockbox_rating": "L"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -45,11 +45,11 @@ type Track struct {
|
||||||
DiscNumber int
|
DiscNumber int
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
ISRC string
|
ISRC string
|
||||||
RecordingMbid mbtypes.MBID
|
RecordingMBID mbtypes.MBID
|
||||||
ReleaseMbid mbtypes.MBID
|
ReleaseMBID mbtypes.MBID
|
||||||
ReleaseGroupMbid mbtypes.MBID
|
ReleaseGroupMBID mbtypes.MBID
|
||||||
ArtistMbids []mbtypes.MBID
|
ArtistMBIDs []mbtypes.MBID
|
||||||
WorkMbids []mbtypes.MBID
|
WorkMBIDs []mbtypes.MBID
|
||||||
Tags []string
|
Tags []string
|
||||||
AdditionalInfo AdditionalInfo
|
AdditionalInfo AdditionalInfo
|
||||||
}
|
}
|
||||||
|
@ -63,20 +63,20 @@ func (t *Track) FillAdditionalInfo() {
|
||||||
if t.AdditionalInfo == nil {
|
if t.AdditionalInfo == nil {
|
||||||
t.AdditionalInfo = make(AdditionalInfo, 5)
|
t.AdditionalInfo = make(AdditionalInfo, 5)
|
||||||
}
|
}
|
||||||
if t.RecordingMbid != "" {
|
if t.RecordingMBID != "" {
|
||||||
t.AdditionalInfo["recording_mbid"] = t.RecordingMbid
|
t.AdditionalInfo["recording_mbid"] = t.RecordingMBID
|
||||||
}
|
}
|
||||||
if t.ReleaseGroupMbid != "" {
|
if t.ReleaseGroupMBID != "" {
|
||||||
t.AdditionalInfo["release_group_mbid"] = t.ReleaseGroupMbid
|
t.AdditionalInfo["release_group_mbid"] = t.ReleaseGroupMBID
|
||||||
}
|
}
|
||||||
if t.ReleaseMbid != "" {
|
if t.ReleaseMBID != "" {
|
||||||
t.AdditionalInfo["release_mbid"] = t.ReleaseMbid
|
t.AdditionalInfo["release_mbid"] = t.ReleaseMBID
|
||||||
}
|
}
|
||||||
if len(t.ArtistMbids) > 0 {
|
if len(t.ArtistMBIDs) > 0 {
|
||||||
t.AdditionalInfo["artist_mbids"] = t.ArtistMbids
|
t.AdditionalInfo["artist_mbids"] = t.ArtistMBIDs
|
||||||
}
|
}
|
||||||
if len(t.WorkMbids) > 0 {
|
if len(t.WorkMBIDs) > 0 {
|
||||||
t.AdditionalInfo["work_mbids"] = t.WorkMbids
|
t.AdditionalInfo["work_mbids"] = t.WorkMBIDs
|
||||||
}
|
}
|
||||||
if t.ISRC != "" {
|
if t.ISRC != "" {
|
||||||
t.AdditionalInfo["isrc"] = t.ISRC
|
t.AdditionalInfo["isrc"] = t.ISRC
|
||||||
|
@ -111,7 +111,7 @@ type Love struct {
|
||||||
Track
|
Track
|
||||||
Created time.Time
|
Created time.Time
|
||||||
UserName string
|
UserName string
|
||||||
RecordingMbid mbtypes.MBID
|
RecordingMBID mbtypes.MBID
|
||||||
RecordingMsid mbtypes.MBID
|
RecordingMsid mbtypes.MBID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,11 +45,11 @@ func TestTrackArtistName(t *testing.T) {
|
||||||
|
|
||||||
func TestTrackFillAdditionalInfo(t *testing.T) {
|
func TestTrackFillAdditionalInfo(t *testing.T) {
|
||||||
track := models.Track{
|
track := models.Track{
|
||||||
RecordingMbid: mbtypes.MBID("c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"),
|
RecordingMBID: mbtypes.MBID("c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"),
|
||||||
ReleaseGroupMbid: mbtypes.MBID("80aca1ee-aa51-41be-9f75-024710d92ff4"),
|
ReleaseGroupMBID: mbtypes.MBID("80aca1ee-aa51-41be-9f75-024710d92ff4"),
|
||||||
ReleaseMbid: mbtypes.MBID("aa1ea1ac-7ec4-4542-a494-105afbfe547d"),
|
ReleaseMBID: mbtypes.MBID("aa1ea1ac-7ec4-4542-a494-105afbfe547d"),
|
||||||
ArtistMbids: []mbtypes.MBID{"24412926-c7bd-48e8-afad-8a285b42e131"},
|
ArtistMBIDs: []mbtypes.MBID{"24412926-c7bd-48e8-afad-8a285b42e131"},
|
||||||
WorkMbids: []mbtypes.MBID{"c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"},
|
WorkMBIDs: []mbtypes.MBID{"c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"},
|
||||||
TrackNumber: 5,
|
TrackNumber: 5,
|
||||||
DiscNumber: 1,
|
DiscNumber: 1,
|
||||||
Duration: time.Duration(413787 * time.Millisecond),
|
Duration: time.Duration(413787 * time.Millisecond),
|
||||||
|
@ -59,11 +59,11 @@ func TestTrackFillAdditionalInfo(t *testing.T) {
|
||||||
track.FillAdditionalInfo()
|
track.FillAdditionalInfo()
|
||||||
i := track.AdditionalInfo
|
i := track.AdditionalInfo
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
assert.Equal(track.RecordingMbid, i["recording_mbid"])
|
assert.Equal(track.RecordingMBID, i["recording_mbid"])
|
||||||
assert.Equal(track.ReleaseGroupMbid, i["release_group_mbid"])
|
assert.Equal(track.ReleaseGroupMBID, i["release_group_mbid"])
|
||||||
assert.Equal(track.ReleaseMbid, i["release_mbid"])
|
assert.Equal(track.ReleaseMBID, i["release_mbid"])
|
||||||
assert.Equal(track.ArtistMbids, i["artist_mbids"])
|
assert.Equal(track.ArtistMBIDs, i["artist_mbids"])
|
||||||
assert.Equal(track.WorkMbids, i["work_mbids"])
|
assert.Equal(track.WorkMBIDs, i["work_mbids"])
|
||||||
assert.Equal(track.TrackNumber, i["tracknumber"])
|
assert.Equal(track.TrackNumber, i["tracknumber"])
|
||||||
assert.Equal(track.DiscNumber, i["discnumber"])
|
assert.Equal(track.DiscNumber, i["discnumber"])
|
||||||
assert.Equal(track.Duration.Milliseconds(), i["duration_ms"])
|
assert.Equal(track.Duration.Milliseconds(), i["duration_ms"])
|
||||||
|
|
|
@ -63,7 +63,7 @@ func NormalizeTitle(s string) string {
|
||||||
// Compare two tracks for similarity.
|
// Compare two tracks for similarity.
|
||||||
func CompareTracks(t1 models.Track, t2 models.Track) float64 {
|
func CompareTracks(t1 models.Track, t2 models.Track) float64 {
|
||||||
// Identical recording MBID always compares 100%
|
// Identical recording MBID always compares 100%
|
||||||
if t1.RecordingMbid == t2.RecordingMbid && t1.RecordingMbid != "" {
|
if t1.RecordingMBID == t2.RecordingMBID && t1.RecordingMBID != "" {
|
||||||
return 1.0
|
return 1.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,13 +75,13 @@ func TestCompareTracksSameMBID(t *testing.T) {
|
||||||
t1 := models.Track{
|
t1 := models.Track{
|
||||||
ArtistNames: []string{"Paradise Lost"},
|
ArtistNames: []string{"Paradise Lost"},
|
||||||
TrackName: "Forever After",
|
TrackName: "Forever After",
|
||||||
RecordingMbid: mbtypes.MBID("2886d15c-09b0-43c6-af56-932f70dde164"),
|
RecordingMBID: mbtypes.MBID("2886d15c-09b0-43c6-af56-932f70dde164"),
|
||||||
}
|
}
|
||||||
t2 := models.Track{
|
t2 := models.Track{
|
||||||
ArtistNames: []string{"Paradise Lost"},
|
ArtistNames: []string{"Paradise Lost"},
|
||||||
TrackName: "Forever Failure (radio edit)",
|
TrackName: "Forever Failure (radio edit)",
|
||||||
ReleaseName: "Draconian Times",
|
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))
|
assert.Equal(t, 1.0, similarity.CompareTracks(t1, t2))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue