subsonic

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Handles hashing Taken from stmps https://github.com/spezifisch/stmps

Handles listings of artists and albums

Main request API calls for interacting with Subsonic Loosely based on stmps https://github.com/spezifisch/stmps

Handles responses and their json structs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatAlbums

func FormatAlbums(albums []Album, color bool, interactive bool) string

func FormatArtists

func FormatArtists(artists []Artist, color bool, interactive bool) string

func FormatSongs

func FormatSongs(songs []Song, color bool, interactive bool) string

Types

type Album

type Album struct {

	// Prefix should be `al-`
	ID string `json:"id"`

	// Parent artist
	Parent string `json:"artistId"`

	// UTF-8 name
	Name string `json:"name"`

	Genre string `json:"genre"`

	Songs []Song `json:"song"`

	Year      int `json:"year"`
	SongCount int `json:"songCount"`

	// In seconds
	Duration int `json:"duration"`
}

type Artist

type Artist struct {

	// Prefix should be `ar-`
	ID string `json:"id"`

	// UTF-8 name
	Name string `json:"name"`

	// Albums
	Albums []Album `json:"album"`

	// Number of albums
	AlbumCount int `json:"albumCount"`
}

type Artists

type Artists struct {
	IgnoredArticles string  `json:"ignoredArticles"`
	Index           []Index `json:"index"`
}

func (*Artists) ExtractArtists

func (indexes *Artists) ExtractArtists() []Artist

Remove character indexing and get all artists

type Formatter

type Formatter[T any, C bool, I bool] interface {
	func(T, C, I) string
}

type Index

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

type Response

type Response struct {
	SubsonicResponse SubsonicResponse `json:"subsonic-response"`
}

type Song

type Song struct {

	// Prefix should be `tr-`
	ID string `json:"id"`

	// flac/mp3 etc.
	Suffix string `json:"suffix"`

	// Main song title
	Title string `json:"title"`

	// Parent album
	Parent string `json:"parent"`

	// Should be music
	Type string `json:"type"`

	Track      int `json:"track"`
	DiscNumber int `json:"discNumber"`
	BitRate    int `json:"bitRate"`

	// In seconds
	Duration int `json:"duration"`

	// In bytes
	Size int `json:"size"`

	// Important to know we can stream this
	IsDir bool `json:"isDir"`
}

type SubsonicConnection

type SubsonicConnection struct {
	Username string
	Password string
	Host     string
}

func (*SubsonicConnection) GetAlbum

func (c *SubsonicConnection) GetAlbum(
	id string, sync bool, displayRaw bool, quiet bool, color bool, interactive bool,
) (string, error)

Get songs from an album https://www.subsonic.org/pages/api.jsp#getAlbum

The id string should have an `al-` prefix

Always cache, set TTL 1 week. Force refetch with --sync

func (*SubsonicConnection) GetArtist

func (c *SubsonicConnection) GetArtist(
	id string, sync bool, displayRaw bool, quiet bool, color bool, interactive bool,
) (string, error)

Get albums from an artist https://www.subsonic.org/pages/api.jsp#getArtist

The id string should have an `ar-` prefix

Always cache, set TTL 1 week. Force refetch with --sync

func (*SubsonicConnection) GetArtists

func (c *SubsonicConnection) GetArtists(
	sync bool, displayRaw bool, quiet bool, color bool, interactive bool,
) (string, error)

Get all artists, similar to indexes https://www.subsonic.org/pages/api.jsp#getArtists

Always cache, set TTL 1 week. Force refetch with --sync

func (*SubsonicConnection) GetSongIds

func (c *SubsonicConnection) GetSongIds(id string) ([]string, error)

Given id, get song ids if album, else just return the id if track

func (*SubsonicConnection) GetSongUrls

func (c *SubsonicConnection) GetSongUrls(id string) ([]string, error)

Given ID, get song url If album, we have to parse it Else if just a track, return the track id as part of the url

func (*SubsonicConnection) Scrobble

func (c *SubsonicConnection) Scrobble(id string) (err error)

Scrobble a submission, where the id is a track id https://www.subsonic.org/pages/api.jsp#scrobble

type SubsonicResponse

type SubsonicResponse struct {
	// Should returns "ok"
	Status string `json:"status"`

	// Should return server version
	Version string `json:"version"`

	// Should return server name, e.g. "gonic"
	Type string `json:"type"`

	// Should return subsonic API version
	ServerVersion string `json:"serverVersion"`

	// Relevant for GetArtists()
	Artists Artists `json:"artists,omitempty"`

	// Relevant for GetArtist()
	Artist Artist `json:"artist,omitempty"`

	// Relevant for GetAlbum()
	Album Album `json:"album,omitempty"`

	// Should return true
	OpenSubsonic bool `json:"openSubsonic"`
}

Jump to

Keyboard shortcuts

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