subsonic

package
v0.0.0-...-d5b2c6c Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const MAX_RANDOM_SONGS = 50

Variables

This section is empty.

Functions

This section is empty.

Types

type Album

type Album struct {
	EntityBase
	Name      string   `json:"name"`
	SongCount int      `json:"songCount"`
	PlayCount int      `json:"playCount"`
	Songs     Entities `json:"song"`
	Genres    []Genre  `json:"genres"`
	// Compilation is available only from Navidrome
	Compilation bool `json:"isCompilation"`
	// SortName is available only from Navidrome
	SortName string
	// DiscTitles is available only from Navidrome
	DiscTitles []DiscTitle
}

func (Album) ID

func (s Album) ID() string

type Artist

type Artist struct {
	Id             string
	Name           string
	AlbumCount     int
	ArtistImageUrl string
	Albums         []Album `json:"album"`
}

func (Artist) ID

func (s Artist) ID() string

type Connection

type Connection struct {
	Username         string
	Password         string
	Host             string
	PlaintextAuth    bool
	Scrobble         bool
	RandomSongNumber uint
	// contains filtered or unexported fields
}

func Init

func Init(logger logger.LoggerInterface) *Connection

func (*Connection) AddSongToPlaylist

func (connection *Connection) AddSongToPlaylist(playlistId string, songId string) error

func (*Connection) ClearCache

func (s *Connection) ClearCache()

func (*Connection) CreatePlaylist

func (connection *Connection) CreatePlaylist(id, name string, songIds []string) (Playlist, error)

CreatePlaylist creates or updates a playlist on the server. If id is provided, the existing playlist with that ID is updated with the new song list. If name is provided, a new playlist is created with the song list. Either id or name _must_ be populated, or the function returns an error. If _both_ id and name are poplated, the function returns an error. songIds may be nil, in which case the new playlist is created empty, or all songs are removed from the existing playlist.

func (*Connection) DeletePlaylist

func (connection *Connection) DeletePlaylist(id string) error

func (*Connection) GetAlbum

func (connection *Connection) GetAlbum(id string) (Album, error)

GetAlbum gets information about a specific album If the item is in the cache, the cached item is returned; if not, it is put in the cache and returned. The songs in the album are sorted before return. https://opensubsonic.netlify.app/docs/endpoints/getalbum/

func (*Connection) GetArtist

func (connection *Connection) GetArtist(id string) (Artist, error)

GetArtist gets information about a single artist. If the item is in the cache, the cached item is returned; if not, it is put in the cache and returned. The albums in the response are sorted before return. https://opensubsonic.netlify.app/docs/endpoints/getartist/

func (*Connection) GetArtists

func (connection *Connection) GetArtists() (Indexes, error)

GetIndexes returns an indexed structure of all artists Artists in the response are _not_ sorted https://opensubsonic.netlify.app/docs/endpoints/getartists/ TODO (B) Artists that only exist under Various Artists don't show up as their own artists in getArtists calls to either gonic or Navidrome. E.g. if an artist has a single song tagged with artist=X and albumartist=A, living in directory A/somealbum/song.opus, that artist will not appear in getArtists

func (*Connection) GetCoverArt

func (connection *Connection) GetCoverArt(id string) (image.Image, error)

GetCoverArt fetches album art from the server, by ID. If id is empty, an error is returned. If, for some reason, the server response can't be parsed into an image, an error is returned. This function can process images of mime types - image/png - image/jpeg - image/gif These assets are not cached by this connection. https://opensubsonic.netlify.app/docs/endpoints/getcoverart/

func (*Connection) GetGenres

func (connection *Connection) GetGenres() ([]GenreEntry, error)

func (*Connection) GetIndexes

func (connection *Connection) GetIndexes() (Indexes, error)

GetIndexes returns an indexed structure of all artists https://opensubsonic.netlify.app/docs/endpoints/getindexes/

func (*Connection) GetLyricsBySongId

func (connection *Connection) GetLyricsBySongId(id string) ([]StructuredLyrics, error)

GetLyricsBySongId fetches time synchronized song lyrics. If the server does not support this, an error is returned.

func (*Connection) GetMusicDirectory

func (connection *Connection) GetMusicDirectory(id string) (Directory, error)

GetMusicDirector fetches a listing of all files in a music directory, by ID. If the item is in the cache, the cached item is returned; if not, it is put in the cache and returned. The entities in the directory are sorted before return. https://opensubsonic.netlify.app/docs/endpoints/getmusicdirectory/

func (*Connection) GetPlayUrl

func (connection *Connection) GetPlayUrl(entity Entity) string

note that this function does not make a request, it just formats the play url to pass to mpv

func (*Connection) GetPlaylist

func (connection *Connection) GetPlaylist(id string) (Playlist, error)

func (*Connection) GetPlaylists

func (connection *Connection) GetPlaylists() (Playlists, error)

func (*Connection) GetRandomSongs

func (connection *Connection) GetRandomSongs(id string) (Entities, error)

GetRandomSongs fetches a number of random songs. The results are not sorted. If a song Id is provided, songs similar to that song will be selected. The function returns Connection.RandomSongNumber or fewer songs; if it is 0, then MAX_RANDOM_SONGS are returned.

func (*Connection) GetServerInfo

func (connection *Connection) GetServerInfo() (Response, error)

GetServerInfo pings the server and returns the response, which contains basic information about the server https://opensubsonic.netlify.app/docs/endpoints/ping/

func (*Connection) GetSongsByGenre

func (connection *Connection) GetSongsByGenre(genre string, offset int, musicFolderID string) (Entities, error)

func (*Connection) GetStarred

func (connection *Connection) GetStarred() (Results, error)

func (*Connection) HasOpenSubsonicExtension

func (connection *Connection) HasOpenSubsonicExtension(feature string) bool

func (*Connection) LoadPlayQueue

func (connection *Connection) LoadPlayQueue() (PlayQueue, error)

func (*Connection) RemoveAlbumCacheEntry

func (s *Connection) RemoveAlbumCacheEntry(key string)

func (*Connection) RemoveArtistCacheEntry

func (s *Connection) RemoveArtistCacheEntry(key string)

func (*Connection) RemoveDirectoryCacheEntry

func (s *Connection) RemoveDirectoryCacheEntry(key string)

func (*Connection) RemoveSongFromPlaylist

func (connection *Connection) RemoveSongFromPlaylist(playlistId string, songIndex int) error

func (*Connection) SavePlayQueue

func (connection *Connection) SavePlayQueue(queueIds []string, current string, position int) error

func (*Connection) ScanStatus

func (connection *Connection) ScanStatus() (ScanStatus, error)

ScanStatus returns the state of any current scanning processes. https://opensubsonic.netlify.app/docs/endpoints/getscanstatus/

func (*Connection) ScrobbleSubmission

func (connection *Connection) ScrobbleSubmission(id string, isSubmission bool) (Response, error)

func (*Connection) Search

func (connection *Connection) Search(searchTerm string, artistOffset, albumOffset, songOffset int) (Results, error)

Search uses the Subsonic search3 API to query a server for all songs that have ID3 tags that match the query. The query is global, in that it matches in any ID3 field. https://www.subsonic.org/pages/api.jsp#search3

func (*Connection) SetClientInfo

func (s *Connection) SetClientInfo(name, version string)

func (*Connection) StartScan

func (connection *Connection) StartScan() error

StartScan tells the Subsonic server to initiate a media library scan. Whether this is a deep or surface scan is dependent on the server implementation. https://opensubsonic.netlify.app/docs/endpoints/startscan/

func (*Connection) ToggleStar

func (connection *Connection) ToggleStar(id string, starredItems map[string]struct{}) (Response, error)

type Directory

type Directory struct {
	Id       string   `json:"id"`
	Parent   string   `json:"parent"`
	Name     string   `json:"name"`
	Entities Entities `json:"child"`
}

func (Directory) ID

func (s Directory) ID() string

type DiscTitle

type DiscTitle struct {
	Disc  int
	Title string
}

type Entities

type Entities []Entity

Entities is a sortable list of entities. Directories are first, then in alphabelical order. Entities are sorted by track number, if they have track numbers; otherwise, they're sorted alphabetically.

func (Entities) Len

func (s Entities) Len() int

func (Entities) Less

func (s Entities) Less(i, j int) bool

func (Entities) Swap

func (s Entities) Swap(i, j int)

type Entity

type Entity struct {
	EntityBase
	Parent             string
	Path               string
	AlbumId            string
	AlbumArtists       []Artist
	DisplayAlbumArtist string
	BitRate            int
	BitDepth           int
	SamplingRate       int
	ChannelCount       int
	ContentType        string
	IsDirectory        bool `json:"isDir"`
	IsVideo            bool
	Size               int
	Suffix             string
	Track              int
	DiscNumber         int
	Type               string
	ReplayGain         ReplayGain
}

Entity could be either a song or a directory, because that's how Subsonic rolls.

func (Entity) GetAlbum

func (e Entity) GetAlbum() string

func (Entity) GetAlbumArtist

func (e Entity) GetAlbumArtist() string

func (Entity) GetArtist

func (e Entity) GetArtist() string

func (Entity) GetDiscNumber

func (e Entity) GetDiscNumber() int

func (Entity) GetDuration

func (e Entity) GetDuration() int

func (Entity) GetGenre

func (e Entity) GetGenre() string

func (Entity) GetId

func (e Entity) GetId() string

##################################### Methods allowing Entity to implement remote.TrackInterface #####################################

func (Entity) GetSongTitle

func (e Entity) GetSongTitle() string

Return the title if present, otherwise fallback to the file path

func (Entity) GetTitle

func (e Entity) GetTitle() string

func (Entity) GetTrackNumber

func (e Entity) GetTrackNumber() int

func (Entity) IsValid

func (e Entity) IsValid() bool

type EntityBase

type EntityBase struct {
	Id            string
	Created       string
	ArtistId      string
	Artist        string
	DisplayArtist string
	Album         string
	Duration      int
	Genre         string
	Year          int
	CoverArtId    string `json:"coverArt"`
	// Title is only available for Albums from gonic
	Title string
	// Artists is only available for Entities from gonic
	Artists []Artist
	// MusicBrainzId is only available for Albums from Navidrome
	MusicBrainzId string
}

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

response structs

type Extension

type Extension struct {
	Name     string
	Versions []int
}

type Genre

type Genre struct {
	Name string `json:"name"`
}

type GenreEntries

type GenreEntries struct {
	Genres []GenreEntry `json:"genre"`
}

type GenreEntry

type GenreEntry struct {
	SongCount  int    `json:"songCount"`
	AlbumCount int    `json:"albumCount"`
	Name       string `json:"value"`
}

type Id

type Id string

func (*Id) UnmarshalJSON

func (si *Id) UnmarshalJSON(b []byte) error

type Ider

type Ider interface {
	ID() string
}

type Index

type Index struct {
	Name    string
	Artists []Artist `json:"artist"`
}

type Indexes

type Indexes struct {
	LastModified    int
	IgnoredArticles string
	Index           []Index
}

type Info

type Info struct{}

type LyricsLine

type LyricsLine struct {
	Start int64  `json:"start"`
	Value string `json:"value"`
}

type LyricsList

type LyricsList struct {
	StructuredLyrics []StructuredLyrics `json:"structuredLyrics"`
}

type PlayQueue

type PlayQueue struct {
	Current  string   `json:"current"`
	Position int      `json:"position"`
	Entries  Entities `json:"entry"`
}

type Playlist

type Playlist struct {
	Id        Id
	Name      string
	SongCount int
	Comment   string
	Owner     string
	Public    bool
	Duration  int
	Created   string
	Changed   string
	Entries   Entities `json:"entry"`
}

type Playlists

type Playlists struct {
	Playlists []Playlist `json:"playlist"`
}

type ReplayGain

type ReplayGain struct {
	TrackPeak int
	AlbumPeak int
}

type Response

type Response struct {
	Status        string
	Version       string
	Type          string
	ServerVersion string
	OpenSubsonic  bool

	// There's no better way to do this, because Go generics are useless
	RandomSongs            Songs
	SimilarSongs           Songs
	Starred                Results
	SearchResult3          Results
	Directory              Directory
	Album                  Album
	Artists                Indexes
	Artist                 Artist
	ScanStatus             ScanStatus
	PlayQueue              PlayQueue
	Genres                 GenreEntries
	SongsByGenre           Songs
	Indexes                Indexes
	LyricsList             LyricsList
	Playlists              Playlists
	Playlist               Playlist
	OpenSubsonicExtensions []Extension

	Error Error
}

type Results

type Results struct {
	Artists []Artist `json:"artist"`
	Albums  []Album  `json:"album"`
	Songs   Entities `json:"song"`
}

type ScanStatus

type ScanStatus struct {
	Scanning bool `json:"scanning"`
	Count    int  `json:"count"`
}

type Songs

type Songs struct {
	Songs Entities `json:"song"`
}

Songs (and Playlists) are here because of how the Subsonic API structures the JSON, frequently nesting things unnecessarily.

type StructuredLyrics

type StructuredLyrics struct {
	Lang   string       `json:"lang"`
	Synced bool         `json:"synced"`
	Lines  []LyricsLine `json:"line"`
}

Jump to

Keyboard shortcuts

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