scrobblerlog

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package to parse and write .scrobbler.log files as written by Rockbox.

The parser supports reading version 1.1 and 1.0 of the scrobbler log file format. The latter is only supported if encoded in UTF-8.

When written it always writes version 1.1 of the scrobbler log file format, which includes the MusicBrainz recording ID as the last field of each row.

See - https://www.rockbox.org/wiki/LastFMLog - https://git.rockbox.org/cgit/rockbox.git/tree/apps/plugins/lastfm_scrobbler.c - https://web.archive.org/web/20110110053056/http://www.audioscrobbler.net/wiki/Portable_Player_Logging

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rating

type Rating string

L if listened at least 50% or S if skipped

const (
	RatingListened Rating = "L"
	RatingSkipped  Rating = "S"
)

type Record

type Record struct {
	ArtistName             string
	AlbumName              string
	TrackName              string
	TrackNumber            int
	Duration               time.Duration
	Rating                 Rating
	Timestamp              time.Time
	MusicBrainzRecordingID mbtypes.MBID
}

A single entry of a track in the scrobbler log file.

type ScrobblerLog

type ScrobblerLog struct {
	TZ      TZInfo
	Client  string
	Records []Record
	// Timezone to be used for timestamps in the log file,
	// if TZ is set to [TimezoneUnknown].
	FallbackTimezone *time.Location
}

Represents a scrobbler log file.

func (*ScrobblerLog) Append

func (l *ScrobblerLog) Append(data io.Writer, records []Record) (lastTimestamp time.Time, err error)

Append writes the given records to the writer.

The writer should be for an existing scrobbler log file or ScrobblerLog.WriteHeader should be called before this function. Returns the last timestamp of the records written.

func (*ScrobblerLog) Parse

func (l *ScrobblerLog) Parse(data io.Reader, ignoreSkipped bool) error

Parses a scrobbler log file from the given reader.

The reader must provide a valid scrobbler log file with a valid header. This function implicitly calls ScrobblerLog.ReadHeader.

func (*ScrobblerLog) ParseIter added in v0.6.0

func (l *ScrobblerLog) ParseIter(data io.Reader, ignoreSkipped bool) iter.Seq2[Record, error]

Parses a scrobbler log file from the given reader and returns an iterator over all records.

The reader must provide a valid scrobbler log file with a valid header. This function implicitly calls ScrobblerLog.ReadHeader.

func (*ScrobblerLog) ReadHeader

func (l *ScrobblerLog) ReadHeader(reader io.Reader) error

Parses just the header of a scrobbler log file from the given reader.

This function sets [ScrobblerLog.TZ] and [ScrobblerLog.Client].

func (*ScrobblerLog) WriteHeader

func (l *ScrobblerLog) WriteHeader(writer io.Writer) error

Writes the header of a scrobbler log file to the given writer.

type TZInfo

type TZInfo string

TZInfo is the timezone information in the header of the scrobbler log file. It can be "UTC" or "UNKNOWN", if the device writing the scrobbler log file knows the time, but not the timezone.

const (
	TimezoneUnknown TZInfo = "UNKNOWN"
	TimezoneUTC     TZInfo = "UTC"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL