Documentation
¶
Overview ¶
Package playlist manages an ordered track list with shuffle and repeat support.
Index ¶
- Variables
- func IsFeed(path string) bool
- func IsLocalM3U(path string) bool
- func IsLocalPLS(path string) bool
- func IsM3U(path string) bool
- func IsPLS(path string) bool
- func IsURL(path string) bool
- func IsXiaoyuzhouEpisode(path string) bool
- func IsYTDL(path string) bool
- func IsYTSearch(path string) bool
- func IsYouTubeMusicURL(path string) bool
- func IsYouTubeURL(path string) bool
- func TotalDurationSecs(tracks []Track) int
- type Authenticator
- type Playlist
- func (p *Playlist) ActivateSelected() (SelectionActivation, bool)
- func (p *Playlist) Add(tracks ...Track)
- func (p *Playlist) BookmarkCount() int
- func (p *Playlist) ClearQueue()
- func (p *Playlist) Current() (Track, int)
- func (p *Playlist) CurrentIsQueued() bool
- func (p *Playlist) CycleRepeat()
- func (p *Playlist) Dequeue(trackIdx int) bool
- func (p *Playlist) Index() int
- func (p *Playlist) Len() int
- func (p *Playlist) Move(from, to int) bool
- func (p *Playlist) MoveQueue(from, to int) bool
- func (p *Playlist) Next() (Track, bool)
- func (p *Playlist) PeekNext() (Track, bool)
- func (p *Playlist) Prev() (Track, bool)
- func (p *Playlist) Queue(trackIdx int)
- func (p *Playlist) QueueLen() int
- func (p *Playlist) QueuePosition(trackIdx int) int
- func (p *Playlist) QueueTracks() []Track
- func (p *Playlist) Remove(idx int) bool
- func (p *Playlist) RemoveQueueAt(pos int)
- func (p *Playlist) Repeat() RepeatMode
- func (p *Playlist) Replace(tracks []Track)
- func (p *Playlist) SetIndex(i int)
- func (p *Playlist) SetRepeat(mode RepeatMode)
- func (p *Playlist) SetTrack(i int, t Track)
- func (p *Playlist) Shuffled() bool
- func (p *Playlist) ToggleBookmark(idx int)
- func (p *Playlist) ToggleShuffle()
- func (p *Playlist) Tracks() []Track
- type PlaylistInfo
- type Provider
- type Refresher
- type RepeatMode
- type SelectionActivation
- type Track
Constants ¶
This section is empty.
Variables ¶
var ErrNeedsAuth = errors.New("sign-in required")
ErrNeedsAuth is returned by providers that require interactive sign-in before they can be used.
Functions ¶
func IsLocalM3U ¶
IsLocalM3U reports whether the path is a local (non-URL) M3U file.
func IsLocalPLS ¶
IsLocalPLS reports whether the path is a local (non-URL) PLS file.
func IsURL ¶
IsURL reports whether path is an HTTP or HTTPS URL, or a yt-dlp search protocol string.
func IsXiaoyuzhouEpisode ¶
IsXiaoyuzhouEpisode reports whether the URL points to a Xiaoyuzhou episode page.
func IsYTDL ¶
IsYTDL reports whether the URL points to a site supported by yt-dlp (YouTube, SoundCloud, Bandcamp, ytsearch: protocol, etc.).
func IsYTSearch ¶
IsYTSearch reports whether path is a yt-dlp search expression (ytsearch:, ytsearchN:, scsearch:, scsearchN:).
func IsYouTubeMusicURL ¶
IsYouTubeMusicURL reports whether the URL points to YouTube Music (music.youtube.com). These URLs require yt-dlp rather than the native YouTube API client.
func IsYouTubeURL ¶
IsYouTubeURL reports whether the URL points to YouTube (youtube.com or youtu.be). YouTube Music (music.youtube.com) is excluded — use IsYouTubeMusicURL for that.
func TotalDurationSecs ¶
TotalDurationSecs sums DurationSecs across a slice of tracks, skipping entries with unknown duration (zero).
Types ¶
type Authenticator ¶
type Authenticator interface {
Authenticate() error
}
Authenticator is optionally implemented by providers that require sign-in.
type Playlist ¶
type Playlist struct {
// contains filtered or unexported fields
}
Playlist manages an ordered list of tracks with shuffle and repeat support. All exported methods are safe for concurrent use: the Bubbletea UI loop mutates the playlist while Lua plugin goroutines read state through it.
func (*Playlist) ActivateSelected ¶
func (p *Playlist) ActivateSelected() (SelectionActivation, bool)
ActivateSelected promotes the selected row to the active playable track. Queue state is ignored for candidate selection and left unchanged. If no playable track can be activated, playlist state is unchanged.
func (*Playlist) BookmarkCount ¶
BookmarkCount returns the number of bookmarked tracks.
func (*Playlist) ClearQueue ¶
func (p *Playlist) ClearQueue()
ClearQueue removes all entries from the play-next queue.
func (*Playlist) CurrentIsQueued ¶
func (*Playlist) CycleRepeat ¶
func (p *Playlist) CycleRepeat()
CycleRepeat cycles through Off -> All -> One.
func (*Playlist) Move ¶
Move swaps the track at position from with the track at position to, updating order, queue, and position references so playback is unaffected. When shuffle is off, the visual order becomes the new playback order.
func (*Playlist) MoveQueue ¶
MoveQueue swaps the two entries at the given positions in the play-next queue.
func (*Playlist) Next ¶
Next advances to the next track according to queue, repeat, and shuffle. Unplayable queued entries are pruned as playback advances. RepeatOne still limits playback to the current track.
func (*Playlist) PeekNext ¶
PeekNext returns the next track without advancing the playlist position. Returns false when the next track can't be predicted (e.g., shuffle wrap).
func (*Playlist) Prev ¶
Prev moves to the previous track, skipping unavailable tracks. Wraps around with RepeatAll.
func (*Playlist) QueuePosition ¶
QueuePosition returns the 1-based position of a track in the queue, or 0 if the track is not queued.
func (*Playlist) QueueTracks ¶
QueueTracks returns copies of the tracks in queue order.
func (*Playlist) Remove ¶
Remove deletes the track at index idx, updating order, queue, and position references so playback state is preserved when possible. Returns true if a track was removed. If the removed track was the active one, the position stays at the same order slot so playback advances naturally on next.
func (*Playlist) RemoveQueueAt ¶
RemoveQueueAt removes the entry at the given 0-based queue position.
func (*Playlist) Repeat ¶
func (p *Playlist) Repeat() RepeatMode
Repeat returns the current repeat mode.
func (*Playlist) Replace ¶
Replace clears the playlist and loads the given tracks, resetting position, queue, and shuffle order.
func (*Playlist) SetRepeat ¶
func (p *Playlist) SetRepeat(mode RepeatMode)
SetRepeat sets the repeat mode directly.
func (*Playlist) ToggleBookmark ¶
ToggleBookmark flips the Bookmark flag on the track at the given index.
func (*Playlist) ToggleShuffle ¶
func (p *Playlist) ToggleShuffle()
ToggleShuffle enables or disables shuffle mode. Uses Fisher-Yates shuffle, preserving the current track at position 0.
type PlaylistInfo ¶
PlaylistInfo describes a playlist with its name and track count.
DurationSecs is optional: providers that can compute it cheaply should populate it so the UI can render a total runtime. A zero value means "unknown" and the UI will hide the duration column.
Section is optional: providers may set it to group their playlists in the UI. Adjacent rows that share a Section are rendered under one header; a change of Section emits a "── header ──" divider. The radio provider uses SectionedList.IDPrefix instead and leaves Section empty.
type Provider ¶
type Provider interface {
// Name returns the display name of this provider.
Name() string
// Playlists returns the available playlists from this provider.
Playlists() ([]PlaylistInfo, error)
// Tracks returns the tracks in the given playlist.
Tracks(playlistID string) ([]Track, error)
}
Provider is the interface for playlist sources (radio, Navidrome, Spotify, etc.).
type Refresher ¶
type Refresher interface {
Refresh()
}
Refresher is optionally implemented by providers that cache playlist or track data and support invalidating that cache so the next Playlists() / Tracks() call re-fetches from the source.
type RepeatMode ¶
type RepeatMode int
RepeatMode controls playlist repeat behavior.
const ( RepeatOff RepeatMode = iota RepeatAll RepeatOne )
func (RepeatMode) String ¶
func (r RepeatMode) String() string
type SelectionActivation ¶
SelectionActivation describes the playable track activated from the selected row.
type Track ¶
type Track struct {
Path string
Title string
Artist string
Album string
Genre string
Year int
TrackNumber int
Stream bool // true for HTTP/HTTPS URLs
Realtime bool // true for real-time/live streams (e.g. radio)
Feed bool // true for RSS/podcast feed URLs (resolved before playback)
DurationSecs int // known duration in seconds (0 = unknown)
Bookmark bool // user-bookmarked track
Unplayable bool // true when the track is known not playable in the current playback context
EmbeddedLyrics string // embedded lyrics from local file tags, when present
AlbumArtURL string // file:// URL for cached embedded album art, when present
// ProviderMeta holds provider-specific key-value pairs.
// Keys are namespaced by provider, e.g. "navidrome.id", "jellyfin.id".
ProviderMeta map[string]string
}
Track represents a single audio file or HTTP stream.
func RefreshEmbeddedMetadata ¶
RefreshEmbeddedMetadata returns track with embedded local-file lyrics and album art populated from its current Path. Existing non-embedded fields are preserved so saved playlist metadata and provider fields remain stable.
func TrackFromFilename ¶
TrackFromFilename creates a Track by parsing "Artist - Title" from the filename, or using the bare filename as the title.
func TrackFromPath ¶
TrackFromPath creates a Track by parsing the filename or URL. For local files, embedded tags (ID3v2, Vorbis, MP4) are tried first, falling back to "Artist - Title" filename parsing.
func (Track) DisplayName ¶
DisplayName returns a formatted display string for the track.