api

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package api contains interface for connecting to remote server. Subpackages contain implementations.

Index

Constants

This section is empty.

Variables

View Source
var MockAlbums = []*models.Album{
	{
		Id:        "album-1",
		Name:      "album-1",
		Year:      2020,
		Duration:  3600,
		Artist:    "artist-1",
		SongCount: 2,
		DiscCount: 1,
		Songs:     []models.Id{"song-1", "song-2"},
	},
	{
		Id:        "album-2",
		Name:      "album-2",
		Year:      2019,
		Duration:  3600,
		Artist:    "artist-1",
		SongCount: 2,
		DiscCount: 1,
		Songs:     []models.Id{"song-3", "song-4"},
	},
	{
		Id:        "album-3",
		Name:      "album-3",
		Year:      2018,
		Duration:  3600,
		Artist:    "artist-2",
		SongCount: 2,
		DiscCount: 1,
		Songs:     []models.Id{"song-5", "song-6"},
	},
}
View Source
var MockArtists = []*models.Artist{
	{
		Id:            "artist-1",
		Name:          "artist 1",
		Albums:        []models.Id{"album-1", "album-2"},
		TotalDuration: 3600,
		AlbumCount:    2,
	},
	{
		Id:            "artist-2",
		Name:          "artist 2",
		Albums:        []models.Id{"album-3"},
		TotalDuration: 3600,
		AlbumCount:    1,
	},
}
View Source
var MockPlaylists = []*models.Playlist{
	{
		Id:        "playlist-1",
		Name:      "playlist 1",
		Songs:     MockSongs[0:2],
		SongCount: 2,
		Duration:  360,
	},
	{
		Id:        "playlist-2",
		Name:      "playlist 2",
		Songs:     MockSongs[0:5],
		SongCount: 5,
		Duration:  900,
	},
}
View Source
var MockSongs = []*models.Song{
	{
		Id:          "song-1",
		Name:        "song 1",
		Duration:    180,
		Index:       0,
		Album:       "album-1",
		DiscNumber:  0,
		AlbumArtist: "artist-1",
	},
	{
		Id:          "song-2",
		Name:        "song 2",
		Duration:    180,
		Index:       0,
		Album:       "album-1",
		DiscNumber:  0,
		AlbumArtist: "artist-1",
	},
	{
		Id:          "song-3",
		Name:        "song 3",
		Duration:    180,
		Index:       0,
		Album:       "album-2",
		DiscNumber:  0,
		AlbumArtist: "artist-1",
	},
	{
		Id:          "song-4",
		Name:        "song 4",
		Duration:    180,
		Index:       0,
		Album:       "album-2",
		DiscNumber:  0,
		AlbumArtist: "artist-1",
	},
	{
		Id:          "song-5",
		Name:        "song 5",
		Duration:    180,
		Index:       0,
		Album:       "album-3",
		DiscNumber:  0,
		AlbumArtist: "artist-2",
	},
	{
		Id:          "song-6",
		Name:        "song 6",
		Duration:    180,
		Index:       0,
		Album:       "album-3",
		DiscNumber:  0,
		AlbumArtist: "artist-2",
	},
}

Functions

func MimeToAudioFormat added in v0.8.0

func MimeToAudioFormat(mimeType string) (format interfaces.AudioFormat, err error)

Types

type Browser added in v0.8.0

type Browser interface {

	// GetArtists returns all artists
	GetArtists(query *interfaces.QueryOpts) ([]*models.Artist, int, error)

	// GetAlbumArtists returns artists that are marked as album artists. See GetArtists.
	GetAlbumArtists(query *interfaces.QueryOpts) ([]*models.Artist, int, error)
	// GetAlbums gets albums with given paging. Only PageSize and CurrentPage are used. Total count is returned
	GetAlbums(query *interfaces.QueryOpts) ([]*models.Album, int, error)

	// GetArtistAlbums returns albums that artist takes part in.
	GetArtistAlbums(artist models.Id) ([]*models.Album, error)

	// GetAlbumSongs returns songs for given album id.
	GetAlbumSongs(album models.Id) ([]*models.Song, error)
	// GetPlaylists returns all playlists.
	GetPlaylists() ([]*models.Playlist, error)
	// GetPlaylistSongs fills songs array for playlist. If there's error, songs will not be filled
	GetPlaylistSongs(playlist models.Id) ([]*models.Song, error)

	// GetSimilarArtists returns similar artists for artist id
	GetSimilarArtists(artist models.Id) ([]*models.Artist, error)

	// GetsimilarAlbums returns list of similar albums.
	GetSimilarAlbums(album models.Id) ([]*models.Album, error)

	// GetRecentlyPlayed returns songs that have been played last.
	GetRecentlyPlayed(paging interfaces.Paging) ([]*models.Song, int, error)

	// GetSongs returns songs by paging. It also returns total number of songs.
	GetSongs(query *interfaces.QueryOpts) ([]*models.Song, int, error)

	// GetGenres returns music genres with paging. Return genres, total genres and possible error
	GetGenres(paging interfaces.Paging) ([]*models.IdName, int, error)

	// GetAlbumArtist returns main artist for album.
	GetAlbumArtist(album *models.Album) (*models.Artist, error)

	// GetInstantMix returns instant mix based on given item.
	GetInstantMix(item models.Item) ([]*models.Song, error)

	// GetLink returns a link to item that can be opened with browser.
	// If there is no link or item is invalid, empty link is returned.
	GetLink(item models.Item) string

	// Search returns values matching query and itemType, limited by number of maxResults,
	// Only items of itemType should ne returned.
	Search(query string, itemType models.ItemType, maxResults int) ([]models.Item, error)

	GetAlbum(id models.Id) (*models.Album, error)

	GetArtist(id models.Id) (*models.Artist, error)

	GetImageUrl(item models.Id, itemType models.ItemType) string
}

Browser implements item-based viewing for music artists,albums,playlists etc.

type Cacher added in v0.9.0

type Cacher interface {

	// CanCacheSong returns true if caching songs by Browser.GetSongs is implemented.
	// Else, player tries to pull songs directly using Browser.GetAlbumSongs.
	// GetAlbumSongs is slower method (when album contains less songs then paged song list).
	CanCacheSongs() bool
}

Cacher describes how data may be pulled from remote server and might override some Browser methods.

type MediaServer

type MediaServer interface {
	Streamer
	Browser
	RemoteServer
}

MediaServer combines minimal interfaces for browsing and playing songs from remote server. Mediaserver can additionally implement RemoteController, and Cacher.

type MockConfig added in v0.9.0

type MockConfig struct {
}

func (*MockConfig) DumpConfig added in v0.9.0

func (m *MockConfig) DumpConfig() interface{}

func (*MockConfig) GetType added in v0.9.0

func (m *MockConfig) GetType() string

type MockServer added in v0.9.0

type MockServer struct {
	Artists         []*models.Artist
	FavoriteArtists []*models.Artist
	AlbumArtists    []*models.Artist
	Albums          []*models.Album
	AlbumSongs      map[models.Id][]*models.Song
	Playlists       []*models.Playlist
	PlaylistSongs   map[models.Id]*models.Song
	Songs           []*models.Song
}

func NewMockServer added in v0.9.0

func NewMockServer() *MockServer

func (*MockServer) ConnectionOk added in v0.9.0

func (m *MockServer) ConnectionOk() error

func (*MockServer) GetAlbum added in v0.9.0

func (m *MockServer) GetAlbum(id models.Id) (*models.Album, error)

func (*MockServer) GetAlbumArtist added in v0.9.0

func (m *MockServer) GetAlbumArtist(album *models.Album) (*models.Artist, error)

func (*MockServer) GetAlbumArtists added in v0.9.0

func (m *MockServer) GetAlbumArtists(query *interfaces.QueryOpts) ([]*models.Artist, int, error)

func (*MockServer) GetAlbumSongs added in v0.9.0

func (m *MockServer) GetAlbumSongs(album models.Id) ([]*models.Song, error)

func (*MockServer) GetAlbums added in v0.9.0

func (m *MockServer) GetAlbums(query *interfaces.QueryOpts) ([]*models.Album, int, error)

func (*MockServer) GetArtist added in v0.9.0

func (m *MockServer) GetArtist(id models.Id) (*models.Artist, error)

func (*MockServer) GetArtistAlbums added in v0.9.0

func (m *MockServer) GetArtistAlbums(artist models.Id) ([]*models.Album, error)

func (*MockServer) GetArtists added in v0.9.0

func (m *MockServer) GetArtists(query *interfaces.QueryOpts) ([]*models.Artist, int, error)

func (*MockServer) GetConfig added in v0.9.0

func (m *MockServer) GetConfig() config.Backend

func (*MockServer) GetFavoriteAlbums added in v0.9.0

func (m *MockServer) GetFavoriteAlbums(paging interfaces.Paging) ([]*models.Album, int, error)

func (*MockServer) GetGenreAlbums added in v0.9.0

func (m *MockServer) GetGenreAlbums(genre models.IdName) ([]*models.Album, error)

func (*MockServer) GetGenres added in v0.9.0

func (m *MockServer) GetGenres(paging interfaces.Paging) ([]*models.IdName, int, error)

func (*MockServer) GetImageUrl added in v0.9.0

func (m *MockServer) GetImageUrl(item models.Id, itemType models.ItemType) string

func (*MockServer) GetInfo added in v0.9.0

func (m *MockServer) GetInfo() (*models.ServerInfo, error)

func (*MockServer) GetInstantMix added in v0.9.0

func (m *MockServer) GetInstantMix(item models.Item) ([]*models.Song, error)

func (*MockServer) GetLatestAlbums added in v0.9.0

func (m *MockServer) GetLatestAlbums() ([]*models.Album, error)
func (m *MockServer) GetLink(item models.Item) string

func (*MockServer) GetPlaylistSongs added in v0.9.0

func (m *MockServer) GetPlaylistSongs(playlist models.Id) ([]*models.Song, error)

func (*MockServer) GetPlaylists added in v0.9.0

func (m *MockServer) GetPlaylists() ([]*models.Playlist, error)

func (*MockServer) GetRecentlyPlayed added in v0.9.0

func (m *MockServer) GetRecentlyPlayed(paging interfaces.Paging) ([]*models.Song, int, error)

func (*MockServer) GetSimilarAlbums added in v0.9.0

func (m *MockServer) GetSimilarAlbums(album models.Id) ([]*models.Album, error)

func (*MockServer) GetSimilarArtists added in v0.9.0

func (m *MockServer) GetSimilarArtists(artist models.Id) ([]*models.Artist, error)

func (*MockServer) GetSongs added in v0.9.0

func (m *MockServer) GetSongs(query *interfaces.QueryOpts) ([]*models.Song, int, error)

func (*MockServer) ReportProgress added in v0.9.0

func (m *MockServer) ReportProgress(state *interfaces.ApiPlaybackState) error

func (*MockServer) Search added in v0.9.0

func (m *MockServer) Search(query string, itemType models.ItemType, maxResults int) ([]models.Item, error)

func (*MockServer) Start added in v0.9.0

func (m *MockServer) Start() error

func (*MockServer) Stop added in v0.9.0

func (m *MockServer) Stop() error

type RemoteController added in v0.8.0

type RemoteController interface {
	// SetPlayer allows connecting remote controller to player, which can
	// then be controlled remotely.
	SetPlayer(player interfaces.Player)

	SetQueue(q interfaces.QueueController)

	RemoteControlEnabled() error
}

RemoteController controls audio player remotely as well as keeps remote server updated on player status.

type RemoteServer added in v0.8.0

type RemoteServer interface {
	// GetInfo returns general info
	GetInfo() (*models.ServerInfo, error)

	// ConnectionOk returns nil of connection ok, else returns description for failure.
	ConnectionOk() error

	// GetConfig returns backend config that is saved to config file.
	GetConfig() config.Backend

	// ReportProgress reports player progress to remote controller.
	ReportProgress(state *interfaces.ApiPlaybackState) error

	// Start starts background service for remote server, if any.
	Start() error

	// Stop stops background service for remote server, if any.
	Stop() error

	// GetId returns unique id for server. If server does not provide one,
	// it can be e.g. hashed from url and user.
	GetId() string
}

RemoteServer contains general methods for getting server connection status

type StreamBuffer added in v0.8.0

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

StreamBuffer is a buffer that reads whole http body in the background and copies it to local buffer.

func NewStreamDownload added in v0.6.0

func NewStreamDownload(url string, headers map[string]string, params map[string]string,
	client *http.Client, duration int) (*StreamBuffer, error)

func (*StreamBuffer) AudioFormat added in v0.8.0

func (s *StreamBuffer) AudioFormat() (format interfaces.AudioFormat, err error)

func (*StreamBuffer) Close added in v0.8.0

func (s *StreamBuffer) Close() error

func (*StreamBuffer) Len added in v0.8.0

func (s *StreamBuffer) Len() int

func (*StreamBuffer) Read added in v0.8.0

func (s *StreamBuffer) Read(p []byte) (n int, err error)

func (*StreamBuffer) SecondsBuffered added in v0.8.0

func (s *StreamBuffer) SecondsBuffered() int

type Streamer added in v0.8.0

type Streamer interface {

	// Stream streams song. If server does not implement separate streaming endpoint,
	// implementcation can wrap Download.
	Stream(Song *models.Song) (io.ReadCloser, interfaces.AudioFormat, error)

	// Download downloads original audio file.
	Download(Song *models.Song) (io.ReadCloser, interfaces.AudioFormat, error)
}

Streamer contains methods for streaming audio from remote location.

Directories

Path Synopsis
Package jellyfin implements connection to Jellyfin server.
Package jellyfin implements connection to Jellyfin server.
Package subsonic contains remote server implementation for Subsonic-compatible servers.
Package subsonic contains remote server implementation for Subsonic-compatible servers.

Jump to

Keyboard shortcuts

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