jamsonic

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2018 License: GPL-3.0 Imports: 9 Imported by: 5

README

Build Status Go Report Card

Jamsonic

Jamsonic is a console based music player for Subsonic/Madsonic/Libresonic/Airsonic. It's forked from Jam, which is a console based music player for Google Play Music.

It has the following features:

  • Populating the database with artists and albums you saved through the web interface (or by any other means)
  • Playing, pausing, stopping, previous track, next track

Contributions are welcome!

How to get up and running?

For macOS and Linux, portaudio has to be installed. Windows doesn't need anything extra.

Keybindings

The keybindings are mostly the same as in Cmus:

Key Action
return, x play currently selected artist, album or song
c pause
v stop
b next track
z previous track
Ctrl+u synchronize the database (in case you added some songs in the web interface)
/ search artists
n next search result
tab toggle artists/tracks view
escape quit
up arrow, k scroll up
down arrow, j scroll down
Home, g scroll to top
End, G scroll to bottom
space toggle albums
R randomize artists
Ctrl+Space toggle view (playlists/artists)
r repeat current track

Documentation

Index

Constants

View Source
const Version string = "0.9.0"

Version represents the application version using SemVer

Variables

View Source
var BufferingWait = time.Duration(200 * time.Millisecond)

BufferingWait is the time in milliseconds to wait on reading from the network socket before playing the track. If this is to low, an EOF can be returned when reading from the memory buffer causing the track from being skipped. Default value is 200 ms.

View Source
var DefaultCredentialRequest = &CredentialRequest{}

DefaultCredentialRequest is a default credential requester. It will read the info from stdin.

View Source
var (
	// ErrNoCredentialsStored is returned if the backend does not have any
	// credentials stored.
	ErrNoCredentialsStored = errors.New("No credentials stored")
)
View Source
var (
	// ErrNoNextTrack is returned when the playing queue does not have a track to play
	// but is asked to play one.
	ErrNoNextTrack = errors.New("no track in playing queue")
)
View Source
var MaxReadRetryAttempts = 5

MaxReadRetryAttempts is the number of retries when a EOF is returned during the first read.

Functions

func AskForPassword

func AskForPassword() ([]byte, error)

func AskForServer

func AskForServer() string

func AskForUsername

func AskForUsername() string

func RefreshLibrary

func RefreshLibrary(db MusicStore, provider Provider) error

Types

type Album

type Album struct {
	// Name is the album name
	Name string
	// Artist is the name of the artist for this album.
	Artist string
	// Year is the year the album was released.
	Year uint32
	// ID is the ID for the album.
	ID string
	// Tracks is an array of all the tracks.
	Tracks []*Track
}

Album holds all data for an album.

type Artist

type Artist struct {
	// Name of the artist.
	Name string
	// ID for the artist.
	ID string
	// Albums is an array of all the artist's albums.
	Albums []*Album
}

Artist holds all the data for an artist.

type AuthStore

type AuthStore interface {
	// GetCredentials gets the credentials from the database.
	GetCredentials(key []byte) ([]byte, error)
	// SaveCredentials saves the credentials to the database.
	SaveCredentials(key []byte, credStruct []byte) error
}

AuthStore is the interface for databases which handles credentials.

type CallbackData added in v0.8.0

type CallbackData struct {
	// CurrentTrack is the track being played.
	CurrentTrack *Track
	// Duration is how long the current track has been played.
	Duration time.Duration
}

CallbackData is passed in to the player's callback function. It holds current values from right before the callback function was called.

type CredentialRequest

type CredentialRequest struct{}

func (*CredentialRequest) GetPassword

func (c *CredentialRequest) GetPassword() string

GetPassword asks the user to enter the password via stdin.

func (*CredentialRequest) GetServer

func (c *CredentialRequest) GetServer() string

GetServer asks the user to enter the server url via stdin.

func (*CredentialRequest) GetUsername

func (c *CredentialRequest) GetUsername() string

GetUsername asks the user to enter the username via stdin.

type CredentialRequester

type CredentialRequester interface {
	// GetServer should return the server url.
	GetServer() string
	// GetUsername should return the username gotten from the user.
	GetUsername() string
	// GetPassword should return the password gotten from the user.
	GetPassword() string
}

CredentialRequester is an interface for getting credentials from the user.

type LogLevel added in v0.9.0

type LogLevel int8

LogLevel is used to determine which logs are written to the writer. The logger will write log types of the set level or lower. For example if the level is set at InfoLevel, info and error logs will be written to the writer but debug logs will not.

const (
	// ErrorLevel will only log errors.
	ErrorLevel LogLevel = iota
	// InfoLevel will log error and info logs.
	InfoLevel
	// DebugLevel is the highest level of logging.
	DebugLevel
)

type Logger added in v0.9.0

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

Logger instance can be used to log messages to the user. Each parent logger keep tracks of its children logs.

func DefaultLogger added in v0.9.0

func DefaultLogger() *Logger

DefaultLogger returns a Logger instance that logs to STDERR.

func NewLogger added in v0.9.0

func NewLogger(w io.Writer) *Logger

NewLogger creates a new Logger instance that will log to the given io.Writer.

func (*Logger) DebugLog added in v0.9.0

func (l *Logger) DebugLog(logLine string)

DebugLog writes a debug message to the log.

func (*Logger) ErrorLog added in v0.9.0

func (l *Logger) ErrorLog(logLine string)

ErrorLog writes an error the log.

func (*Logger) InfoLog added in v0.9.0

func (l *Logger) InfoLog(logLine string)

InfoLog writes an info message to the log.

func (*Logger) RemoveChild added in v0.9.0

func (l *Logger) RemoveChild(child *Logger)

RemoveChild tells the Logger to stop tracking the child logger.

func (*Logger) SetLevel added in v0.9.0

func (l *Logger) SetLevel(level LogLevel)

SetLevel changes the logging level to the new level.

func (*Logger) SetOutput added in v0.9.0

func (l *Logger) SetOutput(w io.Writer)

SetOutput changes the writer used by the logger.

func (*Logger) SubLogger added in v0.9.0

func (l *Logger) SubLogger(prefix string) *Logger

SubLogger creates a new child log. The prefix for the child will be The given prefix appended to the parents prefix.

type MusicProvider

type MusicProvider int

MusicProvider is the provider identifier.

const (
	// GooglePlayMusic is used as an identifier for the GPM provider.
	GooglePlayMusic MusicProvider = iota
	// SubSonic us used as an identifier for the subsonic provider.
	SubSonic
)

type MusicStore

type MusicStore interface {
	// AddTracks stores the tracks to the database. This methods is
	// deprecated and should not be used by new implementations.
	AddTracks([]*Track) error
	// AddPlaylists stores the playlists to the database. This methods is
	// deprecated and should not be used by new implementations.
	AddPlaylists(Provider, []*Playlist, []*PlaylistEntry) error
	// Artists returns the stored artists from the database.
	Artists() ([]*Artist, error)
	// SaveArtists saves the artists to the database.
	SaveArtists(artists []*Artist) error
}

MusicStore is the interface for databases which stores library caches.

type Player added in v0.8.0

type Player struct {
	// Error returns errors from the handler and the provider.
	Error chan error
	// contains filtered or unexported fields
}

Player is the mp3 player struct. This struct handles all player actions.

func NewPlayer added in v0.8.0

func NewPlayer(l *Logger, p Provider, h StreamHandler, callback func(*CallbackData), interval int) *Player

NewPlayer returns a new Player. The Provider should be a music provider. The callback is a function that is called every interval by the Player as long as the state is not stopped. If interval is set to 0, the callback will be called every 1000 ms. The callback function can be used to update the UI with current play status etc.

func (*Player) Close added in v0.8.0

func (p *Player) Close()

Close closes the player.

func (*Player) CreatePlayQueue added in v0.8.0

func (p *Player) CreatePlayQueue(tracks []*Track)

CreatePlayQueue creates a new list with queued tracks.

func (*Player) CurrentTrack added in v0.8.0

func (p *Player) CurrentTrack() *Track

CurrentTrack returns the current playing or paused track.

func (*Player) GetCurrentState added in v0.8.0

func (p *Player) GetCurrentState() State

GetCurrentState returns the player's current internal state.

func (*Player) Next added in v0.8.0

func (p *Player) Next()

Next skips to the next track in the play queue.

func (*Player) NextTrack added in v0.8.0

func (p *Player) NextTrack() *Track

NextTrack returns the next track in the play queue.

func (*Player) Pause added in v0.8.0

func (p *Player) Pause()

Pause pauses or resumes playing a track.

func (*Player) Play added in v0.8.0

func (p *Player) Play()

Play starts or resumes playing the track first in the play queue.

func (*Player) Previous added in v0.8.0

func (p *Player) Previous()

Previous will go back to previous played track.

func (*Player) Stop added in v0.8.0

func (p *Player) Stop()

Stop should be called to stop playing the track.

func (*Player) UpdateProvider added in v0.8.0

func (p *Player) UpdateProvider(c Provider)

UpdateProvider sets a new provider for the player. It stops the current playing track and restart the player.

type Playlist

type Playlist struct {
	// ID is the playlist's ID.
	ID string
	// Name is the name of the playlist.
	Name string
}

Playlist is a playlist structure.

type PlaylistEntry

type PlaylistEntry struct {
	// PlaylistId is the ID of the playlist.
	PlaylistId string
	// TrackId is the ID of the track.
	TrackId string
}

PlaylistEntry represents an entry in a playlist.

type Provider

type Provider interface {
	// ListTracks returns all the tracks from the provider. [DEPRECATED]
	ListTracks() ([]*Track, error)
	// FetchLibrary gets the library from the server. This implementation
	// should be used instead of the old implementations.
	FetchLibrary() ([]*Artist, error)
	// GetTrackInfo returns information abot the track from the provider.
	GetTrackInfo(trackID string) (*Track, error)
	// GetStream returns a ReadCloser stream of the track. The stream
	// has to be a MP3 encoded stream. [DEPRECATED]
	GetStream(songID string) (io.ReadCloser, error)
	// ListPlaylists returns all the playlists from the provider.
	ListPlaylists() ([]*Playlist, error)
	// ListPlaylistEntries returns to entries in the playlist. [DEPRECATED]
	ListPlaylistEntries() ([]*PlaylistEntry, error)
	// GetProvider returns the MusicProvider type.
	GetProvider() MusicProvider
}

Provider is a music provider.

type State added in v0.8.0

type State int8

State is the state the player can be in.

const (
	// Stopped is the state when the player is not playing anything.
	Stopped State = iota
	// Playing is the state when the player is playing a stream.
	Playing
	// Paused is the state when the player has been paused.
	Paused
)

type StreamHandler added in v0.8.0

type StreamHandler interface {
	// Finished should return a chan that is used to signal to the Player when the
	// track has been processed. The Player will call Play with a Reader for the next track
	// in the queue if one exists or call Stop if it was the final track in the playing queue.
	Finished() <-chan struct{}
	// Play is called with an io.Reader for the track. The handler should decode the stream and
	// send it to an output writer.
	Play(io.Reader) error
	// Stop is called by the Player to signal that all processing should stop. It is recommended that
	// output writers is closed when this is called.
	Stop()
	// Pause is called when stream processing should be paused.
	Pause()
	// Continue is called when stream processing should be resumed after it has been paused.
	Continue()
	// Errors returns a channel with errors from the handler. All read and write errors not handled
	// by the stream handler is sent to this channel. The controller must listen to this channel or
	// the handler might hang.
	Errors() <-chan error
}

StreamHandler should handle streams for the player. It should take an io.Reader and do the decoding to play the track.

type Track

type Track struct {
	// Artist is the name of the artist.
	Artist string
	// Album is the album.
	Album string
	// AlbumArtist is the album artist.
	AlbumArtist string
	// DiscNumber is the disc number for the track.
	DiscNumber uint8
	// TrackNumber is the track number for the track.
	TrackNumber uint32
	// DurationMillis is the song length in milliseconds.
	DurationMillis string
	// EstimatedSize is the estimated size for the track.
	EstimatedSize string
	// ID is the tracks unique ID.
	ID string
	// PlayCount is how many times to track has been played.
	PlayCount uint32
	// Title is the song title.
	Title string
	// Year is the year the track was released.
	Year uint32
}

Track is a common structure from a music track.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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