mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 05:37:05 +02:00
scrobblerlog: renamed setting include-skipped to ignore-skipped
This makes the setting consistent with the similar setting for spotify
This commit is contained in:
parent
82858315fa
commit
1516a3a9d6
4 changed files with 25 additions and 25 deletions
|
@ -56,8 +56,8 @@ backend = "scrobbler-log"
|
||||||
# The file path to the .scrobbler.log file. Relative paths are resolved against
|
# The file path to the .scrobbler.log file. Relative paths are resolved against
|
||||||
# the current working directory when running scotty.
|
# the current working directory when running scotty.
|
||||||
file-path = "./.scrobbler.log"
|
file-path = "./.scrobbler.log"
|
||||||
# If true, reading listens from the file also returns listens marked as "skipped"
|
# If true (default), ignore listens marked as skipped.
|
||||||
include-skipped = true
|
ignore-skipped = true
|
||||||
# If true (default), new listens will be appended to the existing file. Set to
|
# If true (default), new listens will be appended to the existing file. Set to
|
||||||
# false to overwrite the file and create a new scrobbler log on every run.
|
# false to overwrite the file and create a new scrobbler log on every run.
|
||||||
append = true
|
append = true
|
||||||
|
@ -105,9 +105,9 @@ dir-path = "./my_spotify_data_extended/Spotify Extended Streaming Histor
|
||||||
ignore-incognito = true
|
ignore-incognito = true
|
||||||
# If true, ignore listens marked as skipped. Default is false.
|
# If true, ignore listens marked as skipped. Default is false.
|
||||||
ignore-skipped = false
|
ignore-skipped = false
|
||||||
# Only consider skipped listens with a playback duration longer than this number
|
# Only consider skipped listens with a playback duration longer than or equal to
|
||||||
# of seconds. Default is 30 seconds. If ignore-skipped is set to false this
|
# this number of seconds. Default is 30 seconds. If ignore-skipped is enabled
|
||||||
# setting has no effect.
|
# this setting has no effect.
|
||||||
ignore-min-duration-seconds = 30
|
ignore-min-duration-seconds = 30
|
||||||
|
|
||||||
[service.deezer]
|
[service.deezer]
|
||||||
|
|
|
@ -32,7 +32,7 @@ import (
|
||||||
|
|
||||||
type ScrobblerLogBackend struct {
|
type ScrobblerLogBackend struct {
|
||||||
filePath string
|
filePath string
|
||||||
includeSkipped bool
|
ignoreSkipped bool
|
||||||
append bool
|
append bool
|
||||||
file *os.File
|
file *os.File
|
||||||
timezone *time.Location
|
timezone *time.Location
|
||||||
|
@ -47,9 +47,10 @@ func (b *ScrobblerLogBackend) Options() []models.BackendOption {
|
||||||
Label: i18n.Tr("File path"),
|
Label: i18n.Tr("File path"),
|
||||||
Type: models.String,
|
Type: models.String,
|
||||||
}, {
|
}, {
|
||||||
Name: "include-skipped",
|
Name: "ignore-skipped",
|
||||||
Label: i18n.Tr("Include skipped listens"),
|
Label: i18n.Tr("Ignore skipped listens"),
|
||||||
Type: models.Bool,
|
Type: models.Bool,
|
||||||
|
Default: "true",
|
||||||
}, {
|
}, {
|
||||||
Name: "append",
|
Name: "append",
|
||||||
Label: i18n.Tr("Append to file"),
|
Label: i18n.Tr("Append to file"),
|
||||||
|
@ -64,7 +65,7 @@ func (b *ScrobblerLogBackend) Options() []models.BackendOption {
|
||||||
|
|
||||||
func (b *ScrobblerLogBackend) InitConfig(config *config.ServiceConfig) error {
|
func (b *ScrobblerLogBackend) InitConfig(config *config.ServiceConfig) error {
|
||||||
b.filePath = config.GetString("file-path")
|
b.filePath = config.GetString("file-path")
|
||||||
b.includeSkipped = config.GetBool("include-skipped", false)
|
b.ignoreSkipped = config.GetBool("ignore-skipped", true)
|
||||||
b.append = config.GetBool("append", true)
|
b.append = config.GetBool("append", true)
|
||||||
timezone := config.GetString("time-zone")
|
timezone := config.GetString("time-zone")
|
||||||
if timezone != "" {
|
if timezone != "" {
|
||||||
|
@ -140,7 +141,7 @@ func (b *ScrobblerLogBackend) ExportListens(oldestTimestamp time.Time, results c
|
||||||
|
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
err = b.log.Parse(file, b.includeSkipped)
|
err = b.log.Parse(file, b.ignoreSkipped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
progress <- models.Progress{}.Complete()
|
progress <- models.Progress{}.Complete()
|
||||||
results <- models.ListensResult{Error: err}
|
results <- models.ListensResult{Error: err}
|
||||||
|
|
|
@ -79,7 +79,7 @@ type ScrobblerLog struct {
|
||||||
FallbackTimezone *time.Location
|
FallbackTimezone *time.Location
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ScrobblerLog) Parse(data io.Reader, includeSkipped bool) error {
|
func (l *ScrobblerLog) Parse(data io.Reader, ignoreSkipped bool) error {
|
||||||
l.Records = make([]Record, 0)
|
l.Records = make([]Record, 0)
|
||||||
|
|
||||||
reader := bufio.NewReader(data)
|
reader := bufio.NewReader(data)
|
||||||
|
@ -111,16 +111,15 @@ func (l *ScrobblerLog) Parse(data io.Reader, includeSkipped bool) error {
|
||||||
return fmt.Errorf("invalid record in scrobblerlog line %v", line)
|
return fmt.Errorf("invalid record in scrobblerlog line %v", line)
|
||||||
}
|
}
|
||||||
|
|
||||||
rating := row[5]
|
|
||||||
if !includeSkipped && rating == "S" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
record, err := l.rowToRecord(row)
|
record, err := l.rowToRecord(row)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ignoreSkipped && record.Rating == RATING_SKIPPED {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
l.Records = append(l.Records, record)
|
l.Records = append(l.Records, record)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ func TestParser(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
data := bytes.NewBufferString(testScrobblerLog)
|
data := bytes.NewBufferString(testScrobblerLog)
|
||||||
result := scrobblerlog.ScrobblerLog{}
|
result := scrobblerlog.ScrobblerLog{}
|
||||||
err := result.Parse(data, true)
|
err := result.Parse(data, false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(scrobblerlog.TZ_UNKNOWN, result.TZ)
|
assert.Equal(scrobblerlog.TZ_UNKNOWN, result.TZ)
|
||||||
assert.Equal("Rockbox sansaclipplus $Revision$", result.Client)
|
assert.Equal("Rockbox sansaclipplus $Revision$", result.Client)
|
||||||
|
@ -68,11 +68,11 @@ func TestParser(t *testing.T) {
|
||||||
record4.MusicBrainzRecordingID)
|
record4.MusicBrainzRecordingID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParserExcludeSkipped(t *testing.T) {
|
func TestParserIgnoreSkipped(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
data := bytes.NewBufferString(testScrobblerLog)
|
data := bytes.NewBufferString(testScrobblerLog)
|
||||||
result := scrobblerlog.ScrobblerLog{}
|
result := scrobblerlog.ScrobblerLog{}
|
||||||
err := result.Parse(data, false)
|
err := result.Parse(data, true)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(result.Records, 4)
|
assert.Len(result.Records, 4)
|
||||||
record4 := result.Records[3]
|
record4 := result.Records[3]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue