mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-10 23:49:28 +02:00
More conversion to mbtypes.MBID
This commit is contained in:
parent
13eb8342ab
commit
0d9bc74bc0
8 changed files with 82 additions and 81 deletions
|
@ -189,16 +189,15 @@ func (f FavoriteTrack) AsLove() models.Love {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Track) AsTrack() models.Track {
|
func (t Track) AsTrack() models.Track {
|
||||||
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: t.RecordingMBID,
|
||||||
ReleaseMBID: mbtypes.MBID(t.Album.ReleaseMBID),
|
ReleaseMBID: t.Album.ReleaseMBID,
|
||||||
ArtistMBIDs: []mbtypes.MBID{mbtypes.MBID(t.Artist.ArtistMBID)},
|
ArtistMBIDs: []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,
|
||||||
|
|
|
@ -23,7 +23,6 @@ import (
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"go.uploadedlobster.com/mbtypes"
|
|
||||||
"go.uploadedlobster.com/scotty/internal/backends/funkwhale"
|
"go.uploadedlobster.com/scotty/internal/backends/funkwhale"
|
||||||
"go.uploadedlobster.com/scotty/internal/config"
|
"go.uploadedlobster.com/scotty/internal/config"
|
||||||
)
|
)
|
||||||
|
@ -75,9 +74,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(fwListen.Track.RecordingMBID, listen.RecordingMBID)
|
||||||
assert.Equal(mbtypes.MBID(fwListen.Track.Album.ReleaseMBID), listen.ReleaseMBID)
|
assert.Equal(fwListen.Track.Album.ReleaseMBID, listen.ReleaseMBID)
|
||||||
assert.Equal(mbtypes.MBID(fwListen.Track.Artist.ArtistMBID), listen.ArtistMBIDs[0])
|
assert.Equal(fwListen.Track.Artist.ArtistMBID, listen.ArtistMBIDs[0])
|
||||||
assert.Equal(funkwhale.FunkwhaleClientName, listen.AdditionalInfo["media_player"])
|
assert.Equal(funkwhale.FunkwhaleClientName, listen.AdditionalInfo["media_player"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,10 +118,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(favorite.Track.RecordingMBID, love.RecordingMBID)
|
||||||
assert.Equal(mbtypes.MBID(favorite.Track.RecordingMBID), love.Track.RecordingMBID)
|
assert.Equal(favorite.Track.RecordingMBID, love.Track.RecordingMBID)
|
||||||
assert.Equal(mbtypes.MBID(favorite.Track.Album.ReleaseMBID), love.ReleaseMBID)
|
assert.Equal(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(favorite.Track.Artist.ArtistMBID, love.ArtistMBIDs[0])
|
||||||
assert.Equal(funkwhale.FunkwhaleClientName, love.AdditionalInfo["media_player"])
|
assert.Equal(funkwhale.FunkwhaleClientName, love.AdditionalInfo["media_player"])
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package funkwhale
|
package funkwhale
|
||||||
|
|
||||||
|
import "go.uploadedlobster.com/mbtypes"
|
||||||
|
|
||||||
type ListeningsResult struct {
|
type ListeningsResult struct {
|
||||||
Count int `json:"count"`
|
Count int `json:"count"`
|
||||||
Previous string `json:"previous"`
|
Previous string `json:"previous"`
|
||||||
|
@ -50,30 +52,30 @@ type FavoriteTrack struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Track struct {
|
type Track struct {
|
||||||
Id int `json:"int"`
|
Id int `json:"int"`
|
||||||
Artist Artist `json:"artist"`
|
Artist Artist `json:"artist"`
|
||||||
Album Album `json:"album"`
|
Album Album `json:"album"`
|
||||||
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 mbtypes.MBID `json:"mbid"`
|
||||||
Tags []string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
Uploads []Upload `json:"uploads"`
|
Uploads []Upload `json:"uploads"`
|
||||||
}
|
}
|
||||||
|
|
||||||
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 mbtypes.MBID `json:"mbid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Album struct {
|
type Album struct {
|
||||||
Id int `json:"int"`
|
Id int `json:"int"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
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 mbtypes.MBID `json:"mbid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"github.com/jarcoal/httpmock"
|
"github.com/jarcoal/httpmock"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"go.uploadedlobster.com/mbtypes"
|
||||||
"go.uploadedlobster.com/scotty/internal/backends/listenbrainz"
|
"go.uploadedlobster.com/scotty/internal/backends/listenbrainz"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -114,7 +115,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(mbtypes.MBID("c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"), result.Feedback[0].RecordingMBID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSendFeedback(t *testing.T) {
|
func TestSendFeedback(t *testing.T) {
|
||||||
|
@ -154,7 +155,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(mbtypes.MBID("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[mbtypes.MBID]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *ListenBrainzApiBackend) Name() string { return "listenbrainz" }
|
func (b *ListenBrainzApiBackend) Name() string { return "listenbrainz" }
|
||||||
|
@ -239,14 +239,14 @@ 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[mbtypes.MBID]bool, len(existingLoves.Items))
|
||||||
for _, love := range existingLoves.Items {
|
for _, love := range existingLoves.Items {
|
||||||
b.existingMBIDs[string(love.RecordingMBID)] = true
|
b.existingMBIDs[love.RecordingMBID] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, love := range export.Items {
|
for _, love := range export.Items {
|
||||||
recordingMBID := string(love.RecordingMBID)
|
recordingMBID := love.RecordingMBID
|
||||||
|
|
||||||
if recordingMBID == "" {
|
if recordingMBID == "" {
|
||||||
lookup, err := b.client.Lookup(love.TrackName, love.ArtistName())
|
lookup, err := b.client.Lookup(love.TrackName, love.ArtistName())
|
||||||
|
@ -324,7 +324,7 @@ func (lbListen Listen) AsListen() models.Listen {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Feedback) AsLove() models.Love {
|
func (f Feedback) AsLove() models.Love {
|
||||||
recordingMBID := mbtypes.MBID(f.RecordingMBID)
|
recordingMBID := f.RecordingMBID
|
||||||
track := f.TrackMetadata
|
track := f.TrackMetadata
|
||||||
if track == nil {
|
if track == nil {
|
||||||
track = &Track{}
|
track = &Track{}
|
||||||
|
@ -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: t.RecordingMBID(),
|
||||||
ReleaseMBID: mbtypes.MBID(t.ReleaseMBID()),
|
ReleaseMBID: t.ReleaseMBID(),
|
||||||
ReleaseGroupMBID: mbtypes.MBID(t.ReleaseGroupMBID()),
|
ReleaseGroupMBID: 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, artistMBID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,9 +73,9 @@ func TestListenBrainzListenAsListen(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListenBrainzFeedbackAsLove(t *testing.T) {
|
func TestListenBrainzFeedbackAsLove(t *testing.T) {
|
||||||
recordingMBID := "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"
|
recordingMBID := mbtypes.MBID("c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12")
|
||||||
releaseMBID := "d7f22677-9803-4d21-ba42-081b633a6f68"
|
releaseMBID := mbtypes.MBID("d7f22677-9803-4d21-ba42-081b633a6f68")
|
||||||
artistMBID := "d7f22677-9803-4d21-ba42-081b633a6f68"
|
artistMBID := mbtypes.MBID("d7f22677-9803-4d21-ba42-081b633a6f68")
|
||||||
feedback := listenbrainz.Feedback{
|
feedback := listenbrainz.Feedback{
|
||||||
Created: 1699859066,
|
Created: 1699859066,
|
||||||
RecordingMBID: recordingMBID,
|
RecordingMBID: recordingMBID,
|
||||||
|
@ -88,7 +88,7 @@ func TestListenBrainzFeedbackAsLove(t *testing.T) {
|
||||||
MBIDMapping: &listenbrainz.MBIDMapping{
|
MBIDMapping: &listenbrainz.MBIDMapping{
|
||||||
RecordingMBID: recordingMBID,
|
RecordingMBID: recordingMBID,
|
||||||
ReleaseMBID: releaseMBID,
|
ReleaseMBID: releaseMBID,
|
||||||
ArtistMBIDs: []string{artistMBID},
|
ArtistMBIDs: []mbtypes.MBID{artistMBID},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -99,15 +99,15 @@ 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(recordingMBID, love.RecordingMBID)
|
||||||
assert.Equal(mbtypes.MBID(recordingMBID), love.Track.RecordingMBID)
|
assert.Equal(recordingMBID, love.Track.RecordingMBID)
|
||||||
assert.Equal(mbtypes.MBID(releaseMBID), love.Track.ReleaseMBID)
|
assert.Equal(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(artistMBID, love.Track.ArtistMBIDs[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListenBrainzPartialFeedbackAsLove(t *testing.T) {
|
func TestListenBrainzPartialFeedbackAsLove(t *testing.T) {
|
||||||
recordingMBID := "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"
|
recordingMBID := mbtypes.MBID("c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12")
|
||||||
feedback := listenbrainz.Feedback{
|
feedback := listenbrainz.Feedback{
|
||||||
Created: 1699859066,
|
Created: 1699859066,
|
||||||
RecordingMBID: recordingMBID,
|
RecordingMBID: recordingMBID,
|
||||||
|
@ -116,7 +116,7 @@ func TestListenBrainzPartialFeedbackAsLove(t *testing.T) {
|
||||||
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(recordingMBID, love.RecordingMBID)
|
||||||
assert.Equal(mbtypes.MBID(recordingMBID), love.Track.RecordingMBID)
|
assert.Equal(recordingMBID, love.Track.RecordingMBID)
|
||||||
assert.Empty(love.Track.TrackName)
|
assert.Empty(love.Track.TrackName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,11 +71,11 @@ type Track struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 mbtypes.MBID `json:"recording_mbid,omitempty"`
|
||||||
ReleaseMBID string `json:"release_mbid,omitempty"`
|
ReleaseMBID mbtypes.MBID `json:"release_mbid,omitempty"`
|
||||||
ArtistMBIDs []string `json:"artist_mbids,omitempty"`
|
ArtistMBIDs []mbtypes.MBID `json:"artist_mbids,omitempty"`
|
||||||
Artists []Artist `json:"artists,omitempty"`
|
Artists []Artist `json:"artists,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Artist struct {
|
type Artist struct {
|
||||||
|
@ -92,21 +92,21 @@ 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 mbtypes.MBID `json:"recording_mbid,omitempty"`
|
||||||
RecordingMsid string `json:"recording_msid,omitempty"`
|
RecordingMsid mbtypes.MBID `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"`
|
||||||
UserName string `json:"user_id,omitempty"`
|
UserName string `json:"user_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LookupResult struct {
|
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 mbtypes.MBID `json:"recording_mbid"`
|
||||||
ReleaseMBID string `json:"release_mbid"`
|
ReleaseMBID mbtypes.MBID `json:"release_mbid"`
|
||||||
ArtistMBIDs []string `json:"artist_mbids"`
|
ArtistMBIDs []mbtypes.MBID `json:"artist_mbids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatusResult struct {
|
type StatusResult struct {
|
||||||
|
@ -163,8 +163,8 @@ func (t Track) ISRC() mbtypes.ISRC {
|
||||||
return mbtypes.ISRC(tryGetValueOrEmpty[string](t.AdditionalInfo, "isrc"))
|
return mbtypes.ISRC(tryGetValueOrEmpty[string](t.AdditionalInfo, "isrc"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Track) RecordingMBID() string {
|
func (t Track) RecordingMBID() mbtypes.MBID {
|
||||||
mbid := tryGetValueOrEmpty[string](t.AdditionalInfo, "recording_mbid")
|
mbid := mbtypes.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 {
|
||||||
|
@ -172,8 +172,8 @@ func (t Track) RecordingMBID() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Track) ReleaseMBID() string {
|
func (t Track) ReleaseMBID() mbtypes.MBID {
|
||||||
mbid := tryGetValueOrEmpty[string](t.AdditionalInfo, "release_mbid")
|
mbid := mbtypes.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 {
|
||||||
|
@ -181,8 +181,8 @@ func (t Track) ReleaseMBID() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Track) ReleaseGroupMBID() string {
|
func (t Track) ReleaseGroupMBID() mbtypes.MBID {
|
||||||
return tryGetValueOrEmpty[string](t.AdditionalInfo, "release_group_mbid")
|
return mbtypes.MBID(tryGetValueOrEmpty[string](t.AdditionalInfo, "release_group_mbid"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryGetValueOrEmpty[T any](dict map[string]any, key string) T {
|
func tryGetValueOrEmpty[T any](dict map[string]any, key string) T {
|
||||||
|
|
|
@ -142,30 +142,30 @@ func TestTrackIsrc(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTrackRecordingMBID(t *testing.T) {
|
func TestTrackRecordingMBID(t *testing.T) {
|
||||||
expected := "e02cc1c3-93fd-4e24-8b77-325060de920b"
|
expected := mbtypes.MBID("e02cc1c3-93fd-4e24-8b77-325060de920b")
|
||||||
track := listenbrainz.Track{
|
track := listenbrainz.Track{
|
||||||
AdditionalInfo: map[string]any{
|
AdditionalInfo: map[string]any{
|
||||||
"recording_mbid": expected,
|
"recording_mbid": string(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 := mbtypes.MBID("e02cc1c3-93fd-4e24-8b77-325060de920b")
|
||||||
track := listenbrainz.Track{
|
track := listenbrainz.Track{
|
||||||
AdditionalInfo: map[string]any{
|
AdditionalInfo: map[string]any{
|
||||||
"release_mbid": expected,
|
"release_mbid": string(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 := mbtypes.MBID("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": string(expected),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.Equal(t, expected, track.ReleaseGroupMBID())
|
assert.Equal(t, expected, track.ReleaseGroupMBID())
|
||||||
|
|
Loading…
Add table
Reference in a new issue