history

package
v1.60.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package history persists the user's recently played tracks to a TOML file in the cliamp config directory. Entries are recorded when a track has been played past the scrobble threshold (the same heuristic Last.fm and the Navidrome scrobbler use) so skipped tracks never enter the list.

The store is safe for concurrent callers and writes atomically (temp file + rename) so a crash mid-write cannot leave a half-finished history.toml.

Index

Constants

View Source
const DefaultCap = 200

DefaultCap is the maximum number of entries kept on disk. Older entries are dropped FIFO once the cap is exceeded.

View Source
const PlaylistName = "Recently Played"

PlaylistName is the virtual playlist name surfaced to the UI by the local provider. Browsing this name returns history entries newest-first.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Track    playlist.Track
	PlayedAt time.Time
}

Entry pairs a track with the wall-clock time it was played past threshold.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store reads and writes the history TOML file.

func New

func New() *Store

New returns a Store backed by ~/.config/cliamp/history.toml. Returns nil if the config directory cannot be resolved (rare; same failure mode as the local playlist provider).

func NewAt

func NewAt(path string) *Store

NewAt returns a Store rooted at an explicit file path. Used by tests.

func (*Store) Clear

func (s *Store) Clear() error

Clear deletes the history file. Returns nil if the file does not exist.

func (*Store) Path

func (s *Store) Path() string

Path returns the on-disk file path.

func (*Store) Recent

func (s *Store) Recent(limit int) ([]Entry, error)

Recent returns up to limit entries, newest first. limit <= 0 returns all.

func (*Store) Record

func (s *Store) Record(track playlist.Track, playedAt time.Time) error

Record appends an entry for track played at playedAt. If the most recent entry has the same path and was logged within dedupWindow, its timestamp is updated in place instead of duplicating the row. Empty paths are ignored.

func (*Store) SetCap

func (s *Store) SetCap(n int)

SetCap overrides the entry cap. Values <= 0 leave the cap unchanged.

func (*Store) Tracks

func (s *Store) Tracks(limit int) ([]playlist.Track, error)

Tracks returns up to limit recent tracks, newest first, suitable for handing to a playlist.Playlist. The PlayedAt timestamp is dropped.

Jump to

Keyboard shortcuts

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