From bcb183499449e3fe9572895c8b8a1734b346c7d2 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Tue, 29 Apr 2025 13:29:00 +0200 Subject: [PATCH] scrobblerlog: use camelcase for constants --- internal/backends/scrobblerlog/scrobblerlog.go | 4 ++-- pkg/scrobblerlog/parser.go | 14 +++++++------- pkg/scrobblerlog/parser_test.go | 14 +++++++------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/internal/backends/scrobblerlog/scrobblerlog.go b/internal/backends/scrobblerlog/scrobblerlog.go index 26d417a..19ed30b 100644 --- a/internal/backends/scrobblerlog/scrobblerlog.go +++ b/internal/backends/scrobblerlog/scrobblerlog.go @@ -76,7 +76,7 @@ func (b *ScrobblerLogBackend) InitConfig(config *config.ServiceConfig) error { b.log.FallbackTimezone = location } b.log = scrobblerlog.ScrobblerLog{ - TZ: scrobblerlog.TZ_UTC, + TZ: scrobblerlog.TimezoneUTC, Client: "Rockbox unknown $Revision$", } return nil @@ -197,7 +197,7 @@ func listenToRecord(listen models.Listen) scrobblerlog.Record { var rating scrobblerlog.Rating rockboxRating, ok := listen.AdditionalInfo["rockbox_rating"].(string) if !ok || rockboxRating == "" { - rating = scrobblerlog.RATING_LISTENED + rating = scrobblerlog.RatingListened } else { rating = scrobblerlog.Rating(rating) } diff --git a/pkg/scrobblerlog/parser.go b/pkg/scrobblerlog/parser.go index 892f6e8..9c6471c 100644 --- a/pkg/scrobblerlog/parser.go +++ b/pkg/scrobblerlog/parser.go @@ -45,16 +45,16 @@ import ( type TZInfo string const ( - TZ_UNKNOWN TZInfo = "UNKNOWN" - TZ_UTC TZInfo = "UTC" + TimezoneUnknown TZInfo = "UNKNOWN" + TimezoneUTC TZInfo = "UTC" ) // L if listened at least 50% or S if skipped type Rating string const ( - RATING_LISTENED Rating = "L" - RATING_SKIPPED Rating = "S" + RatingListened Rating = "L" + RatingSkipped Rating = "S" ) // A single entry of a track in the scrobbler log file. @@ -75,7 +75,7 @@ type ScrobblerLog struct { Client string Records []Record // Timezone to be used for timestamps in the log file, - // if TZ is set to [TZ_UNKNOWN]. + // if TZ is set to [TimezoneUnknown]. FallbackTimezone *time.Location } @@ -116,7 +116,7 @@ func (l *ScrobblerLog) Parse(data io.Reader, ignoreSkipped bool) error { return err } - if ignoreSkipped && record.Rating == RATING_SKIPPED { + if ignoreSkipped && record.Rating == RatingSkipped { continue } @@ -224,7 +224,7 @@ func (l ScrobblerLog) rowToRecord(row []string) (Record, error) { } var timezone *time.Location = nil - if l.TZ == TZ_UNKNOWN { + if l.TZ == TimezoneUnknown { timezone = l.FallbackTimezone } diff --git a/pkg/scrobblerlog/parser_test.go b/pkg/scrobblerlog/parser_test.go index 7fd57c3..f4527cc 100644 --- a/pkg/scrobblerlog/parser_test.go +++ b/pkg/scrobblerlog/parser_test.go @@ -50,7 +50,7 @@ func TestParser(t *testing.T) { result := scrobblerlog.ScrobblerLog{} err := result.Parse(data, false) require.NoError(t, err) - assert.Equal(scrobblerlog.TZ_UNKNOWN, result.TZ) + assert.Equal(scrobblerlog.TimezoneUnknown, result.TZ) assert.Equal("Rockbox sansaclipplus $Revision$", result.Client) assert.Len(result.Records, 5) record1 := result.Records[0] @@ -59,11 +59,11 @@ func TestParser(t *testing.T) { assert.Equal("Sevdanin rengi (sipacik) byMrTurkey", record1.TrackName) assert.Equal(5, record1.TrackNumber) assert.Equal(time.Duration(306*time.Second), record1.Duration) - assert.Equal(scrobblerlog.RATING_LISTENED, record1.Rating) + assert.Equal(scrobblerlog.RatingListened, record1.Rating) assert.Equal(time.Unix(1260342084, 0), record1.Timestamp) assert.Equal(mbtypes.MBID(""), record1.MusicBrainzRecordingID) record4 := result.Records[3] - assert.Equal(scrobblerlog.RATING_SKIPPED, record4.Rating) + assert.Equal(scrobblerlog.RatingSkipped, record4.Rating) assert.Equal(mbtypes.MBID("385ba9e9-626d-4750-a607-58e541dca78e"), record4.MusicBrainzRecordingID) } @@ -76,7 +76,7 @@ func TestParserIgnoreSkipped(t *testing.T) { require.NoError(t, err) assert.Len(result.Records, 4) record4 := result.Records[3] - assert.Equal(scrobblerlog.RATING_LISTENED, record4.Rating) + assert.Equal(scrobblerlog.RatingListened, record4.Rating) assert.Equal(mbtypes.MBID("1262beaf-19f8-4534-b9ed-7eef9ca8e83f"), record4.MusicBrainzRecordingID) } @@ -101,7 +101,7 @@ func TestAppend(t *testing.T) { data := make([]byte, 0, 10) buffer := bytes.NewBuffer(data) log := scrobblerlog.ScrobblerLog{ - TZ: scrobblerlog.TZ_UNKNOWN, + TZ: scrobblerlog.TimezoneUnknown, Client: "Rockbox foo $Revision$", } records := []scrobblerlog.Record{ @@ -111,7 +111,7 @@ func TestAppend(t *testing.T) { TrackName: "Reign", TrackNumber: 1, Duration: 271 * time.Second, - Rating: scrobblerlog.RATING_LISTENED, + Rating: scrobblerlog.RatingListened, Timestamp: time.Unix(1699572072, 0), MusicBrainzRecordingID: mbtypes.MBID("b59cf4e7-caee-4019-a844-79d2c58d4dff"), }, @@ -139,7 +139,7 @@ func TestReadHeader(t *testing.T) { log := scrobblerlog.ScrobblerLog{} err := log.ReadHeader(reader) assert.NoError(t, err) - assert.Equal(t, log.TZ, scrobblerlog.TZ_UNKNOWN) + assert.Equal(t, log.TZ, scrobblerlog.TimezoneUnknown) assert.Equal(t, log.Client, "Rockbox sansaclipplus $Revision$") assert.Empty(t, log.Records) }