mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-16 10:09:28 +02:00
Uppercase acronyms (ISRC / JSPF)
This commit is contained in:
parent
409acccebe
commit
36cc41d05d
14 changed files with 28 additions and 28 deletions
|
@ -77,7 +77,7 @@ func GetBackends() []BackendInfo {
|
|||
var knownBackends = map[string]func() models.Backend{
|
||||
"dump": func() models.Backend { return &dump.DumpBackend{} },
|
||||
"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{} },
|
||||
"maloja": func() models.Backend { return &maloja.MalojaApiBackend{} },
|
||||
"scrobbler-log": func() models.Backend { return &scrobblerlog.ScrobblerLogBackend{} },
|
||||
|
|
|
@ -81,10 +81,10 @@ func TestImplementsInterfaces(t *testing.T) {
|
|||
expectInterface[models.LovesExport](t, &funkwhale.FunkwhaleApiBackend{})
|
||||
// expectInterface[models.LovesImport](t, &funkwhale.FunkwhaleApiBackend{})
|
||||
|
||||
// expectInterface[models.ListensExport](t, &jspf.JspfBackend{})
|
||||
// expectInterface[models.ListensImport](t, &jspf.JspfBackend{})
|
||||
// expectInterface[models.LovesExport](t, &jspf.JspfBackend{})
|
||||
expectInterface[models.LovesImport](t, &jspf.JspfBackend{})
|
||||
// expectInterface[models.ListensExport](t, &jspf.JSPFBackend{})
|
||||
// expectInterface[models.ListensImport](t, &jspf.JSPFBackend{})
|
||||
// expectInterface[models.LovesExport](t, &jspf.JSPFBackend{})
|
||||
expectInterface[models.LovesImport](t, &jspf.JSPFBackend{})
|
||||
|
||||
expectInterface[models.ListensExport](t, &listenbrainz.ListenBrainzApiBackend{})
|
||||
// expectInterface[models.ListensImport](t, &listenbrainz.ListenBrainzApiBackend{})
|
||||
|
|
|
@ -26,7 +26,7 @@ import (
|
|||
"go.uploadedlobster.com/scotty/models"
|
||||
)
|
||||
|
||||
type JspfBackend struct {
|
||||
type JSPFBackend struct {
|
||||
filePath string
|
||||
title string
|
||||
creator string
|
||||
|
@ -34,9 +34,9 @@ type JspfBackend struct {
|
|||
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.title = config.GetString("title")
|
||||
b.creator = config.GetString("username")
|
||||
|
@ -45,13 +45,13 @@ func (b *JspfBackend) FromConfig(config *viper.Viper) models.Backend {
|
|||
return b
|
||||
}
|
||||
|
||||
func (b *JspfBackend) StartImport() error { return nil }
|
||||
func (b *JspfBackend) FinishImport() error {
|
||||
err := b.writeJspf(b.tracks)
|
||||
func (b *JSPFBackend) StartImport() error { return nil }
|
||||
func (b *JSPFBackend) FinishImport() error {
|
||||
err := b.writeJSPF(b.tracks)
|
||||
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 {
|
||||
track := listenAsTrack(listen)
|
||||
b.tracks = append(b.tracks, track)
|
||||
|
@ -63,7 +63,7 @@ func (b *JspfBackend) ImportListens(export models.ListensResult, importResult mo
|
|||
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 {
|
||||
track := loveAsTrack(love)
|
||||
b.tracks = append(b.tracks, track)
|
||||
|
@ -132,8 +132,8 @@ func makeMusicBrainzExtension(t models.Track) MusicBrainzTrackExtension {
|
|||
return extension
|
||||
}
|
||||
|
||||
func (b JspfBackend) writeJspf(tracks []Track) error {
|
||||
playlist := Jspf{
|
||||
func (b JSPFBackend) writeJSPF(tracks []Track) error {
|
||||
playlist := JSPF{
|
||||
Playlist: Playlist{
|
||||
Title: b.title,
|
||||
Creator: b.creator,
|
||||
|
|
|
@ -20,7 +20,7 @@ package jspf
|
|||
import "time"
|
||||
|
||||
// See https://xspf.org/jspf
|
||||
type Jspf struct {
|
||||
type JSPF struct {
|
||||
Playlist Playlist `json:"playlist"`
|
||||
}
|
||||
|
||||
|
|
|
@ -88,8 +88,8 @@ func TestUnmarshalListenBrainzPlaylist(t *testing.T) {
|
|||
assert.Equal("outsidecontext", extension["added_by"])
|
||||
}
|
||||
|
||||
func readSampleJson(path string) (jspf.Jspf, error) {
|
||||
var result jspf.Jspf
|
||||
func readSampleJson(path string) (jspf.JSPF, error) {
|
||||
var result jspf.JSPF
|
||||
jsonFile, err := os.Open(path)
|
||||
if err != nil {
|
||||
return result, err
|
||||
|
|
|
@ -236,7 +236,7 @@ func (t Track) AsTrack() models.Track {
|
|||
RecordingMbid: models.MBID(t.RecordingMbid()),
|
||||
ReleaseMbid: models.MBID(t.ReleaseMbid()),
|
||||
ReleaseGroupMbid: models.MBID(t.ReleaseGroupMbid()),
|
||||
Isrc: t.Isrc(),
|
||||
ISRC: t.ISRC(),
|
||||
AdditionalInfo: t.AdditionalInfo,
|
||||
}
|
||||
|
||||
|
|
|
@ -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("d7f22677-9803-4d21-ba42-081b633a6f68"), listen.ReleaseMbid)
|
||||
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"])
|
||||
}
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ func (t Track) DiscNumber() int {
|
|||
return 0
|
||||
}
|
||||
|
||||
func (t Track) Isrc() string {
|
||||
func (t Track) ISRC() string {
|
||||
return tryGetValueOrEmpty[string](t.AdditionalInfo, "isrc")
|
||||
}
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ func TestTrackIsrc(t *testing.T) {
|
|||
"isrc": expected,
|
||||
},
|
||||
}
|
||||
assert.Equal(t, expected, track.Isrc())
|
||||
assert.Equal(t, expected, track.ISRC())
|
||||
}
|
||||
|
||||
func TestTrackRecordingMbid(t *testing.T) {
|
||||
|
|
|
@ -224,7 +224,7 @@ func (t Track) AsTrack() models.Track {
|
|||
Duration: time.Duration(t.DurationMs * int(time.Millisecond)),
|
||||
TrackNumber: t.TrackNumber,
|
||||
DiscNumber: t.DiscNumber,
|
||||
Isrc: t.ExternalIds.ISRC,
|
||||
ISRC: t.ExternalIds.ISRC,
|
||||
AdditionalInfo: map[string]any{},
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ func TestSpotifyListenAsListen(t *testing.T) {
|
|||
assert.Equal(t, []string{"Dool"}, listen.ArtistNames)
|
||||
assert.Equal(t, 5, listen.TrackNumber)
|
||||
assert.Equal(t, 1, listen.DiscNumber)
|
||||
assert.Equal(t, "DES561620801", listen.Isrc)
|
||||
assert.Equal(t, "DES561620801", listen.ISRC)
|
||||
info := listen.AdditionalInfo
|
||||
assert.Equal(t, "spotify.com", info["music_service"])
|
||||
assert.Equal(t, "https://open.spotify.com/track/2JKUgGuXK3dEvyuIJ4Yj2V", info["origin_url"])
|
||||
|
|
|
@ -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 {
|
||||
loves := make(models.LovesList, len(songs))
|
||||
for i, song := range songs {
|
||||
love := SongToLove(*song, b.client.User)
|
||||
love := SongAsLove(*song, b.client.User)
|
||||
if love.Created.Unix() > oldestTimestamp.Unix() {
|
||||
loves[i] = love
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ func (b *SubsonicApiBackend) filterSongs(songs []*subsonic.Child, oldestTimestam
|
|||
return loves
|
||||
}
|
||||
|
||||
func SongToLove(song subsonic.Child, username string) models.Love {
|
||||
func SongAsLove(song subsonic.Child, username string) models.Love {
|
||||
love := models.Love{
|
||||
UserName: username,
|
||||
Created: song.Starred,
|
||||
|
|
|
@ -46,7 +46,7 @@ func TestSongToLove(t *testing.T) {
|
|||
DiscNumber: 1,
|
||||
Track: 5,
|
||||
}
|
||||
love := subsonic.SongToLove(song, user)
|
||||
love := subsonic.SongAsLove(song, user)
|
||||
assert := assert.New(t)
|
||||
assert.Equal(time.Unix(1699574369, 0).Unix(), love.Created.Unix())
|
||||
assert.Equal(user, love.UserName)
|
||||
|
|
|
@ -37,7 +37,7 @@ type Track struct {
|
|||
TrackNumber int
|
||||
DiscNumber int
|
||||
Duration time.Duration
|
||||
Isrc string
|
||||
ISRC string
|
||||
RecordingMbid MBID
|
||||
ReleaseMbid MBID
|
||||
ReleaseGroupMbid MBID
|
||||
|
|
Loading…
Add table
Reference in a new issue