Uppercase acronyms (ISRC / JSPF)

This commit is contained in:
Philipp Wolfer 2023-11-23 08:26:45 +01:00
parent 409acccebe
commit 36cc41d05d
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
14 changed files with 28 additions and 28 deletions

View file

@ -77,7 +77,7 @@ func GetBackends() []BackendInfo {
var knownBackends = map[string]func() models.Backend{ var knownBackends = map[string]func() models.Backend{
"dump": func() models.Backend { return &dump.DumpBackend{} }, "dump": func() models.Backend { return &dump.DumpBackend{} },
"funkwhale": func() models.Backend { return &funkwhale.FunkwhaleApiBackend{} }, "funkwhale": func() models.Backend { return &funkwhale.FunkwhaleApiBackend{} },
"jspf": func() models.Backend { return &jspf.JspfBackend{} }, "jspf": func() models.Backend { return &jspf.JSPFBackend{} },
"listenbrainz": func() models.Backend { return &listenbrainz.ListenBrainzApiBackend{} }, "listenbrainz": func() models.Backend { return &listenbrainz.ListenBrainzApiBackend{} },
"maloja": func() models.Backend { return &maloja.MalojaApiBackend{} }, "maloja": func() models.Backend { return &maloja.MalojaApiBackend{} },
"scrobbler-log": func() models.Backend { return &scrobblerlog.ScrobblerLogBackend{} }, "scrobbler-log": func() models.Backend { return &scrobblerlog.ScrobblerLogBackend{} },

View file

@ -81,10 +81,10 @@ func TestImplementsInterfaces(t *testing.T) {
expectInterface[models.LovesExport](t, &funkwhale.FunkwhaleApiBackend{}) expectInterface[models.LovesExport](t, &funkwhale.FunkwhaleApiBackend{})
// expectInterface[models.LovesImport](t, &funkwhale.FunkwhaleApiBackend{}) // expectInterface[models.LovesImport](t, &funkwhale.FunkwhaleApiBackend{})
// expectInterface[models.ListensExport](t, &jspf.JspfBackend{}) // expectInterface[models.ListensExport](t, &jspf.JSPFBackend{})
// expectInterface[models.ListensImport](t, &jspf.JspfBackend{}) // expectInterface[models.ListensImport](t, &jspf.JSPFBackend{})
// expectInterface[models.LovesExport](t, &jspf.JspfBackend{}) // expectInterface[models.LovesExport](t, &jspf.JSPFBackend{})
expectInterface[models.LovesImport](t, &jspf.JspfBackend{}) expectInterface[models.LovesImport](t, &jspf.JSPFBackend{})
expectInterface[models.ListensExport](t, &listenbrainz.ListenBrainzApiBackend{}) expectInterface[models.ListensExport](t, &listenbrainz.ListenBrainzApiBackend{})
// expectInterface[models.ListensImport](t, &listenbrainz.ListenBrainzApiBackend{}) // expectInterface[models.ListensImport](t, &listenbrainz.ListenBrainzApiBackend{})

View file

@ -26,7 +26,7 @@ import (
"go.uploadedlobster.com/scotty/models" "go.uploadedlobster.com/scotty/models"
) )
type JspfBackend struct { type JSPFBackend struct {
filePath string filePath string
title string title string
creator string creator string
@ -34,9 +34,9 @@ type JspfBackend struct {
tracks []Track tracks []Track
} }
func (b *JspfBackend) Name() string { return "jspf" } func (b *JSPFBackend) Name() string { return "jspf" }
func (b *JspfBackend) FromConfig(config *viper.Viper) models.Backend { func (b *JSPFBackend) FromConfig(config *viper.Viper) models.Backend {
b.filePath = config.GetString("file-path") b.filePath = config.GetString("file-path")
b.title = config.GetString("title") b.title = config.GetString("title")
b.creator = config.GetString("username") b.creator = config.GetString("username")
@ -45,13 +45,13 @@ func (b *JspfBackend) FromConfig(config *viper.Viper) models.Backend {
return b return b
} }
func (b *JspfBackend) StartImport() error { return nil } func (b *JSPFBackend) StartImport() error { return nil }
func (b *JspfBackend) FinishImport() error { func (b *JSPFBackend) FinishImport() error {
err := b.writeJspf(b.tracks) err := b.writeJSPF(b.tracks)
return err return err
} }
func (b *JspfBackend) ImportListens(export models.ListensResult, importResult models.ImportResult, progress chan models.Progress) (models.ImportResult, error) { func (b *JSPFBackend) ImportListens(export models.ListensResult, importResult models.ImportResult, progress chan models.Progress) (models.ImportResult, error) {
for _, listen := range export.Listens { for _, listen := range export.Listens {
track := listenAsTrack(listen) track := listenAsTrack(listen)
b.tracks = append(b.tracks, track) b.tracks = append(b.tracks, track)
@ -63,7 +63,7 @@ func (b *JspfBackend) ImportListens(export models.ListensResult, importResult mo
return importResult, nil return importResult, nil
} }
func (b *JspfBackend) ImportLoves(export models.LovesResult, importResult models.ImportResult, progress chan models.Progress) (models.ImportResult, error) { func (b *JSPFBackend) ImportLoves(export models.LovesResult, importResult models.ImportResult, progress chan models.Progress) (models.ImportResult, error) {
for _, love := range export.Loves { for _, love := range export.Loves {
track := loveAsTrack(love) track := loveAsTrack(love)
b.tracks = append(b.tracks, track) b.tracks = append(b.tracks, track)
@ -132,8 +132,8 @@ func makeMusicBrainzExtension(t models.Track) MusicBrainzTrackExtension {
return extension return extension
} }
func (b JspfBackend) writeJspf(tracks []Track) error { func (b JSPFBackend) writeJSPF(tracks []Track) error {
playlist := Jspf{ playlist := JSPF{
Playlist: Playlist{ Playlist: Playlist{
Title: b.title, Title: b.title,
Creator: b.creator, Creator: b.creator,

View file

@ -20,7 +20,7 @@ package jspf
import "time" import "time"
// See https://xspf.org/jspf // See https://xspf.org/jspf
type Jspf struct { type JSPF struct {
Playlist Playlist `json:"playlist"` Playlist Playlist `json:"playlist"`
} }

View file

@ -88,8 +88,8 @@ func TestUnmarshalListenBrainzPlaylist(t *testing.T) {
assert.Equal("outsidecontext", extension["added_by"]) assert.Equal("outsidecontext", extension["added_by"])
} }
func readSampleJson(path string) (jspf.Jspf, error) { func readSampleJson(path string) (jspf.JSPF, error) {
var result jspf.Jspf var result jspf.JSPF
jsonFile, err := os.Open(path) jsonFile, err := os.Open(path)
if err != nil { if err != nil {
return result, err return result, err

View file

@ -236,7 +236,7 @@ func (t Track) AsTrack() models.Track {
RecordingMbid: models.MBID(t.RecordingMbid()), RecordingMbid: models.MBID(t.RecordingMbid()),
ReleaseMbid: models.MBID(t.ReleaseMbid()), ReleaseMbid: models.MBID(t.ReleaseMbid()),
ReleaseGroupMbid: models.MBID(t.ReleaseGroupMbid()), ReleaseGroupMbid: models.MBID(t.ReleaseGroupMbid()),
Isrc: t.Isrc(), ISRC: t.ISRC(),
AdditionalInfo: t.AdditionalInfo, AdditionalInfo: t.AdditionalInfo,
} }

View file

@ -66,7 +66,7 @@ func TestListenBrainzListenAsListen(t *testing.T) {
assert.Equal(t, models.MBID("c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"), listen.RecordingMbid) assert.Equal(t, models.MBID("c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12"), listen.RecordingMbid)
assert.Equal(t, models.MBID("d7f22677-9803-4d21-ba42-081b633a6f68"), listen.ReleaseMbid) assert.Equal(t, models.MBID("d7f22677-9803-4d21-ba42-081b633a6f68"), listen.ReleaseMbid)
assert.Equal(t, models.MBID("80aca1ee-aa51-41be-9f75-024710d92ff4"), listen.ReleaseGroupMbid) assert.Equal(t, models.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"])
} }

View file

@ -144,7 +144,7 @@ func (t Track) DiscNumber() int {
return 0 return 0
} }
func (t Track) Isrc() string { func (t Track) ISRC() string {
return tryGetValueOrEmpty[string](t.AdditionalInfo, "isrc") return tryGetValueOrEmpty[string](t.AdditionalInfo, "isrc")
} }

View file

@ -137,7 +137,7 @@ func TestTrackIsrc(t *testing.T) {
"isrc": expected, "isrc": expected,
}, },
} }
assert.Equal(t, expected, track.Isrc()) assert.Equal(t, expected, track.ISRC())
} }
func TestTrackRecordingMbid(t *testing.T) { func TestTrackRecordingMbid(t *testing.T) {

View file

@ -224,7 +224,7 @@ func (t Track) AsTrack() models.Track {
Duration: time.Duration(t.DurationMs * int(time.Millisecond)), Duration: time.Duration(t.DurationMs * int(time.Millisecond)),
TrackNumber: t.TrackNumber, TrackNumber: t.TrackNumber,
DiscNumber: t.DiscNumber, DiscNumber: t.DiscNumber,
Isrc: t.ExternalIds.ISRC, ISRC: t.ExternalIds.ISRC,
AdditionalInfo: map[string]any{}, AdditionalInfo: map[string]any{},
} }

View file

@ -43,7 +43,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, "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"])

View file

@ -68,7 +68,7 @@ func (b *SubsonicApiBackend) ExportLoves(oldestTimestamp time.Time, results chan
func (b *SubsonicApiBackend) filterSongs(songs []*subsonic.Child, oldestTimestamp time.Time) models.LovesList { func (b *SubsonicApiBackend) filterSongs(songs []*subsonic.Child, oldestTimestamp time.Time) models.LovesList {
loves := make(models.LovesList, len(songs)) loves := make(models.LovesList, len(songs))
for i, song := range songs { for i, song := range songs {
love := SongToLove(*song, b.client.User) love := SongAsLove(*song, b.client.User)
if love.Created.Unix() > oldestTimestamp.Unix() { if love.Created.Unix() > oldestTimestamp.Unix() {
loves[i] = love loves[i] = love
} }
@ -78,7 +78,7 @@ func (b *SubsonicApiBackend) filterSongs(songs []*subsonic.Child, oldestTimestam
return loves return loves
} }
func SongToLove(song subsonic.Child, username string) models.Love { func SongAsLove(song subsonic.Child, username string) models.Love {
love := models.Love{ love := models.Love{
UserName: username, UserName: username,
Created: song.Starred, Created: song.Starred,

View file

@ -46,7 +46,7 @@ func TestSongToLove(t *testing.T) {
DiscNumber: 1, DiscNumber: 1,
Track: 5, Track: 5,
} }
love := subsonic.SongToLove(song, user) love := subsonic.SongAsLove(song, user)
assert := assert.New(t) assert := assert.New(t)
assert.Equal(time.Unix(1699574369, 0).Unix(), love.Created.Unix()) assert.Equal(time.Unix(1699574369, 0).Unix(), love.Created.Unix())
assert.Equal(user, love.UserName) assert.Equal(user, love.UserName)

View file

@ -37,7 +37,7 @@ type Track struct {
TrackNumber int TrackNumber int
DiscNumber int DiscNumber int
Duration time.Duration Duration time.Duration
Isrc string ISRC string
RecordingMbid MBID RecordingMbid MBID
ReleaseMbid MBID ReleaseMbid MBID
ReleaseGroupMbid MBID ReleaseGroupMbid MBID