jellyfin

package module
v0.0.0-...-fb02c0b Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: GPL-3.0 Imports: 21 Imported by: 2

README

go-jellyfin

An API client library for Jellyfin music functionality for Go.

This code is an adaptation of the Jellyfin API implementation from the Jellycli project, originally written by Tero Vierimaa (@tryffel). Also a very helpful resource was the Jellyfin API layer of Sonixd.

The scope of this library is currently music-only, as it is being built for the Supersonic project.

Status

This library is functional, and currently in use in Supersonic. However, it is certainly not API stable and can be expected to change frequently.

Example

import (
    "github.com/dweymouth/go-jellyfin"
    "log"
)

func main() {
    // create client
    jellyClient, err := jellyfin.NewClient("https://jellyfin.example.com", "supersonic", "1")
    if err != nil {
        log.Fatalf("unable to create jellyfin client: %v", err)
    }

    // login. Saves the access key to Client for future calls.
    if err := jellyClient.Login("user", "pass"); err != nil {
        log.Fatalf("unable to log in to jellyfin: %v", err)
    }

    // get albums between 2000-2010
    filter := jellyfin.QueryOpts{
        Filter: jellyfin.Filter{
            YearRange: []int{2000, 2010},
        },
    }

    albums, err := jellyClient.GetAlbums(filter)
    if err != nil {
        log.Fatalf("unable to get albums: %v", err)
    }

    // print out all the album names
    for _, album := range albums {
        log.Print(album.Name)
    }
}

Documentation

Index

Constants

View Source
const (
	FilterIsPlayed    = "Played"
	FilterIsNotPlayed = "Not played"
)
View Source
const (
	DefaultTimeOut = 30 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Album

type Album struct {
	Name         string   `json:"Name"`
	ID           string   `json:"Id"`
	RunTimeTicks int64    `json:"RunTimeTicks"`
	Year         int      `json:"ProductionYear"`
	DateCreated  string   `json:"DateCreated"`
	Type         string   `json:"Type"`
	Artists      []NameID `json:"AlbumArtists"`
	Overview     string   `json:"Overview"`
	Genres       []string `json:"Genres"`
	ChildCount   int      `json:"ChildCount"`
	ImageTags    Images   `json:"ImageTags"`
	UserData     UserData `json:"UserData"`
}

type Artist

type Artist struct {
	Name         string   `json:"Name"`
	Overview     string   `json:"Overview"`
	ID           string   `json:"Id"`
	RunTimeTicks int64    `json:"RunTimeTicks"`
	Type         string   `json:"Type"`
	AlbumCount   int      `json:"AlbumCount"`
	UserData     UserData `json:"UserData"`
	ImageTags    Images   `json:"ImageTags"`
}

type Client

type Client struct {
	HTTPClient *http.Client

	ClientName    string
	ClientVersion string
	// contains filtered or unexported fields
}

Client is the root struct for all Jellyfin API calls

func NewClient

func NewClient(urlStr, clientName, clientVersion string, opts ...ClientOptionFunc) (*Client, error)

NewClient creates a jellyfin Client using the url provided.

func (*Client) AddSongsToPlaylist

func (c *Client) AddSongsToPlaylist(playlistID string, trackIDs []string) error

func (*Client) BaseURL

func (c *Client) BaseURL() *url.URL

BaseURL return a copy of the baseURL.

func (*Client) CreatePlaylist

func (c *Client) CreatePlaylist(name string, trackIDs []string) error

func (*Client) DeletePlaylist

func (c *Client) DeletePlaylist(playlistID string) error

func (*Client) GetAlbum

func (c *Client) GetAlbum(albumID string) (*Album, error)

func (*Client) GetAlbumArtists

func (c *Client) GetAlbumArtists(opts QueryOpts) ([]*Artist, error)

func (*Client) GetAlbums

func (c *Client) GetAlbums(opts QueryOpts) ([]*Album, error)

GetAlbums returns albums with given sort, filter, and paging options. - Can be used to get an artist's discography with ArtistID filter.

func (*Client) GetArtist

func (c *Client) GetArtist(artistID string) (*Artist, error)

func (*Client) GetGenres

func (c *Client) GetGenres(paging Paging) ([]NameID, error)

func (*Client) GetInstantMix

func (c *Client) GetInstantMix(id string, idType ItemType, limit int) ([]*Song, error)

func (*Client) GetItemImage

func (c *Client) GetItemImage(itemID, imageTag string, size, quality int) (image.Image, error)

func (*Client) GetItemImageBinary

func (c *Client) GetItemImageBinary(itemID, imageTag string, size, quality int) (io.ReadCloser, error)

func (*Client) GetPlaylist

func (c *Client) GetPlaylist(playlistID string) (*Playlist, error)

func (*Client) GetPlaylistSongs

func (c *Client) GetPlaylistSongs(playlistID string) ([]*Song, error)

func (*Client) GetPlaylists

func (c *Client) GetPlaylists() ([]*Playlist, error)

GetPlaylists retrieves all playlists. Each playlists song count is known, but songs must be retrieved separately

func (*Client) GetSimilarArtists

func (c *Client) GetSimilarArtists(artistID string) ([]*Artist, error)

func (*Client) GetSong

func (c *Client) GetSong(songID string) (*Song, error)

func (*Client) GetSongs

func (c *Client) GetSongs(opts QueryOpts) ([]*Song, error)

Get songs matching the given filter criteria with given sorting and paging.

  • Can be used to get an album track list with the ParentID filter.
  • Can be used to get top songs for an artist with the ArtistId filter and sorting by CommunityRating descending

func (*Client) GetStreamURL

func (c *Client) GetStreamURL(id string) (string, error)

func (*Client) LoggedInUser

func (c *Client) LoggedInUser() string

LoggedInUser returns the user associated with this Client.

func (*Client) Login

func (c *Client) Login(username, password string) error

Login authenticates a user into the server provided in Client. If the login is successful, the access token is stored for future API calls.

func (*Client) MovePlaylistSong

func (c *Client) MovePlaylistSong(playlistID string, trackID string, newIdx int) error

func (*Client) Ping

func (c *Client) Ping() (*PingResponse, error)

Ping queries the jellyfin server for a response. Return is some basic information about the jellyfin server.

func (*Client) RefreshLibrary

func (c *Client) RefreshLibrary() error

func (*Client) RemoveSongsFromPlaylist

func (c *Client) RemoveSongsFromPlaylist(playlistID string, removeIndexes []int) error

func (*Client) Search

func (jf *Client) Search(query string, itemType ItemType, paging Paging) (*SearchResult, error)

Search searches audio items

func (*Client) SetFavorite

func (c *Client) SetFavorite(id string, favorite bool) error

func (*Client) UpdatePlayStatus

func (c *Client) UpdatePlayStatus(songID string, event PlayEvent, positionTicks int64) error

func (*Client) UpdatePlaylistMetadata

func (c *Client) UpdatePlaylistMetadata(playlistID, name, overview string) error

type ClientOptionFunc

type ClientOptionFunc func(*Client)

ClientOptionFunc can be used to customize a new jellyfin API client.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOptionFunc

Http client override.

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOptionFunc

Http timeout override.

type Filter

type Filter struct {
	// Played
	FilterPlayed FilterPlayStatus
	// Favorite marks items as being starred / favorite.
	Favorite bool
	// Include only results from the given artist.
	ArtistID string
	// Include only results with the given parentID.
	ParentID string
	// Genres contains list of genres to include.
	Genres []string
	// YearRange contains two elements, items must be within these boundaries.
	YearRange [2]int
}

Filter contains filter for reducing results. Some fields are exclusive,

type FilterPlayStatus

type FilterPlayStatus string

type Images

type Images struct {
	Primary string `json:"Primary"`
	Disc    string `json:"Disc"`
}

type ItemType

type ItemType string
const (
	TypeArtist   ItemType = "Artist"
	TypeAlbum    ItemType = "Album"
	TypePlaylist ItemType = "Playlist"
	//	TypeQueue    ItemType = "Queue"
	//	TypeHistory  ItemType = "History"
	TypeSong  ItemType = "Song"
	TypeGenre ItemType = "Genre"
)

type MediaSource

type MediaSource struct {
	Bitrate   int    `json:"Bitrate"`
	Container string `json:"Container"`
	Path      string `json:"Path"`
	Size      int    `json:"Size"`
}

type NameID

type NameID struct {
	Name string `json:"Name"`
	ID   string `json:"Id"`
}

type Paging

type Paging struct {
	StartIndex int
	Limit      int
}

type PingResponse

type PingResponse struct {
	LocalAddress    string
	ServerName      string
	Version         string
	ProductName     string
	OperatingSystem string
	Id              string
}

type PlayEvent

type PlayEvent string
const (
	Start      PlayEvent = "start"
	Stop       PlayEvent = "stop"
	Pause      PlayEvent = "pause"
	Unpause    PlayEvent = "unpause"
	TimeUpdate PlayEvent = "timeupdate"
)

type Playlist

type Playlist struct {
	Name               string            `json:"Name"`
	ID                 string            `json:"Id"`
	Overview           string            `json:"Overview"`
	DateCreated        string            `json:"DateCreated"`
	PremiereDate       string            `json:"PremiereDate"`
	DateLastMediaAdded string            `json:"DateLastMediaAdded"`
	Genres             []string          `json:"Genres"`
	RunTimeTicks       int64             `json:"RunTimeTicks"`
	Type               string            `json:"Type"`
	MediaType          string            `json:"MediaType"`
	ImageTags          Images            `json:"ImageTags"`
	Tags               []string          `json:"Tags"`
	ProviderIds        map[string]string `json:"ProviderIds"`
	SongCount          int               `json:"ChildCount"`
}

type QueryOpts

type QueryOpts struct {
	Paging Paging
	Filter Filter
	Sort   Sort
}

type SearchResult

type SearchResult struct {
	Artists   []*Artist
	Albums    []*Album
	Songs     []*Song
	Playlists []*Playlist
}

type Song

type Song struct {
	Name           string        `json:"Name"`
	Id             string        `json:"Id"`
	PlaylistItemId string        `json:"PlaylistItemId"`
	RunTimeTicks   int64         `json:"RunTimeTicks"`
	ProductionYear int           `json:"ProductionYear"`
	DateCreated    string        `json:"DateCreated"`
	IndexNumber    int           `json:"IndexNumber"`
	Type           string        `json:"Type"`
	AlbumID        string        `json:"AlbumId"`
	Album          string        `json:"Album"`
	DiscNumber     int           `json:"ParentIndexNumber"`
	Artists        []NameID      `json:"ArtistItems"`
	ImageTags      Images        `json:"ImageTags"`
	MediaSources   []MediaSource `json:"MediaSources"`
	UserData       UserData      `json:"UserData"`
}

type Sort

type Sort struct {
	Field SortField
	Mode  SortOrder
}

Sort describes sorting

type SortField

type SortField string
const (
	SortByName            SortField = "SortName"
	SortByYear            SortField = "ProductionYear,PremiereDate"
	SortByArtist          SortField = "AlbumArtist"
	SortByPlayCount       SortField = "PlayCount"
	SortByRandom          SortField = "Random"
	SortByDateCreated     SortField = "DateCreated"
	SortByDatePlayed      SortField = "DatePlayed"
	SortByCommunityRating SortField = "CommunityRating"
)

type SortOrder

type SortOrder string
const (
	SortAsc  SortOrder = "ASC"
	SortDesc SortOrder = "DESC"
)

type UserData

type UserData struct {
	PlayCount      int    `json:"PlayCount"`
	IsFavorite     bool   `json:"IsFavorite"`
	Rating         int    `json:"Rating"`
	Played         bool   `json:"Played"`
	LastPlayedDate string `json:"LastPlayedDate"`
}

Jump to

Keyboard shortcuts

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