mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-11 07:59:29 +02:00
Use mbtypes.ISRC type
This commit is contained in:
parent
ad1644672c
commit
13eb8342ab
7 changed files with 16 additions and 11 deletions
|
@ -68,7 +68,7 @@ func TestListenBrainzListenAsListen(t *testing.T) {
|
||||||
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, mbtypes.ISRC("DES561620801"), listen.ISRC)
|
||||||
assert.Equal(t, lbListen.TrackMetadata.AdditionalInfo["foo"], listen.AdditionalInfo["foo"])
|
assert.Equal(t, lbListen.TrackMetadata.AdditionalInfo["foo"], listen.AdditionalInfo["foo"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.uploadedlobster.com/mbtypes"
|
||||||
"golang.org/x/exp/constraints"
|
"golang.org/x/exp/constraints"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -158,8 +159,8 @@ func (t Track) DiscNumber() int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Track) ISRC() string {
|
func (t Track) ISRC() mbtypes.ISRC {
|
||||||
return tryGetValueOrEmpty[string](t.AdditionalInfo, "isrc")
|
return mbtypes.ISRC(tryGetValueOrEmpty[string](t.AdditionalInfo, "isrc"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Track) RecordingMBID() string {
|
func (t Track) RecordingMBID() string {
|
||||||
|
|
|
@ -28,6 +28,7 @@ import (
|
||||||
|
|
||||||
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -131,10 +132,10 @@ func TestTrackTrackNumberString(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTrackIsrc(t *testing.T) {
|
func TestTrackIsrc(t *testing.T) {
|
||||||
expected := "TCAEJ1934417"
|
expected := mbtypes.ISRC("TCAEJ1934417")
|
||||||
track := listenbrainz.Track{
|
track := listenbrainz.Track{
|
||||||
AdditionalInfo: map[string]any{
|
AdditionalInfo: map[string]any{
|
||||||
"isrc": expected,
|
"isrc": string(expected),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.Equal(t, expected, track.ISRC())
|
assert.Equal(t, expected, track.ISRC())
|
||||||
|
|
|
@ -22,6 +22,8 @@ THE SOFTWARE.
|
||||||
|
|
||||||
package spotify
|
package spotify
|
||||||
|
|
||||||
|
import "go.uploadedlobster.com/mbtypes"
|
||||||
|
|
||||||
type TracksResult struct {
|
type TracksResult struct {
|
||||||
Href string `json:"href"`
|
Href string `json:"href"`
|
||||||
Limit int `json:"limit"`
|
Limit int `json:"limit"`
|
||||||
|
@ -98,9 +100,9 @@ type Artist struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExternalIds struct {
|
type ExternalIds struct {
|
||||||
ISRC string `json:"isrc"`
|
ISRC mbtypes.ISRC `json:"isrc"`
|
||||||
EAN string `json:"ean"`
|
EAN string `json:"ean"`
|
||||||
UPC string `json:"upc"`
|
UPC string `json:"upc"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExternalUrls struct {
|
type ExternalUrls struct {
|
||||||
|
|
|
@ -26,6 +26,7 @@ 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/spotify"
|
"go.uploadedlobster.com/scotty/internal/backends/spotify"
|
||||||
"go.uploadedlobster.com/scotty/internal/config"
|
"go.uploadedlobster.com/scotty/internal/config"
|
||||||
)
|
)
|
||||||
|
@ -59,7 +60,7 @@ func TestSpotifyListenAsListen(t *testing.T) {
|
||||||
assert.Equal(t, []string{"Dool"}, listen.ArtistNames)
|
assert.Equal(t, []string{"Dool"}, 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, "DES561620801", listen.ISRC)
|
assert.Equal(t, mbtypes.ISRC("DES561620801"), listen.ISRC)
|
||||||
info := listen.AdditionalInfo
|
info := listen.AdditionalInfo
|
||||||
assert.Equal(t, "spotify.com", info["music_service"])
|
assert.Equal(t, "spotify.com", info["music_service"])
|
||||||
assert.Equal(t, "https://open.spotify.com/track/2JKUgGuXK3dEvyuIJ4Yj2V", info["origin_url"])
|
assert.Equal(t, "https://open.spotify.com/track/2JKUgGuXK3dEvyuIJ4Yj2V", info["origin_url"])
|
||||||
|
|
|
@ -44,7 +44,7 @@ type Track struct {
|
||||||
TrackNumber int
|
TrackNumber int
|
||||||
DiscNumber int
|
DiscNumber int
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
ISRC string
|
ISRC mbtypes.ISRC
|
||||||
RecordingMBID mbtypes.MBID
|
RecordingMBID mbtypes.MBID
|
||||||
ReleaseMBID mbtypes.MBID
|
ReleaseMBID mbtypes.MBID
|
||||||
ReleaseGroupMBID mbtypes.MBID
|
ReleaseGroupMBID mbtypes.MBID
|
||||||
|
|
|
@ -53,7 +53,7 @@ func TestTrackFillAdditionalInfo(t *testing.T) {
|
||||||
TrackNumber: 5,
|
TrackNumber: 5,
|
||||||
DiscNumber: 1,
|
DiscNumber: 1,
|
||||||
Duration: time.Duration(413787 * time.Millisecond),
|
Duration: time.Duration(413787 * time.Millisecond),
|
||||||
ISRC: "DES561620801",
|
ISRC: mbtypes.ISRC("DES561620801"),
|
||||||
Tags: []string{"rock", "psychedelic rock"},
|
Tags: []string{"rock", "psychedelic rock"},
|
||||||
}
|
}
|
||||||
track.FillAdditionalInfo()
|
track.FillAdditionalInfo()
|
||||||
|
|
Loading…
Add table
Reference in a new issue